All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Stefan Lengfeld <stefan.lengfeld@inovex.de>
Cc: <linux-iio@vger.kernel.org>
Subject: Re: Questions: IIO type for absorbance and float values in channels?
Date: Tue, 21 Jun 2022 13:29:09 +0100	[thread overview]
Message-ID: <20220621132909.00005439@Huawei.com> (raw)
In-Reply-To: <20220621121855.ynnv5ckymbmmvjcm@gmail.com>

On Tue, 21 Jun 2022 14:18:55 +0200
Stefan Lengfeld <stefan.lengfeld@inovex.de> wrote:

> Hi all,

Hi Stefan,

> 
> I'm currently working on a linux kernel driver for a new sensor design. It's a
> special kind of light sensor that measures the reflection of emitted light.
> 
> I'm trying to fit this type of sensor into the IIO subsystem but I hit some
> issues.
> 
> 
> 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.

So probably needs a new channel type.

 
> 
> 
> Question 2:
> 
> The sensor effectively returns a float value of the measurement. I grepped trough
> the existing IIO drivers, but there seems only one driver that deals with float
> values.  The sps30 driver[3] gets a float from the device, but converts it to a
> integer value before passing it to the IIO subsystem.
> 
> 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.


> 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.

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.

> 
> 
> Question 3:
> 
> 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.

Jonathan

> 
> 
> Thanks a lot for answering my question.
> 
> 
> Kind regards,
> Stefan
> 
> [1]: https://en.wikipedia.org/wiki/Absorbance
> [2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/iio/types.h#n14
> [3]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/iio/chemical/sps30.c#n39
> [4]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/iio/dummy/iio_simple_dummy.c#n122


  reply	other threads:[~2022-06-21 12:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21 12:18 Questions: IIO type for absorbance and float values in channels? Stefan Lengfeld
2022-06-21 12:29 ` Jonathan Cameron [this message]
2022-06-21 14:13   ` Andy Shevchenko
2022-06-21 19:26     ` Jonathan Cameron
2022-06-22 15:42   ` Stefan Lengfeld
2022-06-25 13:21     ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220621132909.00005439@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=stefan.lengfeld@inovex.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.