Hi Jonathan, On Tue, Jun 21, 2022 at 01:29:09PM +0100, Jonathan Cameron wrote: > > Is there another kernel subsystem/UAPI that fits this type of sensor > > better? (My guess would be: No, IIO is the correct subsystem.) > > Based on your description, IIO is the best option. Great. This means that I'm on the right track. > > Question 1: > > > > The sensor measures the absorbance[1] of a material. It's the negative > > logarithmic quotient of the received and emitted light. It's a unit-less value. > > > > As far as I can see there is currently no predefined IIO type in the kernel for > > this. I have search the list [2], but nothing matches. > > > > Do I overlook something or what channel type should I use for this sensor > > measurement value? > > So the closest we've seen to this is some of the health sensors (pulse oximeter > targeting devices) but in that case the processing is done with a custom userspace > library so we just pass values on in fixed point. I have look at the 'oximeter' drivers in the IIO framework, namely afe440x and max3010x. All use the IIO type IIO_INTENSITY and the max30100x drivers also use the modifiers IIO_MOD_LIGHT_*. You also referenced the modifiers in your response to Andy. > So probably needs a new channel type. Ok. This makes it a bit harder for us, because we want to provide a kernel driver that also works for older kernels. Is there a private IIO type range that can be use in the meantime, until a new IIO type is accepted and merged upstream? Another side note/question: Is there a documented mapping between the IIO types and physical SI units? I have found nothing about that in the IIO documentation. It would have helped me to better understand the differences between the various types. Just for reference. I mentioned the absorbance, but there is also another equivalent physical value: the refelctance[1]. It's the same value just without the negative logarithm. > > So effectively the result of a > > measurement can be a float-point value after it's computed in userspace. > > > > Are floats really not supported as channel values? What is the recommend > > approach to deal with these measurement values? > > So, in kernel we basically can't do floats (not quite true, but near enough that > it doesn't matter). Given IIO can have in kernel consumers, that more or > less rules out true floating point handling. Yes, float point math is frowned in the kernel. I have read the kernel hacking documentation [2]. :-) But I also know that the functions kernel_fpu_begin() and kernel_fpu_end() exist (including there performance problems ;-) ). > We have in the past discussed simply passing them on to userspace (and > hence ruling out any interpretation of the value) but so far no one has added > the necessary support. I'm not against adding that support, but I would > want to see the code / docs to fully understand why we are doing it. > It will be a special case in various code paths hence the extra consideration > needed. Ack on that. My take way is that it's currently not implemented but theoretical acceptable upstream to pass float point values from the chip to userspace. But it would require a good/valid show case and extra work in the IIO subsystem. I take this information to the sensor engineers. Maybe we can rework the communication/data protocol to pass the measurement as integer values with a separate scale factor that does not require raw float point values. > > I know that it's possible to provide a 'scale' attribute per channel to > > userspace[4], which can be a float point number. > > More fixed point - though we have a couple of precision options. The aim there > is to ensure we only need a few bits of custom code to consume these values > in kernel. Raw value can also be fixed point. Yes. I already saw and tested the IIO_VAL_* defines (like IIO_VAL_INT_PLUS_NANO or IIO_VAL_FRACTIONAL) that can be used to provide fixed point scale values to userspace. They work great and maybe we can use them. Thanks again! Kind Regards, Stefan [1]: https://en.wikipedia.org/wiki/Reflectance [2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/kernel-hacking/hacking.rst?id=9d2231c5d74e13b2a0546fee6737ee4446017903#n134