-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: Specify sensor channel in DT #61163
Comments
Hi @semihalf-Duleba-Kornel! We appreciate you submitting your first issue for our open-source project. 🌟 Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙 |
cc @MaureenHelm @avisconti @teburd @yperess (Sensors) @mbolivar-ampere @galak (Devicetree) @gmarull @carlescufi @keith-zephyr @semihalf-Duleba-Kornel you may want to open a draft or DNM PR for 2810e96, that way people can comment on the diff |
should we align with iio? https://github.com/devicetree-org/dt-schema/tree/main/dtschema/schemas/iio |
I'd say no myself. We don't have IIO, and IIO (I tried) turns out to be a poor fit, IMHO, for Zephyr. |
I agree with this idea overall, I did something very similar with my pitch for the sensor subsystem (https://github.com/zephyrproject-rtos/zephyr/pull/56963/files#diff-3144f3f020602f03044b01fa08365e64c890a32f059002db005450463f6ab640R12) where I added the sensor types (very very similar to channels). I think having the channels in the devicetree and adding them to the sensor info struct is a great solution. |
I think its generally a great idea, but as noted because some sensors provide multiple channels of the same type (the referenced PR #60833) it would be nicer if this could refer to not just the type but also the index of the channel. Frankly that problem should be solved before this, or minimally this new binding should always refer to channel index 0 to start until the problem is fixed in the sensor API. So I'd change this slightly for future proofing to be phandle channel_type channel_index |
That's very interesting, are you aware of any previous proposal for adding an index parameter to the sensor API? |
Yes, in my two attempts at updating the API as well as the current iteration from @yperess that supports a decoder, where the channel type is returned as each channel is iterated over. Though somewhat implicit in the current decoder API it was gamed out and thought of on some level. This was one of the many requirements/problems laid out in #1387 and #13718 by @microbuilder |
Note that IIO scheme can be used in DT anyway, in the end, this is about describing the hardware. |
That's fine but then how would io-channels map to sensor channel types which are completely different things? iio channels are described by a channel spec I believe? It's unclear what a io-channel in this scenario would be. e.g. is it this? https://docs.kernel.org/driver-api/iio/core.html#c.iio_chan_spec and the io-channel in this case is the mapped channel id? Zephyr sensors lack this channel descriptor and mapping idea entirely for better or worse, there's no notion that sensor X has channel 0 which represents acceleration in the X axis in SI units, iio seems to have this sort of descriptor available and mapped to a numerical channel. |
We use IIO and I agree with Tom, this issue is complex enough without adding another requirement to it. I would vote for us finding a clean way to migrate things forward in a way that fits Zephyr (i.e. backward compatible). I think that listing these "capabilities" in devicetree is great, but some projects have very specific application code and probably won't benefit from this. In a similar way, the sensor info struct is only added behind a Kconfig. That's the pattern we should model here. This is great for generic apps/libraries that want to iterate of expose sensors to another client, but it's not really needed for many other applications. |
Considering that there is no opposition to the approach I proposed here I'll just finish the code and make a normal PR.
I'll update the bindings to be more flexible. When it comes to adding "index" to the sensor API itself it might be a bit more complicated.
Option 1. is much cleaner, but it breaks API. With option 2 we also bloat the API and increase the overall flash size.
Apart from that we also might want to specify a pair of (channel, index). |
@teburd Take a look at https://github.com/semihalf-Duleba-Kornel/zephyr/commits/sensor-index-dt. |
No objections from me assuming the sensor maintainers agree. |
What hardware would the consumer DT node represent? It seems like this approach would lead to nodes in the devicetree that have no relation to hardware. |
Is having a physical piece of hardware that corresponds to a DT node a hard requirement? I'm currently working on implementing a thermal framework, something similar to Linux thermal zones. |
Yeah I think these sort of soft-devices are the right thing to do in these cases, before the input-longpress there was cdc-acm-uart, now we have the lvgl input nodes. Besides being a good spot for a structured config and laying down a pattern for the config/data struct and multiple instances in the driver, you also get the phandle based dependency check for the initialization sequence by doing that. |
Virtual-devices, CDC ACM UART is a type of emulated UART device, in the application it can be replaced with a real controller.
+1 |
In that case I think this should be https://docs.zephyrproject.org/latest/build/dts/bindings-upstream.html#the-zephyr-prefix
|
That's pretty much the plan :) |
Introduction
Configuration parameters in Zephyr are normally set in DT. In particular consumers of a device usually refer to it using phandle-array type, which allows them to specify configuration parameters in addition to the phandle itself.
The goal of this proposal is to enable the specification of a sensor channel through DT.
Problem description
Some temperature sensors expose multiple temperature probes from a single device. The probe to read the temperature from is selected using the sensor channel. Usually driver specific, a.k.a private channels are used for this purpose. See PR with F75303 driver as example - #60833.
In addition to that Zephyr itself defines three different temperature channels:
Application that reads the temperature needs to specify which channel to use. Right now it has to be hardcoded in the source itself. This is not ideal, and definitely not scalable.
Proposed change
This proposal enables the specification of a sensor channel in DT. As mentioned above, it's aimed at consumer applications of temperature sensors, but it might prove to be useful in other types of sensors as well.
Detailed RFC
The change can be split into two parts:
#sensor-cells property
insensor-device.yaml
binding. This way a sensor device node can be referenced using thephandle-array
property type.dt-bindings
directory. In the future additional channels might be added.Proposed change (Detailed)
The Commit with the proposed change can be found here.
To make sure that the
#sensor-cells
property is inherited by all sensor devices bindings defined insensor-device.yaml
binding. Additionally it’s marked as optional to retain backward compatibility.Then each DT node of a sensor that wants to use this has to be modified to contain:
#sensor-cells = <1>;
To expose all temperature related channels in DT their values have been redefined in a dedicated header under
dt-bindings
directory.The redefinition is necessary for two reasons:
In the consumer DT node the following can be added to reference the temperature sensors
Dependencies
N/A
Concerns and Unresolved Questions
Admittedly duplication of sensor channel value definitions is not among the best coding practices. Any suggestion on how to implement this in a cleaner way is more than appreciated.
Alternatives
The text was updated successfully, but these errors were encountered: