Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensors: Sensor channel DT child nodes #65830

Closed
wants to merge 2 commits into from

Conversation

teburd
Copy link
Collaborator

@teburd teburd commented Nov 27, 2023

A rough, WIP, idea of maybe describing sensor channels as child nodes of a sensor. Original idea was from @MaureenHelm

Some nice attributes of this... it maybe better matches up with what the sensor subsystem needs (a channel rather than sensor in terminology). It enables possibly adding optional channels of information for devices that represent sensor hubs like bosch's bhi260ap which has many potential channels of information.

A single numerical value could represent a channel, and the information about that channel could be obtained perhaps using DT macros statically without any allocation or C calls involved

Related Issues/PRs
#64478
#63830
#61163

@teburd teburd force-pushed the sensor_channel_revisit branch 2 times, most recently from eccd8f6 to 78a52c9 Compare November 27, 2023 20:47
Adds a devicetree binding for the idea of a sensor channel. Every sensor
channel has an index, type, and fields with meaning.

This provides the ability to have channels that represent
multi-dimensional physical measurements of the same type grouping them
together. Dimensionless fields are also entirely possible as are arrays
of fields for things like ToF 1 and 2d arrays.

Following this change every sensor is expected to describe the channels
it provides (including perhaps opt in ones for things like sensor hubs).

A channel could be extended to provide default configuration options for
data rate, sensitivity, and other such attributes typically associated
with a sensor channel.

Signed-off-by: Tom Burdick <[email protected]>
Each sensor would be expected to describe some common attributes in an
include file like this and be included in the board/soc dts where the
sensor is used.

In this way common sensor channels and descriptions would be available.

Signed-off-by: Tom Burdick <[email protected]>
@teburd
Copy link
Collaborator Author

teburd commented Nov 28, 2023

So unfortunately, atleast today, there's no great way of patching up a tree given a compatible, or supplying a "default" subtree for a given compatible which would be really useful for this sort of thing but at least this builds and can sort of give some clues as to what I was thinking

I wouldn't release this requiring #include <some_sensor.dtsi> in the node as that's a bit awkward. Instead ideally the node would have some default child nodes created through the binding perhaps (would make sense to me anyways).

From here all the APIs would then reference a channel index rather than a channel type. The channel index for a given type could be obtained through some DT macros or sensor APIs perhaps? Or we could stick with the copy friendly chan spec as the unique identifier (so the pair of type, index) as #63830 noted.

It's a very rough idea, but at least its a place to tinker around perhaps. Each channel could specify an array of available ODR (associating a value for the register perhaps), available power modes, available filter modes, available sensitivities, and so on.

@avisconti was doing that at a sensor level which is cool as well for st sensors

Copy link
Collaborator

@yperess yperess left a comment

Choose a reason for hiding this comment

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

I'm personally not a big fan of the subtree approach (specifically because we can't set a default). I don't envision that we'll need much data here and I think that having something like the following would be enough:

bmi160 {
  compatible = "bosch,bmi160";
  channels = <SENSOR_CHAN_ACCEL_XYZ, SENSOR_CHAN_GYRO_XYZ, SENSOR_CHAN_DIE_TEMP>;
  attributes = <
                SENSOR_CHAN_ALL       SENSOR_ATTR_BATCH_DURATION
                SENSOR_CHAN_ACCEL_XYZ SENSOR_ATTR_SAMPLING_FREQUENCY
                SENSOR_CHAN_ACCEL_XYZ SENSOR_ATTR_OFFSET
                ...
                >;
};

@teburd
Copy link
Collaborator Author

teburd commented Nov 28, 2023

I'm personally not a big fan of the subtree approach (specifically because we can't set a default). I don't envision that we'll need much data here and I think that having something like the following would be enough:

bmi160 {
  compatible = "bosch,bmi160";
  channels = <SENSOR_CHAN_ACCEL_XYZ, SENSOR_CHAN_GYRO_XYZ, SENSOR_CHAN_DIE_TEMP>;
  attributes = <
                SENSOR_CHAN_ALL       SENSOR_ATTR_BATCH_DURATION
                SENSOR_CHAN_ACCEL_XYZ SENSOR_ATTR_SAMPLING_FREQUENCY
                SENSOR_CHAN_ACCEL_XYZ SENSOR_ATTR_OFFSET
                ...
                >;
};

How would you describe multiple channels of the same type in this scenario? This was the initial issue noted in some other PRs.

In case of multiple simple temperature channels this could be pretty easily done with child nodes.

There's also some potential benefit here in being able to configure and enable optional channels, e.g. some devices may act as sensor hubs with externally connected devices, or optional channels.

bhi260ap is the extreme end of this. Imagine a DT for this device with all the channels that you can then enable/disable/configure like SoC peripherals. That would be pretty nice.

I'm not opposed to using properties, this is a rough idea coming from Maureen initially and I think it warranted exploring. I like some attributes of this route.

But really I feel like its DT that's limiting the options here as I'd like to have an array of structured data by default for this just like an SoC sort of has a default tree for a board.

To do it in DT with defaults the way we do things today I'd need to set it up as a destructured set of arrays.. which has some other limitations, like we can't describe all the channels then set their status and configure them individually which for the most part otherwise would be fine to do.

bmi160 {
  compatible = "bosch,bmi160";
  /* position in the array here implies the channels index */
  channels = <SENSOR_CHANNEL_ACCEL, SENSOR_CHANNEL_GYRO, SENSOR_CHANNEL_TEMP>;
  channel-fields = <<SENSOR_FIELD_X, SENSOR_FIELD_Y, SENSOR_FIELD_Z>,
                    <SENSOR_FIELD_X, SENSOR_FIELD_Y, SENSOR_FIELD_Z>,
                    <SENSOR_FIELD_DIE>>;
};

I'd note that the way the ST sensors now work with enum ODR/filter/sensitivity options is quite nice but doesn't match up with attributes very well as you have them. That's something to look at harder seemingly.

@teburd
Copy link
Collaborator Author

teburd commented Dec 11, 2023

Sensor WG: No one likes the include
Brix: Take a look at pinctl as a possible answer (index properties)
Yuval: Wants to use these in class templates, as long as an array of channels is accessible.
Brix: ADC controller binding uses child nodes for channel bindings

@lixuzha
Copy link
Collaborator

lixuzha commented Jan 15, 2024

If there are multiple sensors of the same type in a chip, the sensing subsystem cannot use the existing sensor API to handle this situation. This pull request introduces channel index, which is a way to solve this problem. For me, this is a good start.

Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Mar 16, 2024
@github-actions github-actions bot closed this Mar 31, 2024
@teburd teburd mentioned this pull request Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants