|
1302 | 1302 | #define DT_BUS_LABEL(node_id) DT_PROP(DT_BUS(node_id), label)
|
1303 | 1303 |
|
1304 | 1304 | /**
|
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 |
1306 | 1306 | *
|
1307 | 1307 | * Example devicetree overlay:
|
1308 | 1308 | *
|
|
1320 | 1320 | * DT_ON_BUS(DT_NODELABEL(temp), spi) // 0
|
1321 | 1321 | *
|
1322 | 1322 | * @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 |
1325 | 1324 | * @return 1 if the node is on a bus of the given type,
|
1326 | 1325 | * 0 otherwise
|
1327 | 1326 | */
|
|
1346 | 1345 | #define DT_DRV_INST(inst) DT_INST(inst, DT_DRV_COMPAT)
|
1347 | 1346 |
|
1348 | 1347 | /**
|
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. |
1353 | 1349 | *
|
1354 | 1350 | * @param inst instance number
|
1355 |
| - * @param fn macro to invoke on each child node identifier |
| 1351 | + * @param fn macro to invoke |
1356 | 1352 | *
|
1357 | 1353 | * @see DT_FOREACH_CHILD
|
1358 | 1354 | */
|
|
1541 | 1537 |
|
1542 | 1538 | /**
|
1543 | 1539 | * @brief Get a DT_DRV_COMPAT's (only) register block address
|
| 1540 | + * Equivalent to DT_INST_REG_ADDR_BY_IDX(inst, 0). |
1544 | 1541 | * @param inst instance number
|
1545 | 1542 | * @return instance's register block address
|
1546 | 1543 | */
|
1547 | 1544 | #define DT_INST_REG_ADDR(inst) DT_INST_REG_ADDR_BY_IDX(inst, 0)
|
1548 | 1545 |
|
1549 | 1546 | /**
|
1550 | 1547 | * @brief Get a DT_DRV_COMPAT's (only) register block size
|
| 1548 | + * Equivalent to DT_INST_REG_SIZE_BY_IDX(inst, 0). |
1551 | 1549 | * @param inst instance number
|
1552 | 1550 | * @return instance's register block size
|
1553 | 1551 | */
|
1554 | 1552 | #define DT_INST_REG_SIZE(inst) DT_INST_REG_SIZE_BY_IDX(inst, 0)
|
1555 | 1553 |
|
1556 | 1554 | /**
|
1557 | 1555 | * @brief Get a DT_DRV_COMPAT interrupt specifier value at an index
|
| 1556 | + * (see @ref DT_IRQ_BY_IDX) |
1558 | 1557 | * @param inst instance number
|
1559 | 1558 | * @param idx logical index into the interrupt specifier array
|
1560 | 1559 | * @param cell cell name specifier
|
|
1565 | 1564 |
|
1566 | 1565 | /**
|
1567 | 1566 | * @brief Get a DT_DRV_COMPAT interrupt specifier value by name
|
| 1567 | + * (see @ref DT_IRQ_BY_NAME) |
1568 | 1568 | * @param inst instance number
|
1569 | 1569 | * @param name lowercase-and-underscores interrupt specifier name
|
1570 | 1570 | * @param cell cell name specifier
|
|
1574 | 1574 | DT_IRQ_BY_NAME(DT_DRV_INST(inst), name, cell)
|
1575 | 1575 |
|
1576 | 1576 | /**
|
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). |
1578 | 1579 | * @param inst instance number
|
1579 | 1580 | * @param cell cell name specifier
|
1580 | 1581 | * @return the named value at that index
|
|
1583 | 1584 |
|
1584 | 1585 | /**
|
1585 | 1586 | * @brief Get a DT_DRV_COMPAT's (only) irq number
|
| 1587 | + * Equivalent to DT_INST_IRQ(inst, irq). |
1586 | 1588 | * @param inst instance number
|
1587 | 1589 | * @return the interrupt number for the node's only interrupt
|
1588 | 1590 | */
|
1589 | 1591 | #define DT_INST_IRQN(inst) DT_INST_IRQ(inst, irq)
|
1590 | 1592 |
|
1591 | 1593 | /**
|
1592 | 1594 | * @brief Get a DT_DRV_COMPAT's bus node's label property
|
| 1595 | + * Equivalent to DT_BUS_LABEL(DT_DRV_INST(inst)) |
1593 | 1596 | * @param inst instance number
|
1594 | 1597 | * @return the label property of the instance's bus controller
|
1595 | 1598 | */
|
1596 | 1599 | #define DT_INST_BUS_LABEL(inst) DT_BUS_LABEL(DT_DRV_INST(inst))
|
1597 | 1600 |
|
1598 | 1601 | /**
|
1599 | 1602 | * @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). |
1600 | 1604 | * @param inst instance number
|
1601 | 1605 | * @param bus a binding's bus type as a C token, lowercased and without quotes
|
1602 | 1606 | * @return 1 if the given instance is on a bus of the given type,
|
|
1608 | 1612 | * @brief Test if any DT_DRV_COMPAT node is on a bus of a given type
|
1609 | 1613 | * and has status okay
|
1610 | 1614 | *
|
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 |
| - * |
1615 | 1615 | * Example devicetree overlay:
|
1616 | 1616 | *
|
1617 | 1617 | * &i2c0 {
|
|
1636 | 1636 | DT_COMPAT_ON_BUS_INTERNAL(DT_DRV_COMPAT, bus)
|
1637 | 1637 |
|
1638 | 1638 | /**
|
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 |
1673 | 1640 | *
|
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" |
1683 | 1643 | *
|
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. |
1686 | 1646 | *
|
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". |
1689 | 1649 | *
|
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. |
1693 | 1652 | *
|
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. |
1696 | 1655 | */
|
1697 |
| -#define DT_INST_FOREACH_STATUS_OKAY(fn) \ |
| 1656 | +#define DT_INST_FOREACH_STATUS_OKAY(inst_expr) \ |
1698 | 1657 | COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \
|
1699 | 1658 | (UTIL_CAT(DT_FOREACH_OKAY_INST_, \
|
1700 |
| - DT_DRV_COMPAT)(fn)), \ |
| 1659 | + DT_DRV_COMPAT)(inst_expr)), \ |
1701 | 1660 | ())
|
1702 | 1661 |
|
1703 | 1662 | /**
|
1704 | 1663 | * @brief Does a DT_DRV_COMPAT instance have a property?
|
| 1664 | + * Equivalent to DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop) |
1705 | 1665 | * @param inst instance number
|
1706 | 1666 | * @param prop lowercase-and-underscores property name
|
1707 | 1667 | * @return 1 if the instance has the property, 0 otherwise.
|
|
1710 | 1670 | DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop)
|
1711 | 1671 |
|
1712 | 1672 | /**
|
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 |
1715 | 1675 | * @param inst instance number
|
1716 | 1676 | * @param pha lowercase-and-underscores property with type "phandle-array"
|
1717 | 1677 | * @param idx index to check
|
|
1736 | 1696 |
|
1737 | 1697 | /**
|
1738 | 1698 | * @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). |
1739 | 1700 | * @param inst instance number
|
1740 | 1701 | * @param idx logical index into the interrupt specifier array
|
1741 | 1702 | * @return 1 if the idx is valid for the interrupt property
|
|
1745 | 1706 |
|
1746 | 1707 | /**
|
1747 | 1708 | * @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). |
1748 | 1710 | * @param inst instance number
|
1749 | 1711 | * @param idx index to check
|
1750 | 1712 | * @param cell named cell value whose existence to check
|
|
1756 | 1718 |
|
1757 | 1719 | /**
|
1758 | 1720 | * @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). |
1759 | 1722 | * @param inst instance number
|
1760 | 1723 | * @param cell named cell value whose existence to check
|
1761 | 1724 | * @return 1 if the named cell exists in the interrupt specifier at index 0
|
|
1766 | 1729 |
|
1767 | 1730 | /**
|
1768 | 1731 | * @brief Does a DT_DRV_COMPAT instance have an interrupt value?
|
| 1732 | + * Equivalent to DT_INST_IRQ_HAS_NAME(DT_DRV_INST(inst), name). |
1769 | 1733 | * @param inst instance number
|
1770 | 1734 | * @param name lowercase-and-underscores interrupt specifier name
|
1771 | 1735 | * @return 1 if "name" is a valid named specifier
|
|
0 commit comments