Skip to content

channel parent attribute support - #1635

Draft
rodrigo455 wants to merge 9 commits into
mainfrom
staging/parent-attr
Draft

rodrigo455 wants to merge 9 commits into
mainfrom
staging/parent-attr

Conversation

@rodrigo455

@rodrigo455 rodrigo455 commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

PR Description

Linux 7.4 adds a new IIO sysfs attribute, <dir>_<type>Y_parent (e.g. out_altvoltage1_parent). It holds the sysfs name prefix of the channel's parent, such as out_altvoltage0. It lets userspace arrange channels in a tree that reflects virtual or logical relationships. A typical case is a set of profile- or mode-based subchannels that configure a single physical output channel.

This PR exposes that relationship in libiio, across all backends and bindings.

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have commented new code, particularly complex or unclear areas
  • I have checked that I did not introduce new warnings or errors (CI output)
  • I have checked that components that use libiio did not get broken
  • I have updated the documentation accordingly (GitHub Pages, READMEs, etc)

The IIO subsystem gained a <dir>_<type>[Y]_parent channel attribute,
containing the sysfs name prefix of the parent channel (e.g.
"out_altvoltage0"). It allows userspace to organize channels in a
tree-like structure, reflecting virtual or logical relationships between
them, e.g. profile-based subchannels configuring a primary output.

- Add iio_channel_get_parent(), returning the parent channel, which
  belongs to the same device, or NULL if there is none
- Add iio_channel_set_parent() to the backend API. It refuses a parent
  belonging to another device, or the channel itself.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add the optional "parent" and "parent-type" attributes to the <channel>
element, identifying the parent channel the same way channels are
identified within a <device>: by their ID and direction. When
"parent-type" is not set, the parent has the direction of the channel;
it is only generated when the directions differ.

As parents can be described after their subchannels, the XML backend
sets them once all the channels of a device have been created. Unknown
parents are ignored, with a warning.

Older clients ignore the unknown attributes.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Read the <dir>_<type>[Y]_parent attribute of the channels, like it is
done for the channel label. The attribute is not listed among the
channel attributes.

Its value, the sysfs name prefix of the parent channel, may contain a
modifier and an extended name (e.g. "in_accel_x" or
"in_voltage0_supply"). It is parsed with get_channel_id(), like the
attribute names are when creating the channels: the channel ID is made
of the type, index and modifier, while the extended name is not part of
it. get_channel_id() now also accepts a prefix without attribute name,
like it does for the hwmon attributes without underscore.

The parent is then looked up by ID and direction, once all the channels
of the device are known. Unknown parents are ignored, with a warning.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Parse the "parent" and "parent-type" attributes of the <channel>
elements, so that emulated devices can describe hierarchical channel
relationships. Like in the XML backend, the parents are set once all
the channels of a device have been created.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Print the ID of the parent channel, e.g. "(parent: altvoltage0)", with
its direction when it differs from the one of the channel.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add test_parent, using a new fixture describing channels with parents.
Test, with the XML and EMU backends:

- channels without parent, siblings and nested subchannels
- a parent described after its subchannel
- a parent with a different direction, including one with the same ID
- the default direction of the parent, when "parent-type" is not set
- unknown parents and self-references, which are ignored
- generation and parsing of the context XML, "parent-type" being only
  generated when the directions differ

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add the Channel.parent property, returning the parent channel or None.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add parent() to Channel, returning an optional parent channel.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add the Channel.parent property, returning the parent channel or null.
The instance listed in Device.channels is returned when available.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant