Devicetree

This page contains reference documentation for <devicetree.h>. See Devicetree Guide for an introduction. Use of these macros has no impact on scheduling. They can be used from any calling context and at file scope.

Some of these require a special macro named DT_DRV_COMPAT to be defined before they can be used; these are discussed individually below. These macros are generally meant for use within device drivers.

Generic APIs

These APIs can be used anywhere.

Node identifiers

You can use node identifiers for devicetree nodes which are enabled (i.e. have status = "okay"; properties) and have matching compatibles. This can be tested with DT_HAS_NODE().

group devicetree-generic-id

devicetree.h API

Defines

DT_ROOT

Node identifier for the root node in the devicetree.

DT_PATH(...)

Get a node identifier for a devicetree path.

Example devicetree fragment:

/ {
        soc {
                my-serial: serial@40002000 {
                        status = "okay";
                        current-speed = <115200>;
                        ...
                };
        };
};

Example usage with DT_PROP() to get current-speed:

DT_PROP(DT_PATH(soc, serial_40002000), current_speed) // 115200

The arguments to this macro are the names of non-root nodes in the tree required to reach the desired node, starting from the root. Non-alphanumeric characters in each name must be converted to underscores to form valid C tokens, and letters must be lowercased.

That is:

  • a first argument corresponds to a child node of the root (“soc” above)

  • a second argument corresponds to a child of the first argument (“serial_40002000” above, from the node name “serial@40002000” after changing “@” to “_”)

  • and so on for deeper nodes until the desired path is given

Return

node identifier for the node with that path

Parameters
  • ...: lowercase-and-underscores node names along the node’s path, with each name given as a separate argument

DT_NODELABEL(label)

Get a node identifier for a node label.

Example devicetree fragment:

my-serial: serial@40002000 {
        label = "UART_0";
        status = "okay";
        current-speed = <115200>;
        ...
};

The only node label in this example is “my-serial”. The string “UART_0” is not a node label; it’s the value of a property named “label”.

Example usage to get current-speed:

DT_PROP(DT_NODELABEL(my_serial), current_speed) // 115200

Convert non-alphanumeric characters in the label to underscores as shown, and lowercase all letters.

Another example devicetree fragment:

cpu@0 {
       L2_0: l2-cache {
               cache-level = <2>;
               ...
       };
};

Example usage to get cache-level:

DT_PROP(DT_NODELABEL(l2_0), cache_level) // 2

Notice how “L2_0” in the devicetree is lowercased to “l2_0” for this macro’s argument.

Return

node identifier for the node with that label

Parameters
  • label: lowercase-and-underscores node label name

DT_ALIAS(alias)

Get a node identifier for an alias.

Example devicetree fragment:

aliases {
        my-serial = &serial0;
};

serial0: serial@40002000 {
        status = "okay";
        current-speed = <115200>;
        ...
};

Example usage to get current-speed:

DT_PROP(DT_ALIAS(my_serial), current_speed) // 115200

Convert non-alphanumeric characters in the alias to underscores as shown, and lowercase all letters.

Return

node identifier for the node with that alias

Parameters
  • alias: lowercase-and-underscores alias name.

DT_INST(inst, compat)

Get a node identifier for an instance of a compatible.

Instance numbers are just indexes among enabled nodes with the same compatible. This complicates their use outside of device drivers. The only guarantees are:

  • instance numbers start at 0,

  • are contiguous, and

  • exactly one is assigned for each enabled node with a matching compatible

Instance numbers in no way reflect any numbering scheme that might exist in SoC documentation, node labels or unit addresses, or properties of the /aliases node. There is no guarantee that the same node will have the same instance number between builds, even if you are building the same application again in the same build directory.

Example devicetree fragment:

serial@40002000 {
        compatible = "vnd,soc-serial";
        status = "okay";
        current-speed = <115200>;
        ...
};

Example usage to get current-speed, assuming that this node is instance number zero of the compatible “vnd,soc-serial”:

DT_PROP(DT_INST(0, vnd_soc_serial), current_speed) // 115200

Return

node identifier for the node with that instance number and compatible

Parameters
  • inst: instance number

  • compat: lowercase-and-underscores compatible, without quotes

Property access

group devicetree-generic-prop

Defines

DT_PROP(node_id, prop)

Get a devicetree property value.

For properties whose bindings have the following types, this macro expands to:

  • string: a string literal

  • boolean: 0 if the property is false, or 1 if it is true

  • int: the property’s value as an integer literal

  • array, uint8-array, string-array: an initializer expression in braces, whose elements are integer or string literals (like {0, 1, 2}, {“hello”, “world”}, etc.)

  • phandle: a node identifier

For other properties, behavior is undefined.

For examples, see DT_PATH(), DT_ALIAS(), DT_NODELABEL(), and DT_INST().

Return

a representation of the property’s value

Parameters
  • node_id: node identifier

  • prop: lowercase-and-underscores property name

DT_PROP_LEN(node_id, prop)

Get a property’s logical length.

Here, “length” is a number of elements, which may not be a size in bytes.

For properties whose binding has type array, string-array, or uint8-array, this expands to the number of elements in the array.

For properties of type phandles or phandle-array, it expands to the number of phandles or phandle+specifiers respectively.

These properties are handled as special cases:

  • reg property: use DT_NUM_REGS(node_id) instead

  • interrupts property: use DT_NUM_IRQS(node_id) instead

It is an error to use this macro with the above properties.

For other properties, behavior is undefined.

Return

the property’s length

Parameters
  • node_id: node identifier

  • prop: a lowercase-and-underscores property with a logical length

DT_PROP_HAS_IDX(node_id, prop, idx)

Is index “idx” valid for an array type property?

If this returns 1, then DT_PROP_BY_IDX(node_id, prop, idx) or DT_PHA_BY_IDX(node_id, pha, idx, cell) are valid at index “idx”. If it returns 0, it is an error to use those macros with that index.

These properties are handled as special cases:

  • reg property: use DT_REG_HAS_IDX(node_id, idx) instead

  • interrupts property: use DT_IRQ_HAS_IDX(node_id, idx) instead

It is an error to use this macro with the above properties.

Return

1 if “idx” is a valid index into the given property, 0 otherwise.

Parameters
  • node_id: node identifier

  • prop: a lowercase-and-underscores property with a logical length

  • idx: index to check

DT_PROP_BY_IDX(node_id, prop, idx)

Get the value at index “idx” in an array type property.

It might help to read the argument order as being similar to “node->property[index]”.

When the property’s binding has type array, string-array, uint8-array, or phandles, this expands to the idx-th array element as an integer, string literal, or node identifier respectively.

These properties are handled as special cases:

  • reg property: use DT_REG_ADDR_BY_IDX() or DT_REG_SIZE_BY_IDX() instead

  • interrupts property: use DT_IRQ_BY_IDX() instead

For non-array properties, behavior is undefined.

Return

a representation of the idx-th element of the property

Parameters
  • node_id: node identifier

  • prop: lowercase-and-underscores property name

  • idx: the index to get

DT_LABEL(node_id)

Equivalent to DT_PROP(node_id, label)

This is a convenience for the Zephyr device API, which uses label properties as device_get_binding() arguments.

Return

node’s label property value

Parameters
  • node_id: node identifier

DT_ENUM_IDX(node_id, prop)

Get a property value’s index into its enumeration values.

The return values start at zero.

Example devicetree fragment:

usb1: usb@12340000 {
        maximum-speed = "full-speed";
};
usb2: usb@12341000 {
        maximum-speed = "super-speed";
};

Example bindings fragment:

properties:
  maximum-speed:
    type: string
    enum:
       - "low-speed"
       - "full-speed"
       - "high-speed"
       - "super-speed"

Example usage:

DT_ENUM_IDX(DT_NODELABEL(usb1), maximum_speed) // 1
DT_ENUM_IDX(DT_NODELABEL(usb2), maximum_speed) // 3

Return

zero-based index of the property’s value in its enum: list

Parameters
  • node_id: node identifier

  • prop: lowercase-and-underscores property name

DT_PROP_BY_PHANDLE(node_id, ph, prop)

Get a property value from a phandle’s node.

This is a shorthand for DT_PROP_BY_PHANDLE_IDX(node_id, ph, 0, prop). It helps readability when “ph” has type “phandle”.

Return

the value of “prop” as described in the DT_PROP() documentation

Parameters
  • node_id: node identifier

  • ph: lowercase-and-underscores property of “node_id” with type “phandle”

  • prop: lowercase-and-underscores property of the phandle’s node

DT_PROP_BY_PHANDLE_IDX(node_id, phs, idx, prop)

Get a property value from a phandle in a property.

This is a shorthand for:

DT_PROP(DT_PHANDLE_BY_IDX(node_id, phs, idx), prop)

That is, “prop” is a property of the phandle’s node, not a property of “node_id”.

Example devicetree fragment:

n1: node-1 {
        foo = <&n2 &n3>;
};

n2: node-2 {
        bar = <42>;
};

n3: node-3 {
        baz = <43>;
};

Example usage:

#define N1 DT_NODELABEL(n1)

DT_PROP_BY_PHANDLE_IDX(N1, foo, 0, bar) // 42
DT_PROP_BY_PHANDLE_IDX(N1, foo, 1, baz) // 43

Return

the value of “prop” as described in the DT_PROP() documentation

Parameters
  • node_id: node identifier

  • phs: lowercase-and-underscores property with type “phandle”, “phandles”, or “phandle-array”

  • idx: logical index into “phs”, which must be zero if “phs” has type “phandle”

  • prop: lowercase-and-underscores property of the phandle’s node

DT_PHA_BY_IDX(node_id, pha, idx, cell)

Get a phandle-array specifier value at an index.

It might help to read the argument order as being similar to “node->phandle[index].cell”. That is, the cell value is in the “pha” property of “node_id”.

Example devicetree fragment:

gpio0: gpio@12340000 {
        #gpio-cells = < 2 >;
};

led: led_0 {
        gpios = < &gpio0 17 0x1 >;
};

Bindings fragment for the gpio0 node:

gpio-cells:
  - pin
  - flags

Example usage:

#define LED DT_NODELABEL(led)

DT_PHA_BY_IDX(LED, gpios, pin, 0)   // 17
DT_PHA_BY_IDX(LED, gpios, flags, 0) // 0x1

Return

the value of the cell inside the specifier at index “idx”

Parameters
  • node_id: node identifier

  • pha: lowercase-and-underscores property with type “phandle-array”

  • idx: logical index into the property “pha”

  • cell: binding’s cell name within the specifier at index “idx”

DT_PHA(node_id, pha, cell)

Equivalent to DT_PHA_BY_IDX(node_id, pha, 0, cell)

Return

the cell value

Parameters
  • node_id: node identifier

  • pha: lowercase-and-underscores property with type “phandle-array”

  • cell: binding’s cell name for the specifier at “pha” index 0

DT_PHA_BY_NAME(node_id, pha, name, cell)

Get a value within a phandle-array specifier by name.

This is like DT_PHA_BY_IDX(), except it treats “pha” as a structure where each specifier has a name.

It might help to read the argument order as being similar to “node->phandle_struct.name.cell”. That is, the cell value is in the “pha” property of “node_id”, treated as a data structure with named components.

Example devicetree fragment:

n: node {
        io-channels = <&adc1 10>, <&adc2 20>;
        io-channel-names = "SENSOR", "BANDGAP";
};

Bindings fragment for the “adc1” and “adc2” nodes:

io-channel-cells:
  - input

Example usage:

DT_PHA_BY_NAME(DT_NODELABEL(n), io_channels, sensor, input)  // 10
DT_PHA_BY_NAME(DT_NODELABEL(n), io_channels, bandgap, input) // 20

Return

the cell value

Parameters
  • node_id: node identifier

  • pha: lowercase-and-underscores property with type “phandle-array”

  • name: lowercase-and-underscores name of a specifier in “pha”

  • cell: binding’s cell name for the named specifier

DT_PHANDLE_BY_NAME(node_id, pha, name)

Get a phandle’s node identifier from a phandle array by name.

It might help to read the argument order as being similar to “node->phandle_struct.name.phandle”. That is, the phandle array is treated as a structure with named components. The return value is the node identifier for a phandle inside the structure.

Example devicetree fragment:

adc1: adc@... {
        label = "ADC_1";
};

adc2: adc@... {
        label = "ADC_2";
};

n: node {
        io-channels = <&adc1 10>, <&adc2 20>;
        io-channel-names = "SENSOR", "BANDGAP";
};

Example usage:

#define NODE DT_NODELABEL(n)

DT_LABEL(DT_PHANDLE_BY_NAME(NODE, io_channels, sensor))  // "ADC_1"
DT_LABEL(DT_PHANDLE_BY_NAME(NODE, io_channels, bandgap)) // "ADC_2"

Return

node identifier for the phandle at the element named “name”

Parameters
  • node_id: node identifier

  • pha: lowercase-and-underscores property with type “phandle-array”

  • name: lowercase-and-underscores name of an element in “pha”

DT_PHANDLE_BY_IDX(node_id, prop, idx)

Get a node identifier for a phandle in a property.

When a node’s value at a logical index contains a phandle, this macro returns a node identifier for the node with that phandle.

Therefore, if “prop” has type “phandle”, “idx” must be zero. (A “phandle” type is treated as a “phandles” with a fixed length of 1).

Example devicetree fragment:

n1: node-1 {
        foo = <&n2 &n3>;
};

n2: node-2 { ... };
n3: node-3 { ... };

Example usage:

#define N1 DT_NODELABEL(n1)

DT_PHANDLE_BY_IDX(N1, foo, 0) // node identifier for node-2
DT_PHANDLE_BY_IDX(N1, foo, 1) // node identifier for node-3

Behavior is analogous for phandle-arrays.

Return

a node identifier for the phandle at index “idx” in “prop”

Parameters
  • node_id: node identifier

  • prop: lowercase-and-underscores property name in “node_id” with type “phandle”, “phandles” or “phandle-array”

  • idx: index into “prop”

DT_PHANDLE(node_id, prop)

Get a node identifier for a phandle property’s value.

This is equivalent to DT_PHANDLE_BY_IDX(node_id, prop, 0). Its primary benefit is readability when “prop” has type “phandle”.

Return

a node identifier for the node pointed to by “ph”

Parameters
  • node_id: node identifier

  • prop: lowercase-and-underscores property of “node_id” with type “phandle”

DT_NUM_REGS(node_id)

Get the number of register blocks in the reg property.

Use this instead of DT_PROP_LEN(node_id, reg).

Return

Number of register blocks in the node’s “reg” property.

Parameters
  • node_id: node identifier

DT_REG_HAS_IDX(node_id, idx)

Is “idx” a valid register block index?

If this returns 1, then DT_REG_ADDR_BY_IDX(node_id, idx) or DT_REG_SIZE_BY_IDX(node_id, idx) are valid. If it returns 0, it is an error to use those macros with index “idx”.

Return

1 if “idx” is a valid register block index, 0 otherwise.

Parameters
  • node_id: node identifier

  • idx: index to check

DT_REG_ADDR_BY_IDX(node_id, idx)

Get the base address of the register block at index “idx”.

Return

address of the idx-th register block

Parameters
  • node_id: node identifier

  • idx: index of the register whose address to return

DT_REG_SIZE_BY_IDX(node_id, idx)

Get the size of the register block at index “idx”.

This is the size of an individual register block, not the total number of register blocks in the property; use DT_NUM_REGS() for that.

Return

size of the idx-th register block

Parameters
  • node_id: node identifier

  • idx: index of the register whose size to return

DT_REG_ADDR(node_id)

Get a node’s (only) register block address.

Equivalent to DT_REG_ADDR_BY_IDX(node_id, 0).

Return

node’s register block address

Parameters
  • node_id: node identifier

DT_REG_SIZE(node_id)

Get a node’s (only) register block size.

Equivalent to DT_REG_SIZE_BY_IDX(node_id, 0).

Return

node’s only register block’s size

Parameters
  • node_id: node identifier

DT_REG_ADDR_BY_NAME(node_id, name)

Get a register block’s base address by name.

Return

address of the register block specified by name

Parameters
  • node_id: node identifier

  • name: lowercase-and-underscores register specifier name

DT_REG_SIZE_BY_NAME(node_id, name)

Get a register block’s size by name.

Return

size of the register block specified by name

Parameters
  • node_id: node identifier

  • name: lowercase-and-underscores register specifier name

DT_NUM_IRQS(node_id)

Get the number of interrupt sources for the node.

Use this instead of DT_PROP_LEN(node_id, interrupts).

Return

Number of interrupt specifiers in the node’s “interrupts” property.

Parameters
  • node_id: node identifier

DT_IRQ_HAS_IDX(node_id, idx)

Is “idx” a valid interrupt index?

If this returns 1, then DT_IRQ_BY_IDX(node_id, idx) is valid. If it returns 0, it is an error to use that macro with this index.

Return

1 if the idx is valid for the interrupt property 0 otherwise.

Parameters
  • node_id: node identifier

  • idx: index to check

DT_IRQ_BY_IDX(node_id, idx, cell)

Get a value within an interrupt specifier at an index.

It might help to read the argument order as being similar to “node->interrupts[index].cell”.

This can be used to get information about an individual interrupt when a device generates more than one.

Example devicetree fragment:

my-serial: serial@... {
        interrupts = < 33 0 >, < 34 1 >;
};

Assuming the node’s interrupt domain has “#interrupt-cells = <2>;” and the individual cells in each interrupt specifier are named “irq” and “priority” by the node’s binding, here are some examples:

#define SERIAL DT_NODELABEL(my_serial)

