From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="G8KOGDNC" Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C6A23257 for ; Mon, 20 Nov 2023 06:53:33 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-53dd3f169d8so6104347a12.3 for ; Mon, 20 Nov 2023 06:53:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700492011; x=1701096811; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ET7XZBuYSIsGm9CmNHfDH0i0uNlWweXSO9s0Phl8jmQ=; b=G8KOGDNC2GPE4Oe5Ed8Rz72LIR+1xnWFJDYRi3KffyMW5Uej193i1DILprSIsLRvtF 33bKUVpd11am5xY2IIuYjTJDKLQk5al9/4vUWT+XEwbQE7NQZY6IakIIoSz51pwsZJ1D 60IJYAkNADXmII+Qw22z+bjiyX0/vzorJegrlqF7AyitpEB+7PRufL4cySZcxzf/JRej QEHGfpkcJ8NLiQxrVgMG6uS1KtjhTBo6oO7BrdE+cKHJj6ps7QCL9FSoVWNjtNl1AY1s Yf83fDi2kiiLHg0W6lfxNVBcp26Az8Q+LjHZGtTJKvC9oNesLQKMWQJfFrzswXNaAAMU dCrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700492011; x=1701096811; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ET7XZBuYSIsGm9CmNHfDH0i0uNlWweXSO9s0Phl8jmQ=; b=qwdLOW3UpcM2kwxKGBHMqh8JiPfPqoQrU/T1Wmh7RxjQZW27uRjvWDGrmSYT/74rOS rif6q7tT5XWrKxJcAFtqn4utCJ7QntSueVeyJBVonbHcu+C+EcMYrQaOFc4tJYntnLwf oMs7o/4ktMcV+7UuV+W+dzeDnaRKsb/YBOn8xfL86ZE+4+B3seWpBf3rDCrR/koeZOIw vJz0NWXBaxfIjR6e7aErZoIy0bMrEO8nEp1dWI3pjWE6AIKCUVugu54ZgzEz+8GAvFEo OXqkEtlWc8pitjLhjD4CO9BVzWn8Igw1KuSHedme7UmFL/uSeIPgHvGFKzHsLvC3FfKW CnWQ== X-Gm-Message-State: AOJu0YyC8CX6XN27qtZGsnYYhbI8AYBe5LE2kDUQxLJL5os33rS0k40c uRDtC23onfdN8Gf1GOF0GOtebA== X-Google-Smtp-Source: AGHT+IEiFXQNRTpLbffWwIB/ESoK8FBLpW5+d9rBzMckIo8AyjTDOyxsOL6c6QHe60c5kV4WSWbqHA== X-Received: by 2002:aa7:c588:0:b0:548:e8aa:dfc8 with SMTP id g8-20020aa7c588000000b00548e8aadfc8mr291110edq.32.1700492011605; Mon, 20 Nov 2023 06:53:31 -0800 (PST) Received: from [192.168.1.20] ([178.197.222.11]) by smtp.gmail.com with ESMTPSA id q3-20020aa7cc03000000b0054847e78203sm3387002edt.29.2023.11.20.06.53.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Nov 2023 06:53:31 -0800 (PST) Message-ID: <76fa8f61-fe31-4040-a38d-cc05be3f4f17@linaro.org> Date: Mon, 20 Nov 2023 15:53:28 +0100 Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] docs: dt-bindings: add DTS Coding Style document Content-Language: en-US To: Michal Simek , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Cc: Andrew Davis , Arnd Bergmann , Bjorn Andersson , Geert Uytterhoeven , Heiko Stuebner , Konrad Dybcio , Neil Armstrong , Nishanth Menon , Olof Johansson , linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-msm@vger.kernel.org References: <20231120084044.23838-1-krzysztof.kozlowski@linaro.org> <19358871-009d-4498-9c13-90d5338b1e9f@amd.com> From: Krzysztof Kozlowski Autocrypt: addr=krzysztof.kozlowski@linaro.org; keydata= xsFNBFVDQq4BEAC6KeLOfFsAvFMBsrCrJ2bCalhPv5+KQF2PS2+iwZI8BpRZoV+Bd5kWvN79 cFgcqTTuNHjAvxtUG8pQgGTHAObYs6xeYJtjUH0ZX6ndJ33FJYf5V3yXqqjcZ30FgHzJCFUu JMp7PSyMPzpUXfU12yfcRYVEMQrmplNZssmYhiTeVicuOOypWugZKVLGNm0IweVCaZ/DJDIH gNbpvVwjcKYrx85m9cBVEBUGaQP6AT7qlVCkrf50v8bofSIyVa2xmubbAwwFA1oxoOusjPIE J3iadrwpFvsZjF5uHAKS+7wHLoW9hVzOnLbX6ajk5Hf8Pb1m+VH/E8bPBNNYKkfTtypTDUCj NYcd27tjnXfG+SDs/EXNUAIRefCyvaRG7oRYF3Ec+2RgQDRnmmjCjoQNbFrJvJkFHlPeHaeS BosGY+XWKydnmsfY7SSnjAzLUGAFhLd/XDVpb1Een2XucPpKvt9ORF+48gy12FA5GduRLhQU vK4tU7ojoem/G23PcowM1CwPurC8sAVsQb9KmwTGh7rVz3ks3w/zfGBy3+WmLg++C2Wct6nM Pd8/6CBVjEWqD06/RjI2AnjIq5fSEH/BIfXXfC68nMp9BZoy3So4ZsbOlBmtAPvMYX6U8VwD TNeBxJu5Ex0Izf1NV9CzC3nNaFUYOY8KfN01X5SExAoVTr09ewARAQABzTRLcnp5c3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0OV+Ezo71pg3AYvq0a3/oGRG KQ06ztUMRrj8eVtpImjsWCd0bDWRaaR4vqhCHvAG9iWXZu4qh3ipie2Y0oSJygcZT7H3UZxq fyYKiqEmRuqsvv6dcbblD8ZLkz1EVZL6djImH5zc5x8qpVxlA0A0i23v5QvN00m6G9NFF0Le D2GYIS41Kv4Isx2dEFh+/Q== In-Reply-To: <19358871-009d-4498-9c13-90d5338b1e9f@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 20/11/2023 15:01, Michal Simek wrote: > > > On 11/20/23 09:40, 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: Andrew Davis >> Cc: AngeloGioacchino Del Regno >> Cc: Arnd Bergmann >> Cc: Bjorn Andersson >> Cc: Geert Uytterhoeven >> Cc: Heiko Stuebner >> Cc: Konrad Dybcio >> Cc: Matthias Brugger >> Cc: Michal Simek >> Cc: Neil Armstrong >> Cc: Nishanth Menon >> Cc: Olof Johansson >> Signed-off-by: Krzysztof Kozlowski >> >> --- >> >> Merging idea: Rob/DT bindings >> >> Changes in v2 >> ============= >> 1. Hopefully incorporate entire feedback from comments: >> a. Fix \ { => / { (Rob) >> b. Name: dts-coding-style (Rob) >> c. Exceptions for ordering nodes by name for Renesas and pinctrl (Geert, >> Konrad) >> d. Ordering properties by common/vendor (Rob) >> e. Array entries in <> (Rob) >> >> 2. New chapter: Organizing DTSI and DTS >> >> 3. Several grammar fixes (missing articles) >> >> Cc: linux-rockchip@lists.infradead.org >> Cc: linux-mediatek@lists.infradead.org >> Cc: linux-samsung-soc@vger.kernel.org >> Cc: linux-amlogic@lists.infradead.org >> Cc: linux-arm-kernel@lists.infradead.org >> Cc: linux-arm-msm@vger.kernel.org >> --- >> .../devicetree/bindings/dts-coding-style.rst | 163 ++++++++++++++++++ >> Documentation/devicetree/bindings/index.rst | 1 + >> 2 files changed, 164 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/dts-coding-style.rst >> >> diff --git a/Documentation/devicetree/bindings/dts-coding-style.rst b/Documentation/devicetree/bindings/dts-coding-style.rst >> new file mode 100644 >> index 000000000000..cc7e3b4d1b92 >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/dts-coding-style.rst >> @@ -0,0 +1,163 @@ >> +.. SPDX-License-Identifier: GPL-2.0 >> +.. _dtscodingstyle: >> + >> +===================================== >> +Devicetree Sources (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: - > > device-tree specification v0.4. Chapter 2.2.1/Table 2.1 is describing much more > valid characters for node names. > It means above description is not accurate or DT spec should be updated. Spec allows way to much. dtc doesn't. One thing is the spec, second thing is coding style. > > >> + >> +2. Labels are allowed to use only: >> + >> + * lowercase characters: [a-z] >> + * digits: [0-9] >> + * underscore: _ > > based on dt spec uppercase is also valid char in label. Which we do not want in the DTS. > > >> + >> +3. Unit addresses should use lowercase hex, without leading zeros (padding). >> + >> +4. Hex values in properties, e.g. "reg", should use lowercase hex. The 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>; > > Is 0x0 recommended or 0 is enough? I don't want to impose any rule on that, because someone would like to argue that hex should be also in SPI chip-select reg. > >> + } >> + >> +Order of Nodes >> +-------------- >> + >> +1. Nodes within any bus, thus using unit addresses for children, shall be >> + ordered incrementally by unit address. >> + Alternatively for some sub-architectures, nodes of the same type can be >> + grouped together (e.g. all I2C controllers one after another even if this >> + breaks unit address ordering). >> + >> +2. Nodes without unit addresses should be ordered alpha-numerically by the node >> + name. For a few types of nodes, they can be ordered by the main property >> + (e.g. pin configuration states ordered by value of "pins" property). >> + >> +3. When extending nodes in the board DTS via &label, the entries should be >> + ordered alpha-numerically. >> + >> +Example:: >> + >> + // SoC DTSI > > Same comment about /* */ as was mentioned in another thread. > >> + >> + / { >> + 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. Standard/common properties (defined by common bindings, e.g. without >> + vendor-prefixes) >> +5. Vendor-specific properties >> +6. status (if applicable) >> +7. Child nodes, where each node is preceded with a blank line > > Isn't the order already defined in DT spec in 2.3 in chapters? Where is it defined as this is preferred order? > compatible > model > status > #address/size cells > reg > virtual-reg > ranges > dma-ranges > dma-coherent > dma-non-coherent > > Again I am fine with whatever order but I think we should reflect it in the spec Spec is not a coding style. > too. Especially status property is for my taste too low simply because you start > to read and then you will find that IP is disabled. Which is exactly what you want. status is irrelevant for hardware description, so should be the last item. > > And are you describing all properties starting with # as standard properties? Yes. > > >> + >> +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, it is preferred to align the continued >> + entries with opening < from the first line. >> +3. Each entry in arrays with multiple cells (e.g. "reg" with two IO addresses) >> + should be enclosed in <>. >> + >> +Example:: >> + >> + thermal-sensor@c271000 { >> + compatible = "qcom,sm8550-tsens", "qcom,tsens-v2"; >> + reg = <0x0 0x0c271000 0x0 0x1000>, >> + <0x0 0x0c222000 0x0 0x1000>; >> + }; >> + >> +Organizing DTSI and DTS >> +----------------------- >> + >> +The DTSI and DTS files should be organized in a way representing the common >> +(and re-usable) parts of the hardware. Typically this means organizing DTSI >> +and DTS files into several files: >> + >> +1. DTSI with contents of the entire SoC (without nodes for hardware not present >> + on the SoC). >> +2. If applicable: DTSI with common or re-usable parts of the hardware (e.g. >> + entire System-on-Module). > > DTS/DTSI - SOMs can actually run as they are that's why it is fair to say that > there doesn't need to be DTS representing the board. I have never seen a SoM which can run without elaborate hardware-hacking (e.g. connecting multiple wires to the SoM pins). The definition of the SoM is that it is a module. Module can be re-used, just like SoC. Best regards, Krzysztof