mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Shreeya Patel <shreeya.patel@collabora.com>,
	Paul Gazzillo <paul@pgazz.com>,
	Dmitry Osipenko <dmitry.osipenko@collabora.com>,
	Zhigang Shi <Zhigang.Shi@liteon.com>,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH v3 2/6] iio: light: Add gain-time-scale helpers
Date: Mon, 13 Mar 2023 14:52:45 +0200	[thread overview]
Message-ID: <d6a3fbb8-d51d-b1cf-444c-f9422c22927c@gmail.com> (raw)
In-Reply-To: <20230312170638.3e6807b7@jic23-huawei>

On 3/12/23 19:06, Jonathan Cameron wrote:
> On Mon, 6 Mar 2023 11:17:15 +0200
> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> 
>> Some light sensors can adjust both the HW-gain and integration time.
>> There are cases where adjusting the integration time has similar impact
>> to the scale of the reported values as gain setting has.
>>
>> IIO users do typically expect to handle scale by a single writable 'scale'
>> entry. Driver should then adjust the gain/time accordingly.
>>
>> It however is difficult for a driver to know whether it should change
>> gain or integration time to meet the requested scale. Usually it is
>> preferred to have longer integration time which usually improves
>> accuracy, but there may be use-cases where long measurement times can be
>> an issue. Thus it can be preferable to allow also changing the
>> integration time - but mitigate the scale impact by also changing the gain
>> underneath. Eg, if integration time change doubles the measured values,
>> the driver can reduce the HW-gain to half.
>>
>> The theory of the computations of gain-time-scale is simple. However,
>> some people (undersigned) got that implemented wrong for more than once.
>>
>> Add some gain-time-scale helpers in order to not dublicate errors in all
>> drivers needing these computations.
>>
>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> 
> Trying not to duplicate what Andy has raised...
> 
> 
> At some stage I want to go through the maths very carefully but it's
> not happening today and I don't want to delay resolving other remaining comments
> so that can wait for a later version. I'm sure it's fine but I like to be
> paranoid :)
> 

This is more than welcome! I tried to add some test cases for verifying 
some parts - but extra pair of eyes is always more than appreciated! 
I've written and read way too many bugs to not appreciate a healthy 
amount of paranoia :)

>> +int iio_gts_get_total_gain(struct iio_gts *gts, int gain, int time)
>> +{
>> +	const struct iio_itime_sel_mul *itime;
>> +
>> +	if (!iio_gts_valid_gain(gts, gain))
>> +		return -EINVAL;
>> +
>> +	if (!gts->num_itime)
>> +		return gain;
>> +
>> +	itime = iio_gts_find_itime_by_time(gts, time);
>> +	if (!itime)
>> +		return -EINVAL;
>> +
>> +	return gain * itime->mul;
>> +}
>> +EXPORT_SYMBOL(iio_gts_get_total_gain);
> 
> All of them want to be in the namespace.

Seems like I accidentally did not use the EXPORT_SYMBOL_GPL for this 
one. It must thus have evaded my conversion to name space one. Thanks!

> 
> 
>> diff --git a/drivers/iio/light/iio-gts-helper.h b/drivers/iio/light/iio-gts-helper.h
>> new file mode 100644
>> index 000000000000..4b5a417946f4
>> --- /dev/null
>> +++ b/drivers/iio/light/iio-gts-helper.h
> 
> ...
> 
>> +int iio_gts_find_new_gain_sel_by_old_gain_time(struct iio_gts *gts,
>> +					       int old_gain, int old_time_sel,
>> +					       int new_time_sel, int *new_gain);
>> +int iio_gts_build_avail_tables(struct iio_gts *gts);
>> +int devm_iio_gts_build_avail_tables(struct device *dev, struct iio_gts *gts);
>> +int iio_gts_build_avail_scale_table(struct iio_gts *gts);
>> +int devm_iio_gts_build_avail_scale_table(struct device *dev, struct iio_gts *gts);
>> +int iio_gts_build_avail_time_table(struct iio_gts *gts);
>> +int devm_iio_gts_build_avail_time_table(struct device *dev, struct iio_gts *gts);
> 
> Given most modern IIO drivers use fully devm_ based probing, for now I would not
> expose anything else.  That will reduce the interface a lot which I think
> is probably a good thing at this stage.
> 
> Keep the non devm stuff internally though as it is a nice structure to have
> an I can see we may want some of these in non devm form in the future.
> 
> Similarly - for now don't expose the individual table building functions
> as we may never need them in drivers.  We (more or less) only support interfaces
> that are used and so far they aren't.
> 
> For other functions it's worth thinking about whether to not export them
> initially. I haven't been through them all to figure out what is not currently used.
> 
>> +void iio_gts_purge_avail_scale_table(struct iio_gts *gts);
>> +void iio_gts_purge_avail_time_table(struct iio_gts *gts);
>> +void iio_gts_purge_avail_tables(struct iio_gts *gts);
>> +int iio_gts_avail_times(struct iio_gts *gts,  const int **vals, int *type,
>> +			int *length);
>> +int iio_gts_all_avail_scales(struct iio_gts *gts, const int **vals, int *type,
>> +			     int *length);
>> +int iio_gts_avail_scales_for_time(struct iio_gts *gts, int time,
>> +				  const int **vals, int *type, int *length);
>> +
>> +#endif
> 

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


  parent reply	other threads:[~2023-03-13 12:52 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-06  9:15 [PATCH v3 0/6] Support ROHM BU27034 ALS sensor Matti Vaittinen
2023-03-06  9:15 ` [PATCH v3 1/6] dt-bindings: iio: light: Support ROHM BU27034 Matti Vaittinen
2023-03-06  9:17 ` [PATCH v3 2/6] iio: light: Add gain-time-scale helpers Matti Vaittinen
2023-03-06 12:52   ` Andy Shevchenko
2023-03-12 16:51     ` Jonathan Cameron
2023-03-13 12:56       ` Matti Vaittinen
2023-03-13 13:14         ` Andy Shevchenko
2023-03-14  6:19           ` Vaittinen, Matti
2023-03-14 11:12             ` Andy Shevchenko
2023-03-18 17:17             ` Jonathan Cameron
2023-03-19 14:28               ` Matti Vaittinen
2023-03-18 17:24         ` Jonathan Cameron
2023-03-13 12:47     ` Matti Vaittinen
2023-03-13 13:25       ` Andy Shevchenko
2023-03-13 13:59         ` Matti Vaittinen
2023-03-13 14:17           ` Andy Shevchenko
2023-03-13 14:25             ` Matti Vaittinen
2023-03-18 17:29           ` Jonathan Cameron
2023-03-12 17:06   ` Jonathan Cameron
2023-03-12 17:08     ` Jonathan Cameron
2023-03-13 12:40       ` Andy Shevchenko
2023-03-13 13:11         ` Matti Vaittinen
2023-03-13 13:29           ` Andy Shevchenko
2023-03-13 13:59             ` Matti Vaittinen
2023-03-15 10:51               ` Matti Vaittinen
2023-03-15 14:12                 ` Andy Shevchenko
2023-03-15 14:14                   ` Andy Shevchenko
2023-03-17 10:19                 ` Maxime Ripard
2023-03-17 10:57                   ` Vaittinen, Matti
2023-03-13 12:52     ` Matti Vaittinen [this message]
2023-03-06  9:17 ` [PATCH v3 3/6] iio: test: test " Matti Vaittinen
2023-03-06  9:19 ` [PATCH v3 4/6] MAINTAINERS: Add IIO " Matti Vaittinen
2023-03-06  9:23 ` [PATCH v3 5/6] iio: light: ROHM BU27034 Ambient Light Sensor Matti Vaittinen
2023-03-12 17:39   ` Jonathan Cameron
2023-03-13 13:34     ` Matti Vaittinen
2023-03-06  9:27 ` [PATCH v3 6/6] MAINTAINERS: Add ROHM BU27034 Matti Vaittinen
2023-03-06 12:25 ` [PATCH v3 0/6] Support ROHM BU27034 ALS sensor Andy Shevchenko

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=d6a3fbb8-d51d-b1cf-444c-f9422c22927c@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=Zhigang.Shi@liteon.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=paul@pgazz.com \
    --cc=shreeya.patel@collabora.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®