Example usage                    Value
-------------                    -----
DT_IRQ_BY_IDX(SERIAL, 0, irq)          33
DT_IRQ_BY_IDX(SERIAL, 0, priority)      0
DT_IRQ_BY_IDX(SERIAL, 1, irq,          34
DT_IRQ_BY_IDX(SERIAL, 1, priority)      1

Return

the named value at the specifier given by the index

Parameters
  • node_id: node identifier

  • idx: logical index into the interrupt specifier array

  • cell: cell name specifier

DT_IRQ_BY_NAME(node_id, name, cell)

Get a value within an interrupt specifier by name.

It might help to read the argument order as being similar to “node->interrupts.name.cell”.

This can be used to get information about an individual interrupt when a device generates more than one, if the bindings give each interrupt specifier a name.

Return

the named value at the specifier given by the index

Parameters
  • node_id: node identifier

  • name: lowercase-and-underscores interrupt specifier name

  • cell: cell name specifier

DT_IRQ(node_id, cell)

Get an interrupt specifier’s value Equivalent to DT_IRQ_BY_IDX(node_id, 0, cell).

Return

the named value at that index

Parameters
  • node_id: node identifier

  • cell: cell name specifier

DT_IRQN(node_id)

Get a node’s (only) irq number.

Equivalent to DT_IRQ(node_id, irq). This is provided as a convenience for the common case where a node generates exactly one interrupt, and the IRQ number is in a cell named “irq”.

Return

the interrupt number for the node’s only interrupt

Parameters
  • node_id: node identifier

Chosen nodes

group devicetree-generic-chosen

Defines

DT_CHOSEN(prop)

Get a node identifier for a /chosen node property This is only valid to call if DT_HAS_CHOSEN(prop) is 1.

Return

a node identifier for the chosen node property

Parameters
  • prop: lowercase-and-underscores property name for the /chosen node

Existence checks

group devicetree-generic-exist

Defines

DT_HAS_NODE(node_id)

Does a node identifier refer to a usable node?

Example uses:

DT_HAS_NODE(DT_PATH(soc, i2c@12340000))
DT_HAS_NODE(DT_ALIAS(an_alias_name))

Tests whether a node identifier refers to a node which:

  • exists in the devicetree, and

  • is enabled (has status property “okay”), and

  • has a matching binding

Return

1 if the node identifier refers to a usable node, 0 otherwise.

Parameters
  • node_id: a node identifier

DT_HAS_COMPAT(compat)

Does the devicetree have any usable nodes with a compatible?

Test for whether the devicetree has any usable nodes (as determined by DT_HAS_NODE()) with a given compatible, i.e. if there is at least one “x” for which “DT_HAS_NODE(DT_INST(x, compat))” is 1.

Return

0 if no nodes of the compatible are available for use, 1 if at least one is enabled and has a matching binding

Parameters
  • compat: lowercase-and-underscores version of a compatible

DT_NUM_INST(compat)

Get the number of enabled instances for a given compatible.

Return

Number of enabled instances

Parameters
  • compat: lowercase-and-underscores version of a compatible

DT_HAS_CHOSEN(prop)

Test if the devicetree has a /chosen node.

Return

1 if the chosen property exists and refers to a node, 0 otherwise

Parameters
  • prop: lowercase-and-underscores devicetree property

DT_NODE_HAS_COMPAT(node_id, compat)

Does a devicetree node match a compatible?

Example devicetree fragment:

n: node {
        compatible = "vnd,specific-device", "generic-device";
}

Example usages which evaluate to 1:

DT_NODE_HAS_COMPAT(DT_NODELABEL(n), vnd_specific_device)
DT_NODE_HAS_COMPAT(DT_NODELABEL(n), generic_device)

This macro only uses the value of the compatible property. Whether or not a particular compatible has a matching binding has no effect on its value.

Return

1 if the node’s compatible property contains compat, 0 otherwise.

Parameters
  • node_id: node identifier

  • compat: lowercase-and-underscorse compatible value

DT_NODE_HAS_PROP(node_id, prop)

Does a devicetree node have a property?

Tests whether a devicetree node has a property defined. This tests whether the property is part of the node at all, not whether a boolean property is true or not.

Return

1 if the node has the property, 0 otherwise.

Parameters
  • node_id: node identifier

  • prop: lowercase-and-underscores property name

DT_PHA_HAS_CELL_AT_IDX(node_id, pha, idx, cell)

Does a phandle array have a named cell specifier at an index? If this returns 1, then the cell argument to DT_PHA_BY_IDX(node_id, pha, idx, cell) is valid. If it returns 0, it is an error.

Return

1 if the named cell exists in the specifier at index idx, 0 otherwise.

Parameters
  • node_id: node identifier

  • pha: lowercase-and-underscores property with type “phandle-array”

  • idx: index to check

  • cell: named cell value whose existence to check

DT_PHA_HAS_CELL(node_id, pha, cell)

Equivalent to DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell)

Return

1 if the named ceell exists in the specifier at index 0, 0 otherwise.

Parameters
  • node_id: node identifier

  • pha: lowercase-and-underscores property with type “phandle-array”

  • cell: named cell value whose existence to check

DT_IRQ_HAS_CELL_AT_IDX(node_id, idx, cell)

Does an interrupts property have a named cell specifier at an index? If this returns 1, then DT_IRQ_BY_IDX(node_id, idx, cell) is valid. If it returns 0, it is an error to use that macro.

Return

1 if the named cell exists in the interrupt specifier at index idx 0 otherwise.

Parameters
  • node_id: node identifier

  • idx: index to check

  • cell: named cell value whose existence to check

DT_IRQ_HAS_CELL(node_id, cell)

Equivalent to DT_IRQ_HAS_CELL_AT_IDX(node_id, 0, cell)

Return

1 if the named cell exists in the interrupt specifier at index 0 0 otherwise.

Parameters
  • node_id: node identifier

  • cell: named cell value whose existence to check

DT_IRQ_HAS_NAME(node_id, name)

Does an interrupts property have a named specifier value at an index? If this returns 1, then DT_IRQ_BY_NAME(node_id, name, cell) is valid. If it returns 0, it is an error to use that macro.

Return

1 if “name” is a valid named specifier 0 otherwise.

Parameters
  • node_id: node identifier

  • name: lowercase-and-underscores interrupt specifier name

Bus helpers

group devicetree-generic-bus

Defines

DT_BUS(node_id)

Node’s bus controller.

Get the node identifier of the node’s bus controller. This can be used with DT_PROP() to get properties of the bus controller.

It is an error to use this with nodes which do not have bus controllers.

Example devicetree fragment:

i2c@deadbeef {
        label = "I2C_CTLR";
        status = "okay";
        clock-frequency = < 100000 >;

        i2c_device: accelerometer@12 {
                ...
        };
};

Example usage:

DT_PROP(DT_BUS(DT_NODELABEL(i2c_device)), clock_frequency) // 100000

Return

a node identifier for the node’s bus controller

Parameters
  • node_id: node identifier

DT_BUS_LABEL(node_id)

Node’s bus controller’s label property.

Return

the label property of the node’s bus controller DT_BUS(node)

Parameters
  • node_id: node identifier

DT_ON_BUS(node_id, bus)

Test if a node’s bus type is a given type.

Example devicetree overlay:

&i2c0 {
       temp: temperature-sensor@76 {
                compatible = "vnd,some-sensor";
                reg = <0x76>;
       };
};

Example usage, assuming “i2c0” is an I2C bus controller node, and therefore “temp” is on an I2C bus:

DT_ON_BUS(DT_NODELABEL(temp), i2c) // 1
DT_ON_BUS(DT_NODELABEL(temp), spi) // 0

Return

1 if the node is on a bus of the given type, 0 otherwise

Parameters
  • node_id: node identifier

  • bus: a binding’s bus type as a C token, lowercased and without quotes

Instance-based APIs

These are recommended for use within device drivers. To use them, define DT_DRV_COMPAT to the lowercase-and-underscores compatible the device driver implements support for. Note that there are also helpers available for specific hardware; these are documented in the following sections.

It is an error to use these macros without DT_DRV_COMPAT defined.

group devicetree-inst

Defines

DT_DRV_INST(inst)

Node identifier for an instance of a DT_DRV_COMPAT compatible.

Return

a node identifier for the node with DT_DRV_COMPAT compatible and instance number “inst”

Parameters
  • inst: instance number

DT_INST_PROP(inst, prop)

Get a DT_DRV_COMPAT instance property.

Return

a representation of the property’s value

Parameters
  • inst: instance number

  • prop: lowercase-and-underscores property name

DT_INST_PROP_BY_IDX(inst, prop, idx)

Get a DT_DRV_COMPAT element value in an array property.

Return

a representation of the idx-th element of the property

Parameters
  • inst: instance number

  • prop: lowercase-and-underscores property name

  • idx: the index to get

DT_INST_PROP_HAS_IDX(inst, prop, idx)

Is index “idx” valid for an array type property on a DT_DRV_COMPAT instance?

