Skip to content

Conversation

@pdgendt
Copy link
Contributor

@pdgendt pdgendt commented Nov 8, 2025

Allow fetching child node identifiers by unit address.

It also modifies the ADC_DT_SPEC_STRUCT macro to not use FOREACH macro expansion, which doesn't play nice with COND_CODE_X and other macro loops.

@zephyrbot zephyrbot added area: Devicetree area: Devicetree Bindings area: Boards/SoCs area: Tests Issues related to a particular existing or missing test labels Nov 8, 2025
@pdgendt pdgendt requested a review from teburd November 8, 2025 10:54
@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch from 9bf2b99 to e3c70ba Compare November 8, 2025 11:03
@zephyrbot zephyrbot added the area: ADC Analog-to-Digital Converter (ADC) label Nov 8, 2025
@zephyrbot zephyrbot requested a review from anangl November 8, 2025 11:14
@pdgendt pdgendt added this to the v4.4.0 milestone Nov 8, 2025
@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch from e51dfee to 5eac67f Compare November 8, 2025 11:26
Fix dts formatting issues with dts-linter.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch 3 times, most recently from fa20529 to 2c51d4f Compare November 12, 2025 08:52
@zephyrbot zephyrbot added the Release Notes To be mentioned in the release notes label Nov 12, 2025
@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch from aaddcc3 to 6d71377 Compare November 12, 2025 09:38
rruuaanng
rruuaanng previously approved these changes Nov 12, 2025
Comment on lines 439 to 453
* @brief Get a node identifier for a child node by a reg address
*
* Example devicetree fragment:
*
* @code{.dts}
* / {
* soc-label: soc {
* serial1: serial@40001000 {
* status = "okay";
* current-speed = <115200>;
* ...
* };
* };
* };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the description you say it's by reg address, but I don't see a reg property here in the example, unless you mean to refer to the unit address, in which case the name of the macro is also wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a proper _BY_UNIT_ADDR variant, which is needed to fix the adc dt spec. I could drop the _BY_REG_ADDR, but it doesn't harm I guess?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it makes sense either given #99120 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR

*
* @return node identifier for the child node with the reg address at a specified index
*/
#define DT_CHILD_BY_REG_ADDR(node_id, idx, addr) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are going to do this, then i suggest you make a _BY_IDX version , and make this one do index 0. and also could be useful to add a _BY_NAME version.

Copy link
Member

@henrikbrixandersen henrikbrixandersen Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that resources can be shared between multiple nodes (reg property addresses do not need to be unique across nodes).

@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch from 6d71377 to 21c217a Compare November 12, 2025 18:02
@henrikbrixandersen
Copy link
Member

Allow fetching child node identifiers by reg address.

Can you elaborate a bit on the use case, please?

@pdgendt
Copy link
Contributor Author

pdgendt commented Nov 12, 2025

Allow fetching child node identifiers by reg address.

Can you elaborate a bit on the use case, please?

I've added a commit that replaces the struct adc_dt_spec instantiation macro, that used to have a special FOREACH..IS_EQ check. This check doesn't work for cases where drivers need to instantiate it as part of a DT_FOREACH_COMPAT macro (double FOREACH macro).

@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch from f7ba568 to 3c5f497 Compare November 12, 2025 19:25
@pdgendt pdgendt changed the title devicetree: Add DT_CHILD_BY_REG_ADDR devicetree: Add DT_CHILD_BY_UNIT_ADDR Nov 12, 2025
@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch 2 times, most recently from bc74e56 to 04106bf Compare November 13, 2025 08:21
Copy link
Contributor

@mathieuchopstm mathieuchopstm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise

@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch from 04106bf to 3d2eaf9 Compare November 13, 2025 09:42
@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch from 3d2eaf9 to 19ab0dd Compare November 13, 2025 10:00
Allow fetching child node identifiers by unit address.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Introduce test cases to the devicetree API test suite for
DT_CHILD_BY_UNIT_ADDR and DT_INST_CHILD_BY_UNIT_ADDR.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
The macro to initialise a struct adc_dt_spec instance uses a FOREACH macro,
which can be problematic when nesting in other FOREACH macros, for example
in driver implementations.

Replace it with DT_CHILD_BY_UNIT_ADDR.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Add a DeviceTree section and entries for the new C macros.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
@pdgendt pdgendt force-pushed the dt-child-by-reg-addr branch from 19ab0dd to dd22799 Compare November 13, 2025 16:29
@sonarqubecloud
Copy link

@pdgendt pdgendt requested a review from decsny November 14, 2025 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ADC Analog-to-Digital Converter (ADC) area: Boards/SoCs area: Devicetree Bindings area: Devicetree area: Tests Issues related to a particular existing or missing test Release Notes To be mentioned in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants