Skip to content

Commit 668d034

Browse files
Revert "[nrf fromtree] doc: dts: simplify DT_INST documentation"
This reverts commit 9a38d5e. Signed-off-by: Martí Bolívar <[email protected]>
1 parent 6693323 commit 668d034

File tree

2 files changed

+36
-107
lines changed

2 files changed

+36
-107
lines changed

doc/reference/devicetree/index.rst

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -126,46 +126,11 @@ Instance-based APIs
126126

127127
These are recommended for use within device drivers. To use them, define
128128
``DT_DRV_COMPAT`` to the lowercase-and-underscores compatible the device driver
129-
implements support for. Here is an example devicetree fragment:
130-
131-
.. code-block:: DTS
132-
133-
serial@40001000 {
134-
compatible = "vnd,serial";
135-
status = "okay";
136-
current-speed = <115200>;
137-
};
138-
139-
Example usage, assuming serial@40001000 is the only enabled node
140-
with compatible "vnd,serial":
141-
142-
.. code-block:: c
143-
144-
#define DT_DRV_COMPAT vnd_serial
145-
DT_DRV_INST(0) // node identifier for serial@40001000
146-
DT_INST_PROP(0, current_speed) // 115200
147-
148-
.. warning::
149-
150-
Be careful making assumptions about instance numbers. See :c:func:`DT_INST`
151-
for the API guarantees.
152-
153-
As shown above, the ``DT_INST_*`` APIs are conveniences for addressing nodes by
154-
instance number. They are almost all defined in terms of one of the
155-
:ref:`devicetree-generic-apis`. The equivalent generic API can be found by
156-
removing ``INST_`` from the macro name. For example, ``DT_INST_PROP(inst,
157-
prop)`` is equivalent to ``DT_PROP(DT_DRV_INST(inst), prop)``. Similarly,
158-
``DT_INST_REG_ADDR(inst)`` is equivalent to ``DT_REG_ADDR(DT_DRV_INST(inst))``,
159-
and so on. There are some exceptions: :c:func:`DT_ANY_INST_ON_BUS_STATUS_OKAY`
160-
and :c:func:`DT_INST_FOREACH_STATUS_OKAY` are special-purpose helpers without
161-
straightforward generic equivalents.
162-
163-
Since ``DT_DRV_INST()`` requires ``DT_DRV_COMPAT`` to be defined, it's an error
164-
to use any of these without that macro defined.
165-
166-
Note that there are also helpers available for
129+
implements support for. Note that there are also helpers available for
167130
specific hardware; these are documented in :ref:`devicetree-hw-api`.
168131

132+
It is an error to use these macros without ``DT_DRV_COMPAT`` defined.
133+
169134
.. doxygengroup:: devicetree-inst
170135
:project: Zephyr
171136

include/devicetree.h

Lines changed: 33 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@
13021302
#define DT_BUS_LABEL(node_id) DT_PROP(DT_BUS(node_id), label)
13031303

13041304
/**
1305-
* @brief Is a node on a bus of a given type?
1305+
* @brief Test if a node's bus type is a given type
13061306
*
13071307
* Example devicetree overlay:
13081308
*
@@ -1320,8 +1320,7 @@
13201320
* DT_ON_BUS(DT_NODELABEL(temp), spi) // 0
13211321
*
13221322
* @param node_id node identifier
1323-
* @param bus lowercase-and-underscores bus type as a C token (i.e.
1324-
* without quotes)
1323+
* @param bus a binding's bus type as a C token, lowercased and without quotes
13251324
* @return 1 if the node is on a bus of the given type,
13261325
* 0 otherwise
13271326
*/
@@ -1346,13 +1345,10 @@
13461345
#define DT_DRV_INST(inst) DT_INST(inst, DT_DRV_COMPAT)
13471346

13481347
/**
1349-
* @brief Call "fn" on all child nodes of DT_DRV_INST(inst).
1350-
*
1351-
* The macro "fn" should take one argument, which is the node
1352-
* identifier for the child node.
1348+
* @brief Invokes given macro for all child nodes of DT_DRV_COMPAT instance.
13531349
*
13541350
* @param inst instance number
1355-
* @param fn macro to invoke on each child node identifier
1351+
* @param fn macro to invoke
13561352
*
13571353
* @see DT_FOREACH_CHILD
13581354
*/
@@ -1541,20 +1537,23 @@
15411537

15421538
/**
15431539
* @brief Get a DT_DRV_COMPAT's (only) register block address
1540+
* Equivalent to DT_INST_REG_ADDR_BY_IDX(inst, 0).
15441541
* @param inst instance number
15451542
* @return instance's register block address
15461543
*/
15471544
#define DT_INST_REG_ADDR(inst) DT_INST_REG_ADDR_BY_IDX(inst, 0)
15481545