Return

1 if “idx” is a valid index into the given property, 0 otherwise.

Parameters
  • inst: instance number

  • prop: lowercase-and-underscores property name

  • idx: index to check

DT_INST_PROP_LEN(inst, prop)

Get a DT_DRV_COMPAT property length.

Return

logical length of the property

Parameters
  • inst: instance number

  • prop: lowercase-and-underscores property name

DT_INST_LABEL(inst)

Get a DT_DRV_COMPAT instance’s “label” property.

Return

instance’s label property value

Parameters
  • inst: instance number

DT_INST_PROP_BY_PHANDLE(inst, ph, prop)

Get a DT_DRV_COMPAT instance’s property value from a phandle’s node.

Return

the value of “prop” as described in the DT_PROP() documentation

Parameters
  • inst: instance number

  • ph: lowercase-and-underscores property of “inst” with type “phandle”

  • prop: lowercase-and-underscores property of the phandle’s node

DT_INST_PROP_BY_PHANDLE_IDX(inst, phs, idx, prop)

Get a DT_DRV_COMPAT instance’s property value from a phandle in a property.

Return

the value of “prop” as described in the DT_PROP() documentation

Parameters
  • inst: instance number

  • phs: lowercase-and-underscores property with type “phandle”, “phandles”, or “phandle-array”

  • idx: logical index into “phs”, which must be zero if “phs” has type “phandle”

  • prop: lowercase-and-underscores property of the phandle’s node

DT_INST_PHA_BY_IDX(inst, pha, idx, cell)

Get a DT_DRV_COMPAT instance’s phandle-array specifier value at an index.

Return

the value of the cell inside the specifier at index “idx”

Parameters
  • inst: instance number

  • pha: lowercase-and-underscores property with type “phandle-array”

  • idx: logical index into the property “pha”

  • cell: binding’s cell name within the specifier at index “idx”

DT_INST_PHA(inst, pha, cell)

Get a DT_DRV_COMPAT instance’s phandle-array specifier value Equivalent to DT_INST_PHA_BY_IDX(inst, pha, 0, cell)

Return

the cell value

Parameters
  • inst: instance number

  • pha: lowercase-and-underscores property with type “phandle-array”

  • cell: binding’s cell name for the specifier at “pha” index 0

DT_INST_PHA_BY_NAME(inst, pha, name, cell)

Get a DT_DRV_COMPAT instance’s value within a phandle-array specifier by name.

Return

the cell value

Parameters
  • inst: instance number

  • pha: lowercase-and-underscores property with type “phandle-array”

  • name: lowercase-and-underscores name of a specifier in “pha”

  • cell: binding’s cell name for the named specifier

DT_INST_PHANDLE_BY_NAME(inst, pha, name)

Get a DT_DRV_COMPAT instance’s phandle node identifier from a phandle array by name.

Return

node identifier for the phandle at the element named “name”

Parameters
  • inst: instance number

  • pha: lowercase-and-underscores property with type “phandle-array”

  • name: lowercase-and-underscores name of an element in “pha”

DT_INST_PHANDLE_BY_IDX(inst, prop, idx)

Get a DT_DRV_COMPAT instance’s node identifier for a phandle in a property.

Return

a node identifier for the phandle at index “idx” in “prop”

Parameters
  • inst: instance number

  • prop: lowercase-and-underscores property name in “inst” with type “phandle”, “phandles” or “phandle-array”

  • idx: index into “prop”

DT_INST_PHANDLE(inst, prop)

Get a DT_DRV_COMPAT instance’s node identifier for a phandle property’s value.

Return

a node identifier for the node pointed to by “ph”

Parameters
  • inst: instance number

  • prop: lowercase-and-underscores property of “inst” with type “phandle”

DT_INST_REG_HAS_IDX(inst, idx)

is “idx” a valid register block index on a DT_DRV_COMPAT instance?

Return

1 if “idx” is a valid register block index, 0 otherwise.

Parameters
  • inst: instance number

  • idx: index to check

DT_INST_REG_ADDR_BY_IDX(inst, idx)

Get a DT_DRV_COMPAT instance’s idx-th register block’s address.

Return

address of the instance’s idx-th register block

Parameters
  • inst: instance number

  • idx: index of the register whose address to return

DT_INST_REG_SIZE_BY_IDX(inst, idx)

Get a DT_DRV_COMPAT instance’s idx-th register block’s size.

Return

size of the instance’s idx-th register block

Parameters
  • inst: instance number

  • idx: index of the register whose size to return

DT_INST_REG_ADDR_BY_NAME(inst, name)

Get a DT_DRV_COMPAT’s register block address by name.

Return

address of the register block with the given name

Parameters
  • inst: instance number

  • name: lowercase-and-underscores register specifier name

DT_INST_REG_SIZE_BY_NAME(inst, name)

Get a DT_DRV_COMPAT’s register block size by name.

Return

size of the register block with the given name

Parameters
  • inst: instance number

  • name: lowercase-and-underscores register specifier name

DT_INST_REG_ADDR(inst)

Get a DT_DRV_COMPAT’s (only) register block address Equivalent to DT_INST_REG_ADDR_BY_IDX(inst, 0).

Return

instance’s register block address

Parameters
  • inst: instance number

DT_INST_REG_SIZE(inst)

Get a DT_DRV_COMPAT’s (only) register block size Equivalent to DT_INST_REG_SIZE_BY_IDX(inst, 0).

Return

instance’s register block size

Parameters
  • inst: instance number

DT_INST_IRQ_BY_IDX(inst, idx, cell)

Get a DT_DRV_COMPAT interrupt specifier value at an index (see DT_IRQ_BY_IDX)

Return

the named value at the specifier given by the index

Parameters
  • inst: instance number

  • idx: logical index into the interrupt specifier array

  • cell: cell name specifier

DT_INST_IRQ_BY_NAME(inst, name, cell)

Get a DT_DRV_COMPAT interrupt specifier value by name (see DT_IRQ_BY_NAME)

Return

the named value at the specifier given by the index

Parameters
  • inst: instance number

  • name: lowercase-and-underscores interrupt specifier name

  • cell: cell name specifier

DT_INST_IRQ(inst, cell)

Get a DT_DRV_COMAPT interrupt specifier’s value Equivalent to DT_INST_IRQ_BY_IDX(inst, 0, cell).

Return

the named value at that index

Parameters
  • inst: instance number

  • cell: cell name specifier

DT_INST_IRQN(inst)

Get a DT_DRV_COMPAT’s (only) irq number Equivalent to DT_INST_IRQ(inst, irq).

Return

the interrupt number for the node’s only interrupt

Parameters
  • inst: instance number

DT_INST_BUS_LABEL(inst)

