From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: "Patrik Dahlström" <risca@dalakolonin.se>
Cc: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<letux-kernel@openphoenux.org>, <kernel@pyra-handheld.com>,
<pgoudagunta@nvidia.com>, <hns@goldelico.com>, <jic23@kernel.org>,
<lars@metafoo.de>, <linux-omap@vger.kernel.org>
Subject: Re: [PATCH v4 8/9] iio: adc: palmas: add support for iio threshold events
Date: Thu, 13 Apr 2023 11:28:30 +0100 [thread overview]
Message-ID: <20230413112830.00006279@Huawei.com> (raw)
In-Reply-To: <20230408114825.824505-9-risca@dalakolonin.se>
On Sat, 8 Apr 2023 13:48:24 +0200
Patrik Dahlström <risca@dalakolonin.se> wrote:
> The palmas gpadc block has support for monitoring up to 2 ADC channels
> and issue an interrupt if they reach past a set threshold. This change
> hooks into the IIO events system and exposes to userspace the ability to
> configure these threshold values for each channel, but only allow up to
> 2 such thresholds to be enabled at any given time. Trying to enable a
> third channel will result in an error.
>
> Userspace is expected to input calibrated, as opposed to raw, values as
> threshold. However, it is not enough to do the opposite of what is done
> when converting the other way around. To account for tolerances in the
> ADC, the calculated raw threshold should be adjusted based on the ADC
> specifications for the device. These specifications include the integral
> nonlinearity (INL), offset, and gain error. To adjust the high
> threshold, use the following equation:
>
> (calibrated value + INL) * Gain error + offset = maximum value [1]
>
> Likewise, use the following equation for the low threshold:
>
> (calibrated value - INL) * Gain error - offset = minimum value
>
> The gain error is a combination of gain error, as listed in the
> datasheet, and gain error drift due to temperature and supply. The exact
> values for these specifications vary between palmas devices. This patch
> sets the values found in TWL6035, TWL6037 datasheet.
>
> [1] TI Application Report, SLIA087A, Guide to Using the GPADC in
> TPS65903x, TPS65917-Q1, TPS65919-Q1, and TPS65916 Devices.
>
> Signed-off-by: Patrik Dahlström <risca@dalakolonin.se>
0-day found some stuff we'd missed in here.
I've fixed it up and pushed out again.
> ---
...
> +static int palmas_gpadc_write_event_value(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + enum iio_event_type type,
> + enum iio_event_direction dir,
> + enum iio_event_info info,
> + int val, int val2)
> +{
> + struct palmas_gpadc *adc = iio_priv(indio_dev);
> + int adc_chan = chan->channel;
> + int old;
> + int ret;
> +
> + if (adc_chan > PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH)
> + return -EINVAL;
> +
> + mutex_lock(&adc->lock);
> + switch (info) {
> + case IIO_EV_INFO_VALUE:
> + if (val < 0 || val > 0xFFF) {
> + ret = -EINVAL;
> + break;
Should be goto out_unlock; Found because old is undefined.
> + }
> + if (dir == IIO_EV_DIR_RISING) {
> + old = adc->thresholds[adc_chan].high;
> + adc->thresholds[adc_chan].high = val;
> + }
Whilst here should be } else {
Tidied both up force an update on the testing branch.
> + else {
> + old = adc->thresholds[adc_chan].low;
> + adc->thresholds[adc_chan].low = val;
> + }
> + ret = 0;
> + break;
> + default:
> + ret = -EINVAL;
> + goto out_unlock;
> + }
> +
> + if (val != old && palmas_gpadc_get_event(adc, adc_chan, dir))
> + ret = palmas_gpadc_reconfigure_event_channels(adc);
> +
> +out_unlock:
> + mutex_unlock(&adc->lock);
> +
> + return ret;
> +}
> +
next prev parent reply other threads:[~2023-04-13 10:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-08 11:48 [PATCH v4 0/9] iio: adc: palmas_gpadc: add iio events Patrik Dahlström
2023-04-08 11:48 ` [PATCH v4 1/9] iio: adc: palmas_gpadc: fix NULL dereference on rmmod Patrik Dahlström
2023-04-08 11:48 ` [PATCH v4 2/9] iio: adc: palmas: Take probe fully device managed Patrik Dahlström
2023-04-08 11:48 ` [PATCH v4 3/9] iio: adc: palmas: remove adc_wakeupX_data Patrik Dahlström
2023-04-08 11:48 ` [PATCH v4 4/9] iio: adc: palmas: replace "wakeup" with "event" Patrik Dahlström
2023-04-08 11:48 ` [PATCH v4 5/9] iio: adc: palmas: use iio_event_direction for threshold polarity Patrik Dahlström
2023-04-08 11:48 ` [PATCH v4 6/9] iio: adc: palmas: move eventX_enable into palmas_adc_event Patrik Dahlström
2023-04-08 11:48 ` [PATCH v4 7/9] iio: adc: palmas: always reset events on unload Patrik Dahlström
2023-04-08 11:48 ` [PATCH v4 8/9] iio: adc: palmas: add support for iio threshold events Patrik Dahlström
2023-04-13 10:28 ` Jonathan Cameron [this message]
2023-04-08 11:48 ` [PATCH v4 9/9] iio: adc: palmas: don't alter event config on suspend/resume Patrik Dahlström
2023-04-12 20:22 ` [PATCH v4 0/9] iio: adc: palmas_gpadc: add iio events 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=20230413112830.00006279@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=hns@goldelico.com \
--cc=jic23@kernel.org \
--cc=kernel@pyra-handheld.com \
--cc=lars@metafoo.de \
--cc=letux-kernel@openphoenux.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=pgoudagunta@nvidia.com \
--cc=risca@dalakolonin.se \
/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.