15491546
/**
15501547
* @brief Get a DT_DRV_COMPAT's (only) register block size
1548+
* Equivalent to DT_INST_REG_SIZE_BY_IDX(inst, 0).
15511549
* @param inst instance number
15521550
* @return instance's register block size
15531551
*/
15541552
#define DT_INST_REG_SIZE(inst) DT_INST_REG_SIZE_BY_IDX(inst, 0)
15551553

15561554
/**
15571555
* @brief Get a DT_DRV_COMPAT interrupt specifier value at an index
1556+
* (see @ref DT_IRQ_BY_IDX)
15581557
* @param inst instance number
15591558
* @param idx logical index into the interrupt specifier array
15601559
* @param cell cell name specifier
@@ -1565,6 +1564,7 @@
15651564

15661565
/**
15671566
* @brief Get a DT_DRV_COMPAT interrupt specifier value by name
1567+
* (see @ref DT_IRQ_BY_NAME)
15681568
* @param inst instance number
15691569
* @param name lowercase-and-underscores interrupt specifier name
15701570
* @param cell cell name specifier
@@ -1574,7 +1574,8 @@
15741574
DT_IRQ_BY_NAME(DT_DRV_INST(inst), name, cell)
15751575

15761576
/**
1577-
* @brief Get a DT_DRV_COMPAT interrupt specifier's value
1577+
* @brief Get a DT_DRV_COMAPT interrupt specifier's value
1578+
* Equivalent to DT_INST_IRQ_BY_IDX(inst, 0, cell).
15781579
* @param inst instance number
15791580
* @param cell cell name specifier
15801581
* @return the named value at that index
@@ -1583,20 +1584,23 @@
15831584

15841585
/**
15851586
* @brief Get a DT_DRV_COMPAT's (only) irq number
1587+
* Equivalent to DT_INST_IRQ(inst, irq).
15861588
* @param inst instance number
15871589
* @return the interrupt number for the node's only interrupt
15881590
*/
15891591
#define DT_INST_IRQN(inst) DT_INST_IRQ(inst, irq)
15901592

15911593
/**
15921594
* @brief Get a DT_DRV_COMPAT's bus node's label property
1595+
* Equivalent to DT_BUS_LABEL(DT_DRV_INST(inst))
15931596
* @param inst instance number
15941597
* @return the label property of the instance's bus controller
15951598
*/
15961599
#define DT_INST_BUS_LABEL(inst) DT_BUS_LABEL(DT_DRV_INST(inst))
15971600