Get a DT_DRV_COMPAT’s bus node’s label property Equivalent to DT_BUS_LABEL(DT_DRV_INST(inst))

Return

the label property of the instance’s bus controller

Parameters
  • inst: instance number

DT_HAS_DRV_INST(inst)

Does the devicetree have a particular instance number?

This is equivalent to DT_HAS_NODE(DT_DRV_INST(inst)).

Return

1 if the devicetree has that numbered instance, 0 otherwise.

Parameters
  • inst: instance number

DT_INST_ON_BUS(inst, bus)

Test if a DT_DRV_COMPAT’s bus type is a given type This is equivalent to DT_ON_BUS(DT_DRV_INST(inst), bus).

Return

1 if the given instance is on a bus of the given type, 0 otherwise

Parameters
  • inst: instance number

  • bus: a binding’s bus type as a C token, lowercased and without quotes

DT_ANY_INST_ON_BUS(bus)

Test if any node with compatible DT_DRV_COMPAT is on a bus.

This is the same as logically ORing together DT_ON_BUS(node, bus) for every enabled node which matches compatible DT_DRV_COMPAT.

It can be useful, for instance, when writing device drivers for hardware that supports multiple possible bus connections to the SoC.

Parameters
  • bus: a binding’s bus type as a C token, lowercased and without quotes

DT_INST_FOREACH(inst_expr)

Call specified macro for all nodes with compatible DT_DRV_COMPAT.

This macro will scan for all DT_INST_ device nodes for that driver. The macro then calls the supplied macro with the instance number. This macro can be used for example to call the init macro of a driver for each device specified in the device tree.

Parameters
  • inst_expr: Macro or function that is called for each device node. Has to accept instance_number as only parameter.

DT_INST_NODE_HAS_PROP(inst, prop)

Does a DT_DRV_COMPAT instance have a property? Equivalent to DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop)

Return

1 if the instance has the property, 0 otherwise.

Parameters
  • inst: instance number

  • prop: lowercase-and-underscores property name

DT_INST_PHA_HAS_CELL_AT_IDX(inst, pha, idx, cell)

Does a phandle array have a named cell specifier at an index? for a DT_DRV_COMPAT instance.

Return

1 if the named cell exists in the specifier at index idx, 0 otherwise.

Parameters
  • inst: instance number

  • pha: lowercase-and-underscores property with type “phandle-array”

  • idx: index to check

  • cell: named cell value whose existence to check

DT_INST_PHA_HAS_CELL(inst, pha, cell)

Does a phandle array have a named cell specifier at index 0 for a DT_DRV_COMPAT instance?

Return

1 if the named cell exists in the specifier at index 0, 0 otherwise.

Parameters
  • inst: instance number

  • pha: lowercase-and-underscores property with type “phandle-array”

  • cell: named cell value whose existence to check

DT_INST_IRQ_HAS_IDX(inst, idx)

is index valid for interrupt property on a DT_DRV_COMPAT instance? Equivalent to DT_IRQ_HAS_IDX(DT_DRV_INST(inst), idx).

Return

1 if the idx is valid for the interrupt property 0 otherwise.

Parameters
  • inst: instance number

  • idx: logical index into the interrupt specifier array

DT_INST_IRQ_HAS_CELL_AT_IDX(inst, idx, cell)

Does a DT_DRV_COMPAT instance have an interrupt named cell specifier? Equivalent to DT_IRQ_HAS_CELL_AT_IDX(DT_DRV_INST(inst), idx, cell).

Return

1 if the named cell exists in the interrupt specifier at index idx 0 otherwise.

Parameters
  • inst: instance number

  • idx: index to check

  • cell: named cell value whose existence to check

DT_INST_IRQ_HAS_CELL(inst, cell)

Does a DT_DRV_COMPAT instance have an interrupt value? Equivalent to DT_INST_IRQ_HAS_IDX(DT_DRV_INST(inst), 0, cell).

Return

1 if the named cell exists in the interrupt specifier at index 0 0 otherwise.

Parameters
  • inst: instance number

  • cell: named cell value whose existence to check

DT_INST_IRQ_HAS_NAME(inst, name)

Does a DT_DRV_COMPAT instance have an interrupt value? Equivalent to DT_INST_IRQ_HAS_NAME(DT_DRV_INST(inst), name).

Return

1 if “name” is a valid named specifier

Parameters
  • inst: instance number

  • name: lowercase-and-underscores interrupt specifier name

Hardware specific APIs

The following APIs can also be used by including <devicetree.h>; no additional include is needed.

ADC

group devicetree-adc

Defines

DT_IO_CHANNELS_LABEL_BY_IDX(node_id, idx)

Get IO channels controller “name” (label property) at an index.

It’s an error if the IO channels controller referenced by the phandle in property “io_channels” at index “idx” has no label property.

Example devicetree fragment:

adc1: adc@... {
        label = "ADC_1";
};

adc2: adc@... {
        label = "ADC_2";
};

n: node {
        io-channels = <&adc1 10>, <&adc2 20>;
};

Example usage:

DT_IO_CHANNELS_LABEL_BY_IDX(DT_NODELABEL(n), 1) // "ADC_2"

Return

the label property for the referenced node at index idx

See

DT_PHANDLE_BY_IDX()

Parameters
  • node_id: node identifier

  • idx: logical index into the property

DT_IO_CHANNELS_LABEL_BY_NAME(node_id, name)

Get IO channels controller “name” (label property) by name.

It’s an error if the IO channels controller referenced by the phandle in property “io_channels” at index “idx” has no label property.

Example devicetree fragment:

adc1: adc@... {
        label = "ADC_1";
};

adc2: adc@... {
        label = "ADC_2";
};

n: node {
        io-channels = <&adc1 10>, <&adc2 20>;
        io-channel-names = "SENSOR", "BANDGAP";
};

Example usage:

DT_IO_CHANNELS_LABEL_BY_NAME(DT_NODELABEL(n), bandgap) // "ADC_2"

Return

the label property for the referenced node by name

See

DT_PHANDLE_BY_NAME()

Parameters
  • node_id: node identifier

  • name: lowercase-and-underscores “io_channel” name

DT_IO_CHANNELS_LABEL(node_id)

Equivalent to DT_IO_CHANNELS_LABEL_BY_IDX(node_id, 0)

Return

the label property for the named specifier at index 0

See

DT_IO_CHANNELS_LABEL_BY_IDX()

Parameters
  • node_id: node identifier

DT_INST_IO_CHANNELS_LABEL_BY_IDX(inst, idx)

Get IO channel’s controller “name” at an index (see DT_IO_CHANNELS_LABEL_BY_IDX)

Return

the label property for the named specifier at index idx

Parameters
  • inst: instance number

  • idx: logical index into the property

