Part 1
요약·해설
기존 Linux·vendor binding 조사, YAML description 형식, naming과 vendor prefix, 안전한 default 선정, zephyr, software extension 경계를 보존했습니다.
Linux · vendor
compatible · dash
근거 필수
zephyr, prefix
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
082F53B6150359E11134B7474C49C03F435C03F6048E84F965E920839DBB8884
.. _dt-writing-bindings:
Rules for upstream bindings
###########################
This section includes general rules for writing bindings that you want to
submit to the upstream Zephyr Project. (You don't need to follow these rules
for bindings you don't intend to contribute to the Zephyr Project, but it's a
good idea.)
Decisions made by the Zephyr devicetree maintainer override the contents of
this section. If that happens, though, please let them know so they can update
this page, or you can send a patch yourself.
.. contents:: Contents
:local:
Always check for existing bindings
**********************************
Zephyr aims for devicetree :ref:`dt-source-compatibility`. Therefore, if there
is an existing binding for your device in an authoritative location, you should
try to replicate its properties when writing a Zephyr binding, and you must
justify any Zephyr-specific divergences.
In particular, this rule applies if:
- There is an existing binding in the mainline Linux kernel. See
:file:`Documentation/devicetree/bindings` in `Linus's tree`_ for existing
bindings and the `Linux devicetree documentation`_ for more information.
- Your hardware vendor provides an official binding outside of the Linux
kernel.
.. _Linus's tree:
https://github.com/torvalds/linux/
.. _Linux devicetree documentation:
https://www.kernel.org/doc/html/latest/devicetree/index.html
General rules
*************
File names
==========
Bindings which match a compatible must have file names based on the compatible.
- For example, a binding for compatible ``vnd,foo`` must be named ``vnd,foo.yaml``.
- If the binding is bus-specific, you can append the bus to the file name;
for example, if the binding YAML has ``on-bus: bar``, you may name the file
``vnd,foo-bar.yaml``.
Recommendations are requirements
================================
All recommendations in :ref:`dt-bindings-default` are requirements when
submitting the binding.
In particular, if you use the ``default:`` feature, you must justify the
value in the property's description.
Descriptions
============
There are only two acceptable ways to write property ``description:``
strings.
If your description is short, it's fine to use this style:
.. code-block:: yaml
description: my short string
If your description is long or spans multiple lines, you must use this
style:
.. code-block:: yaml
description: |
My very long string
goes here.
Look at all these lines!
This ``|`` style prevents YAML parsers from removing the newlines in
multi-line descriptions. This in turn makes these long strings
display properly in the :ref:`devicetree_binding_index`.
Naming conventions
==================
Do not use uppercase letters (``A`` through ``Z``) or underscores (``_``) in
property names. Use lowercase letters (``a`` through ``z``) instead of
uppercase. Use dashes (``-``) instead of underscores. (The one exception to
this rule is if you are replicating a well-established binding from somewhere
like Linux.)
Rules for vendor prefixes
*************************
The following general rules apply to vendor prefixes in :ref:`compatible
<dt-important-props>` properties.
- If your device is manufactured by a specific vendor, then its compatible
should have a vendor prefix.
If your binding describes hardware with a well known vendor from the list in
:zephyr_file:`dts/bindings/vendor-prefixes.txt`, you must use that vendor
prefix.
- If your device is not manufactured by a specific hardware vendor, do **not**
invent a vendor prefix. Vendor prefixes are not mandatory parts of compatible
properties, and compatibles should not include them unless they refer to an
actual vendor. There are some exceptions to this rule, but the practice is
strongly discouraged.
- Do not submit additions to Zephyr's :file:`dts/bindings/vendor-prefixes.txt`
file unless you also include users of the new prefix. This means at least a
binding and a devicetree using the vendor prefix, and should ideally include
a device driver handling that compatible.
For custom bindings, you can add a custom
:file:`dts/bindings/vendor-prefixes.txt` file to any directory in your
:ref:`DTS_ROOT <dts_root>`. The devicetree tooling will respect these
prefixes, and will not generate warnings or errors if you use them in your
own bindings or devicetrees.
- We sometimes synchronize Zephyr's vendor-prefixes.txt file with the Linux
kernel's equivalent file; this process is exempt from the previous rule.
- If your binding is describing an abstract class of hardware with Zephyr
specific drivers handling the nodes, it's usually best to use ``zephyr`` as
the vendor prefix. See :ref:`dt_vendor_zephyr` for examples.
.. _dt-bindings-default-rules:
Rules for default values
************************
In any case where ``default:`` is used in a devicetree binding, the
``description:`` for that property **must** explain *why* the value was
selected and any conditions that would make it necessary to provide a different
value. Additionally, if changing one property would require changing another to
create a consistent configuration, then those properties should be made
required.
There is no need to document the default value itself; this is already present
in the :ref:`devicetree_binding_index` output.
There is a risk in using ``default:`` when the value in the binding may be
incorrect for a particular board or hardware configuration. For example,
defaulting the capacity of the connected power cell in a charging IC binding
is likely to be incorrect. For such properties it's better to make the
property ``required: true``, forcing the user to make an explicit choice.
Driver developers should use their best judgment as to whether a value can be
safely defaulted. Candidates for default values include:
- delays that would be different only under unusual conditions
(such as intervening hardware)
- configuration for devices that have a standard initial configuration (such as
a USB audio headset)
- defaults which match the vendor-specified power-on reset value
(as long as they are independent from other properties)
Examples of how to write descriptions according to these rules:
.. code-block:: yaml
properties:
cs-interval:
type: int
default: 0
description: |
Minimum interval between chip select deassertion and assertion.
The default corresponds to the reset value of the register field.
hold-time-ms:
type: int
default: 20
description: |
Amount of time to hold the power enable GPIO asserted before
initiating communication. The default was recommended in the
manufacturer datasheet, and would only change under very
cold temperatures.
Some examples of what **not** to do, and why:
.. code-block:: yaml
properties:
# Description doesn't mention anything about the default
foo:
type: int
default: 1
description: number of foos
# Description mentions the default value instead of why it
# was chosen
bar:
type: int
default: 2
description: bar size; default is 2
# Explanation of the default value is in a comment instead
# of the description. This won't be shown in the bindings index.
baz:
type: int
# This is the recommended value chosen by the manufacturer.
default: 2
description: baz time in milliseconds
The ``zephyr,`` prefix
**********************
You must add this prefix to property names in the following cases:
- Zephyr-specific extensions to bindings we share with upstream Linux. One
example is the ``zephyr,vref-mv`` ADC channel property which is common to ADC
controllers defined in :zephyr_file:`dts/bindings/adc/adc-controller.yaml`.
This channel binding is partially shared with an analogous Linux binding, and
Zephyr-specific extensions are marked as such with the prefix.
- Configuration values that are specific to a Zephyr device driver. One example
is the ``zephyr,lazy-load`` property in the :dtcompatible:`ti,bq274xx`
binding. Though devicetree in general is a hardware description and
configuration language, it is Zephyr's only mechanism for configuring driver
behavior for an individual ``struct device``. Therefore, as a compromise,
we do allow some software configuration in Zephyr's devicetree bindings, as
long as they use this prefix to show that they are Zephyr specific.
You may use the ``zephyr,`` prefix when naming a devicetree compatible that is
specific to Zephyr. One example is
:dtcompatible:`zephyr,ipc-openamp-static-vrings`. In this case, it's permitted
but not required to add the ``zephyr,`` prefix to properties defined in the
binding.
Part 3
한국어 전문 번역
Upstream binding 작성 규칙
이 문서는 Zephyr Project upstream에 제출할 binding의 일반 규칙을 설명합니다. Upstream에 기여하지 않을 자체 binding은 반드시 따를 필요가 없지만 같은 기준을 적용하는 편이 좋습니다.
Zephyr devicetree maintainer의 개별 결정은 이 문서보다 우선합니다. 문서와 다른 결정을 받았다면 maintainer에게 알려 문서를 갱신하게 하거나 직접 patch를 제출해야 합니다.
기존 binding을 먼저 확인
Zephyr는 다른 devicetree 사용자와의 source compatibility를 지향합니다. 권위 있는 위치에 같은 장치의 기존 binding이 있다면 그 property를 최대한 재현해야 하며, Zephyr 전용으로 다르게 만든 부분은 반드시 근거를 제시해야 합니다.
- Mainline Linux kernel의
Documentation/devicetree/bindings에 binding이 있는 경우 - Hardware vendor가 Linux kernel 밖에서 공식 binding을 제공하는 경우
Linux mainline tree와 Linux devicetree 문서는 기존 이름·property·semantics를 확인하는 기준 자료입니다.
일반 규칙
파일 이름
Compatible과 일치하는 binding은 그 compatible을 바탕으로 파일 이름을 지어야 합니다. vnd,foo binding은 vnd,foo.yaml입니다. Bus 전용 binding은 bus 이름을 덧붙일 수 있으므로 on-bus: bar라면 vnd,foo-bar.yaml도 허용됩니다.
권장 사항도 제출 시에는 요구 사항
Binding default 문서의 모든 권장 사항은 upstream 제출 시 필수 조건입니다. 특히 default를 사용하면 property 설명에서 그 값을 선택한 이유를 밝혀야 합니다.
Description 표기
짧은 description은 한 줄로 쓸 수 있습니다.
description: my short string길거나 여러 줄인 설명은 반드시 YAML literal block인 | 형식을 사용합니다.
description: |
My very long string
goes here.
Look at all these lines!|는 YAML parser가 줄바꿈을 제거하지 않게 하므로 긴 설명이 Devicetree binding index에 올바르게 표시됩니다.
이름 규칙
Property 이름에는 대문자와 underscore를 쓰지 않습니다. 대문자는 lowercase로, underscore는 dash로 바꿉니다. Linux처럼 이미 널리 정착된 binding을 그대로 재현할 때만 예외입니다.
Vendor prefix 규칙
- 특정 vendor가 제조한 장치는 compatible에 vendor prefix를 사용합니다.
dts/bindings/vendor-prefixes.txt에 알려진 vendor라면 등록된 prefix를 반드시 사용합니다. - 특정 hardware vendor가 없는 장치에는 prefix를 만들어 붙이지 않습니다. Prefix는 compatible의 필수 문법이 아니며 실제 vendor를 뜻할 때만 넣어야 합니다.
- 새 prefix 사용자 없이
vendor-prefixes.txt만 수정해 제출하지 않습니다. 최소한 새 binding과 그 prefix를 사용하는 devicetree가 필요하고, 가능하면 compatible을 처리하는 driver도 포함해야 합니다. - 자체 binding에서는
DTS_ROOT의 어느 경로든 별도dts/bindings/vendor-prefixes.txt를 둘 수 있습니다. Tooling은 이 prefix를 인정해 warning이나 error를 내지 않습니다. - Zephyr가 Linux의 동등 파일과 vendor prefix 목록을 동기화하는 작업은 새 사용자 동반 규칙의 예외입니다.
- Zephyr 전용 driver가 처리하는 추상 hardware class는 보통 vendor prefix로
zephyr를 쓰는 것이 좋습니다.
Default 값 규칙
Binding에서 default를 사용하면 해당 property의 description은 왜 그 값을 골랐는지, 어떤 조건에서 다른 값을 지정해야 하는지를 설명해야 합니다. 한 property를 바꾸면 일관성을 위해 다른 property도 함께 바꿔야 하는 구조라면 두 값을 default로 숨기지 말고 필수 property로 만들어야 합니다.
Default 숫자 자체는 binding index가 이미 보여 주므로 설명에 반복할 필요가 없습니다. Board나 hardware 구성에 따라 틀릴 가능성이 있는 값에 default를 두는 것은 위험합니다. 예를 들어 charger IC에 연결된 battery capacity는 board마다 달라질 수 있으므로 required: true로 사용자가 명시하게 하는 편이 낫습니다.
안전한 default 후보는 다음과 같습니다.
- 중간 hardware가 끼는 등 이례적인 조건에서만 달라지는 delay
- USB audio headset처럼 표준 초기 구성을 가진 장치의 설정
- 다른 property와 독립적이면서 vendor가 지정한 power-on reset 값과 같은 값
다음은 reset register 값과 datasheet 권장값을 선택 이유로 정확히 설명한 좋은 예입니다.
properties:
cs-interval:
type: int
default: 0
description: |
Minimum interval between chip select deassertion and assertion.
The default corresponds to the reset value of the register field.
hold-time-ms:
type: int
default: 20
description: |
Amount of time to hold the power enable GPIO asserted before
initiating communication. The default was recommended in the
manufacturer datasheet, and would only change under very
cold temperatures.다음은 잘못된 예입니다. foo는 default를 전혀 설명하지 않고, bar는 선택 이유 대신 숫자만 반복하며, baz는 binding index에 나타나지 않는 YAML comment에 근거를 숨깁니다.
properties:
# Description doesn't mention anything about the default
foo:
type: int
default: 1
description: number of foos
# Description mentions the default value instead of why it
# was chosen
bar:
type: int
default: 2
description: bar size; default is 2
# Explanation of the default value is in a comment instead
# of the description. This won't be shown in the bindings index.
baz:
type: int
# This is the recommended value chosen by the manufacturer.
default: 2
description: baz time in millisecondszephyr, prefix
Linux와 공유하는 binding에 Zephyr 전용 property를 확장할 때는 zephyr, prefix가 필수입니다. 예를 들어 공통 ADC channel binding의 zephyr,vref-mv는 Linux 유사 binding과 공유되지 않는 확장임을 표시합니다.
개별 struct device의 Zephyr driver 동작을 조정하는 software 설정에도 이 prefix가 필요합니다. Devicetree는 원칙적으로 hardware 설명·설정 언어지만 Kconfig가 instance별 driver 동작을 유연하게 조절하지 못하므로, ti,bq274xx의 zephyr,lazy-load처럼 Zephyr 전용임을 분명히 표시하는 조건으로 허용됩니다.
Compatible 자체가 Zephyr 전용이면 zephyr,ipc-openamp-static-vrings처럼 zephyr, prefix를 사용할 수 있습니다. 이 경우 그 binding 내부 property에도 prefix를 붙이는 것은 허용되지만 필수는 아닙니다.
Source
출처
원문 파일의 단락, directive, 표, 코드, symbol, 경로는 영어 원문 영역에 그대로 보존했습니다.