15981601
/**
15991602
* @brief Test if a DT_DRV_COMPAT's bus type is a given type
1603+
* This is equivalent to DT_ON_BUS(DT_DRV_INST(inst), bus).
16001604
* @param inst instance number
16011605
* @param bus a binding's bus type as a C token, lowercased and without quotes
16021606
* @return 1 if the given instance is on a bus of the given type,
@@ -1608,10 +1612,6 @@
16081612
* @brief Test if any DT_DRV_COMPAT node is on a bus of a given type
16091613
* and has status okay
16101614
*
1611-
* This is a special-purpose macro which can be useful when writing
1612-
* drivers for devices which can appear on multiple buses. One example
1613-
* is a sensor device which may be wired on an I2C or SPI bus.
1614-
*
16151615
* Example devicetree overlay:
16161616
*
16171617
* &i2c0 {
@@ -1636,72 +1636,32 @@
16361636
DT_COMPAT_ON_BUS_INTERNAL(DT_DRV_COMPAT, bus)
16371637

16381638
/**
1639-
* @brief Call "fn" on all nodes with compatible DT_DRV_COMPAT
1640-
* and status "okay"
1641-
*
1642-
* This macro calls "fn(inst)" on each "inst" number that refers to a
1643-
* node with status "okay". Whitespace is added between invocations.
1644-
*
1645-
* Example devicetree fragment:
1646-
*
1647-
* a {
1648-
* compatible = "vnd,device";
1649-
* status = "okay";
1650-
* label = "DEV_A";
1651-
* };
1652-
*
1653-
* b {
1654-
* compatible = "vnd,device";
1655-
* status = "okay";
1656-
* label = "DEV_B";
1657-
* };
1658-
*
1659-
* c {
1660-
* compatible = "vnd,device";
1661-
* status = "disabled";
1662-
* label = "DEV_C";
1663-
* };
1664-
*
1665-
* Example usage:
1666-
*
1667-
* #define DT_DRV_COMPAT vnd_device
1668-
* #define MY_FN(inst) DT_INST_LABEL(inst),
1669-
*
1670-
* DT_INST_FOREACH_STATUS_OKAY(MY_FN)
1671-
*
1672-
* This expands to:
1639+
* @def DT_INST_FOREACH_STATUS_OKAY
16731640
*
1674-
* MY_FN(0) MY_FN(1)
1675-
*
1676-
* and from there, to either this:
1677-
*
1678-
* "DEV_A", "DEV_B",
1679-
*
1680-
* or this:
1681-
*
1682-
* "DEV_B", "DEV_A",
1641+
* @brief Call specified macro for all nodes with compatible DT_DRV_COMPAT
1642+
* and status "okay"
16831643
*
1684-
* No guarantees are made about the order that a and b appear in the
1685-
* expansion.
1644+
* @details This macro will scan for all DT_INST_ device nodes for that
1645+
* compatible.
16861646
*
1687-
* Note that "fn" is responsible for adding commas, semicolons, or
1688-
* other separators or terminators.
1647+
* The macro then calls the supplied inst_expr with the instance number
1648+
* for each instance which has status "okay".
16891649
*
1690-
* Device drivers should use this macro whenever possible to
1691-
* instantiate a struct device for each enabled node in the devicetree
1692-
* of the driver's compatible DT_DRV_COMPAT.
1650+
* This macro can be used for example to call the init macro of a driver
1651+
* for each device specified in the device tree with "okay" status.
16931652
*
1694-
* @param fn Macro to call for each enabled node. Must accept an
1695-
* instance number as its only parameter.
1653+
* @param inst_expr Macro or function that is called for each device node.
1654+
* Has to accept instance_number as only parameter.
16961655
*/
1697-
#define DT_INST_FOREACH_STATUS_OKAY(fn) \
1656+
#define DT_INST_FOREACH_STATUS_OKAY(inst_expr) \
16981657
COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \
16991658
(UTIL_CAT(DT_FOREACH_OKAY_INST_, \
1700-
DT_DRV_COMPAT)(fn)), \
1659+
DT_DRV_COMPAT)(inst_expr)), \
17011660
())
17021661

17031662
/**
17041663
* @brief Does a DT_DRV_COMPAT instance have a property?
1664+
* Equivalent to DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop)
17051665
* @param inst instance number
17061666
* @param prop lowercase-and-underscores property name
17071667
* @return 1 if the instance has the property, 0 otherwise.
@@ -1710,8 +1670,8 @@
17101670
DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop)
17111671

17121672
/**
1713-
* @brief Does a phandle array have a named cell specifier at an index
1714-
* for a DT_DRV_COMPAT instance?
1673+
* @brief Does a phandle array have a named cell specifier at an index?
1674+
* for a DT_DRV_COMPAT instance
17151675
* @param inst instance number
17161676
* @param pha lowercase-and-underscores property with type "phandle-array"
17171677
* @param idx index to check
@@ -1736,6 +1696,7 @@
17361696

17371697
/**
17381698
* @brief is index valid for interrupt property on a DT_DRV_COMPAT instance?
1699+
* Equivalent to DT_IRQ_HAS_IDX(DT_DRV_INST(inst), idx).
17391700
* @param inst instance number
17401701
* @param idx logical index into the interrupt specifier array
17411702
* @return 1 if the idx is valid for the interrupt property
@@ -1745,6 +1706,7 @@
17451706

17461707
/**
17471708
* @brief Does a DT_DRV_COMPAT instance have an interrupt named cell specifier?
1709+
* Equivalent to DT_IRQ_HAS_CELL_AT_IDX(DT_DRV_INST(inst), idx, cell).
17481710
* @param inst instance number
17491711
* @param idx index to check
17501712
* @param cell named cell value whose existence to check
@@ -1756,6 +1718,7 @@
17561718

17571719
/**
17581720
* @brief Does a DT_DRV_COMPAT instance have an interrupt value?
1721+
* Equivalent to DT_INST_IRQ_HAS_IDX(DT_DRV_INST(inst), 0, cell).
17591722
* @param inst instance number
17601723
* @param cell named cell value whose existence to check
17611724
* @return 1 if the named cell exists in the interrupt specifier at index 0
@@ -1766,6 +1729,7 @@
17661729

17671730
/**
17681731
* @brief Does a DT_DRV_COMPAT instance have an interrupt value?
1732+
* Equivalent to DT_INST_IRQ_HAS_NAME(DT_DRV_INST(inst), name).
17691733
* @param inst instance number
17701734
* @param name lowercase-and-underscores interrupt specifier name
17711735
* @return 1 if "name" is a valid named specifier

0 commit comments

Comments
 (0)