DT_INST_IO_CHANNELS_LABEL_BY_NAME(inst, name)

Get IO channel’s controller “name” by name (see DT_IO_CHANNELS_LABEL_BY_NAME)

Return

the label property for the named specifier by name

Parameters
  • inst: instance number

  • name: lowercase-and-underscores “io_channel” name

DT_INST_IO_CHANNELS_LABEL(inst)

Equivalent to DT_INST_IO_CHANNELS_LABEL_BY_IDX(inst, 0)

Return

the label property for the named specifier at index 0

Parameters
  • inst: instance number

DT_IO_CHANNELS_INPUT_BY_IDX(node_id, idx)

Get IO channels controller ‘input’ at an index.

This macro only works for IO channels controllers that specify a ‘input’ field in the phandle-array specifier. Refer to the specific IO channels controller binding if needed.

Return

the input value for the named specifier at index idx

See

DT_PHA_BY_IDX()

See

DT_PHA()

Parameters
  • node_id: node identifier

  • idx: logical index into the property

DT_IO_CHANNELS_INPUT_BY_NAME(node_id, name)

Get IO channels controller ‘input’ by name.

This macro only works for IO channels controllers that specify a ‘input’ field in the phandle-array specifier. Refer to the specific IO channels controller binding if needed.

Return

the input value for the named specifier by name

See

DT_PHA_BY_NAME()

Parameters
  • node_id: node identifier

  • name: lowercase-and-underscores “io_channel” name

DT_IO_CHANNELS_INPUT(node_id)

Equivalent to DT_IO_CHANNELS_INPUT_BY_IDX(node_id, 0)

Return

the label property for the named specifier at index 0

See

DT_IO_CHANNELS_INPUT_BY_IDX()

Parameters
  • node_id: node identifier

DT_INST_IO_CHANNELS_INPUT_BY_IDX(inst, idx)

Get IO channel’s controller “input” at an index (see DT_IO_CHANNELS_INPUT_BY_IDX)

Return

the input value for the named specifier at index idx

Parameters
  • inst: instance number

  • idx: logical index into the property

DT_INST_IO_CHANNELS_INPUT_BY_NAME(inst, name)

Get IO channel’s controller “input” by name (see DT_IO_CHANNELS_INPUT_BY_NAME)

Return

the input value for the named specifier at index idx

Parameters
  • inst: instance number

  • name: lowercase-and-underscores “io_channel” name

DT_INST_IO_CHANNELS_INPUT(inst)

Equivalent to DT_INST_IO_CHANNELS_INPUT(inst, 0)

Return

the input property for the named specifier at index 0

Parameters
  • inst: instance number

Clocks

group devicetree-clocks

Defines

DT_CLOCKS_LABEL_BY_IDX(node_id, idx)

Get clock controller “name” (label property) at an index.

It’s an error if the clock controller referenced by the phandle in property “clocks” at index “idx” has no label property.

Example devicetree fragment:

clk1: clkctrl@... {
        label = "CLK_1";
};

clk2: clkctrl@... {
        label = "CLK_2";
};

n: node {
        clocks = <&clk1 10 20>, <&clk2 30 40>;
};

Example usage:

DT_CLOCKS_LABEL_BY_IDX(DT_NODELABEL(n), 1) // "CLK_2"

Return

the label property for the referenced node at index idx

See

DT_PROP_BY_PHANDLE_IDX()

Parameters
  • node_id: node identifier

  • idx: logical index into the property

DT_CLOCKS_LABEL(node_id)

Equivalent to DT_CLOCKS_LABEL_BY_IDX(node_id, 0)

Return

the label property for the named specifier at index 0

See

DT_CLOCKS_LABEL_BY_IDX()

Parameters
  • node_id: node identifier

DT_CLOCKS_CELL_BY_IDX(node_id, cell, idx)

Get Clock controller “cell” value at an index.

Example devicetree fragment:

clk1: clkctrl@... {
        label = "CLK_1";
        #clock-cells = < 2 >;
};

n: node {
        clocks = < &clk1 10 20 >, < &clk1 30 40 >;
};

Bindings fragment for the gpio0 node:

clock-cells:
  - bus
  - bits

Example usage:

DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(n), bus, 0) // 10
DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(n), bits, 1) // 40

Return

the value of the cell inside the specifier at index “idx”

See

DT_PHA_PHANDLE_IDX()

Parameters
  • node_id: node identifier

  • cell: binding’s cell name within the specifier at index “idx”

  • idx: logical index into the property

DT_CLOCKS_CELL(node_id, cell)

Equivalent to DT_CLOCKS_CELL_BY_IDX(node_id, cell, 0)

Return

the value of the cell inside the specifier at index 0

See

DT_CLOCKS_CELL_BY_IDX()

Parameters
  • node_id: node identifier

  • cell: binding’s cell name within the specifier at index 0

DT_INST_CLOCKS_LABEL_BY_IDX(inst, idx)

Get a DT_DRV_COMPAT clock controller “name” at an index (see DT_CLOCKS_LABEL_BY_IDX)

Return

the label property for the named specifier at index idx

Parameters
  • inst: instance number

  • idx: logical index into the property

DT_INST_CLOCKS_LABEL(inst)

Get a DT_DRV_COMPAT clock controller “name” (see DT_CLOCKS_LABEL_BY_IDX)

Return

the label property for the named specifier at index 0

Parameters
  • inst: instance number

DT_INST_CLOCKS_CELL_BY_IDX(inst, cell, idx)

Get a DT_DRV_COMPAT clock controller “cell” value at an index.

Return

the value of the cell inside the specifier at index “idx”

Parameters
  • inst: instance number

  • cell: binding’s cell name within the specifier at index “idx”

  • idx: logical index into the property

DT_INST_CLOCKS_CELL(inst, cell)

Get a DT_DRV_COMPAT clock controller “cell” value at an index 0.

Return

the value of the cell inside the specifier at index 0

Parameters
  • inst: instance number

  • cell: binding’s cell name within the specifier at index 0

GPIO

group devicetree-gpio

Defines

DT_GPIO_LABEL_BY_IDX(node_id, gpio_pha, idx)

Get gpio controller “name” (label property) at an index.

It’s an error if the GPIO controller referenced by the phandle in property “gpio_pha” at index “idx” has no label property.

Example devicetree fragment:

gpio1: gpio@... {
        label = "GPIO_1";
};

gpio2: gpio@... {
        label = "GPIO_2";
};

n: node {
        gpios = <&gpio1 10 20>, <&gpio2 30 40>;
};

Example usage:

DT_GPIO_LABEL_BY_IDX(DT_NODELABEL(n), gpios, 1) // "GPIO_2"

Return

the label property for the referenced node at index idx

See

DT_PHANDLE_BY_IDX()

Parameters
  • node_id: node identifier

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

  • idx: logical index into the property

DT_GPIO_LABEL(node_id, gpio_pha)

Equivalent to DT_GPIO_LABEL_BY_IDX(node_id, gpio_pha, 0)

Return

the label property for the named specifier at index 0

See

DT_GPIO_LABEL_BY_IDX()

Parameters
  • node_id: node identifier

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, idx)

Get gpio controller ‘pin’ at an index.

This macro only works for GPIO controllers that specify a ‘pin’ field in the phandle-array specifier. Refer to the specific GPIO controller binding if needed.

Return

the pin value for the named specifier at index idx

See

DT_PHA_BY_IDX()

See

DT_PHA()

Parameters
  • node_id: node identifier

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

  • idx: logical index into the property

DT_GPIO_PIN(node_id, gpio_pha)

Equivalent to DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, 0)

Return

the pin value for the named specifier at index idx

See

DT_GPIO_PIN_BY_IDX()

Parameters
  • node_id: node identifier

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, idx)

Get gpio controller ‘flags’ at an index.

This macro only works for GPIO controllers that specify a ‘flags’ field in the phandle-array specifier. Refer to the specific GPIO controller binding if needed.

Return

the flags value for the named specifier at index idx

See

DT_PHA_BY_IDX()

See

DT_PHA()

Parameters
  • node_id: node identifier

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

  • idx: logical index into the property

DT_GPIO_FLAGS(node_id, gpio_pha)

Equivalent to DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, 0)

Return

the flags value for the named specifier at index idx

See

DT_GPIO_FLAGS_BY_IDX()

Parameters
  • node_id: node identifier

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

DT_INST_GPIO_LABEL_BY_IDX(inst, gpio_pha, idx)

Get gpio controller “name” at an index (see DT_GPIO_LABEL_BY_IDX)

Return

the label property for the named specifier at index idx

Parameters
  • inst: instance number

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

  • idx: logical index into the property

DT_INST_GPIO_LABEL(inst, gpio_pha)

Equivalent to DT_INST_GPIO_LABEL_BY_IDX(inst, gpio_pha, 0)

Return

the label property for the named specifier at index 0

Parameters
  • inst: instance number

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

DT_INST_GPIO_PIN_BY_IDX(inst, gpio_pha, idx)

Get gpio controller “pin” at an index (see DT_GPIO_PIN_BY_IDX)

Return

the pin value for the named specifier at index idx

Parameters
  • inst: instance number

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

  • idx: logical index into the property

DT_INST_GPIO_PIN(inst, gpio_pha)

Equivalent to DT_INST_GPIO_PIN_BY_IDX(inst, gpio_pha, 0)

Return

the pin value for the named specifier at index 0

See

DT_INST_GPIO_PIN_BY_IDX()

Parameters
  • inst: instance number

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

DT_INST_GPIO_FLAGS_BY_IDX(inst, gpio_pha, idx)

Get a devicetree property value (see DT_GPIO_FLAGS_BY_IDX)

Return

a representation of the property’s value

Parameters
  • inst: instance number

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

  • idx: logical index into the property

DT_INST_GPIO_FLAGS(inst, gpio_pha)

Equivalent to DT_INST_GPIO_FLAGS_BY_IDX(inst, gpio_pha, 0)

Return

the flags value for the named specifier at index 0

See

DT_INST_GPIO_FLAGS_BY_IDX()

Parameters
  • inst: instance number

  • gpio_pha: lowercase-and-underscores GPIO property with type “phandle-array”

SPI

group devicetree-spi

Defines

DT_SPI_HAS_CS_GPIOS(spi)

Does a SPI controller have chip select GPIOs configured? The commonly used “cs-gpios” property is used for this test.

Return

1 if it has a cs-gpios property, 0 otherwise

Parameters
  • spi: node identifier for a SPI bus controller

DT_SPI_NUM_CS_GPIOS(spi)

The number of chip select GPIOs in a SPI controller.

Return

The length of its cs-gpios, or 0 if it doesn’t have one

Parameters
  • spi: node identifier for a SPI bus controller

DT_SPI_DEV_HAS_CS_GPIOS(spi_dev)

Does a SPI device have a chip select line in DT?

Return

1 if the SPI device’s bus DT_BUS(spi_dev) has a CS pin at index DT_REG_ADDR(spi_dev), 0 otherwise

Parameters
  • spi_dev: node identifier for a SPI device

DT_SPI_DEV_CS_GPIOS_LABEL(spi_dev)

Get GPIO controller name for a SPI device’s chip select DT_SPI_DEV_HAS_CS_GPIOS(spi_dev) must expand to 1.

spi_dev a SPI device node identifier

Return

label property of spi_dev’s chip select GPIO controller

DT_SPI_DEV_CS_GPIOS_PIN(spi_dev)

Get GPIO specifier ‘pin’ value for a SPI device’s chip select It’s an error if the GPIO specifier for spi_dev’s entry in its bus node’s cs-gpios property has no ‘pin’ value.

spi_dev a SPI device node identifier

Return

pin number of spi_dev’s chip select GPIO

DT_SPI_DEV_CS_GPIOS_FLAGS(spi_dev)

Get GPIO specifier ‘flags’ value for a SPI device’s chip select It’s an error if the GPIO specifier for spi_dev’s entry in its bus node’s cs-gpios property has no ‘flags’ value.

spi_dev a SPI device node identifier

Return

flags value of spi_dev’s chip select GPIO specifier

DT_INST_SPI_DEV_HAS_CS_GPIOS(inst)

Equivalent to DT_SPI_DEV_HAS_CS_GPIOS(DT_DRV_INST(inst))

Return

1 if the instance’s bus has a CS pin at index DT_INST_REG_ADDR(inst), 0 otherwise

Parameters
  • inst: instance number

DT_INST_SPI_DEV_CS_GPIOS_LABEL(inst)

Get GPIO controller name for a SPI device instance This is equivalent to DT_SPI_DEV_CS_GPIOS_LABEL(DT_DRV_INST(inst)).

inst instance number

Return

label property of the instance’s chip select GPIO controller

DT_INST_SPI_DEV_CS_GPIOS_PIN(inst)

Get GPIO specifier “pin” value for a SPI device instance This is equivalent to DT_SPI_DEV_CS_GPIOS_PIN(DT_DRV_INST(inst)).

inst a SPI device instance number

Return

pin number of the instance’s chip select GPIO

DT_INST_SPI_DEV_CS_GPIOS_FLAGS(inst)

Get GPIO specifier “flags” value for a SPI device instance This is equivalent to DT_SPI_DEV_CS_GPIOS_FLAGS(DT_DRV_INST(inst)).

inst a SPI device instance number

Return

flags value of the instance’s chip select GPIO specifier