From: "Erim, Salih" <salih.erim@amd.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: andy@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
conall.ogriofa@amd.com, michal.simek@amd.com, linux@roeck-us.net,
erimsalih@gmail.com, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 5/5] iio: adc: versal-sysmon: add oversampling support
Date: Fri, 12 Jun 2026 14:45:26 +0100 [thread overview]
Message-ID: <538eb304-6a55-4c52-b5b1-07a7788de6aa@amd.com> (raw)
In-Reply-To: <20260612135836.526cc07f@jic23-huawei>
Hi Jonathan,
On 12/06/2026 13:58, Jonathan Cameron wrote:
> On Thu, 11 Jun 2026 23:27:38 +0100
> Salih Erim <salih.erim@amd.com> wrote:
>
>> Add support for reading and writing the oversampling ratio through
>> the IIO oversampling_ratio attribute. The hardware supports averaging
>> 2, 4, 8, or 16 samples, plus a ratio of 1 (no averaging).
>>
>> Temperature and supply channels share oversampling configuration at
>> the type level (all temperature channels share one ratio, all supply
>> channels share another), exposed through info_mask_shared_by_type.
>>
>> The hardware encoding uses sample_count / 2 in a 4-bit field within
>> the CONFIG register. Per-channel averaging enable registers must also
>> be updated to activate or deactivate averaging.
>>
>> Signed-off-by: Salih Erim <salih.erim@amd.com>
>
> One minor comment inline.
>
>> drivers/iio/adc/versal-sysmon-core.c | 147 ++++++++++++++++++++++++++-
>> drivers/iio/adc/versal-sysmon.h | 17 ++++
>> 2 files changed, 163 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/adc/versal-sysmon-core.c b/drivers/iio/adc/versal-sysmon-core.c
>> index 20fd3a87d44..fa8f0dc868a 100644
>> --- a/drivers/iio/adc/versal-sysmon-core.c
>> +++ b/drivers/iio/adc/versal-sysmon-core.c
>
>> +static int sysmon_osr_write(struct sysmon *sysmon, int channel_type, int val)
>
> There is almost nothing shared in here between the two channel_types.
> Might make sense to just split it into two helpers, particularly as
> there is a channel type if / else at the caller.
Agreed. The only shared code outside the switch is the hw_val
computation. Will split into two helpers in v7.
Thanks,
Salih
>
>> +{
>> + /*
>> + * HW register encoding is sample_count / 2:
>> + * 0=none, 1=2x, 2=4x, 4=8x, 8=16x (not log2-based).
>> + */
>> + int hw_val = val >> 1;
>> + unsigned int readback;
>> + int ret;
>> +
>> + switch (channel_type) {
>> + case IIO_TEMP:
>> + ret = regmap_update_bits(sysmon->regmap, SYSMON_CONFIG,
>> + SYSMON_CONFIG_TEMP_SAT_OSR,
>> + FIELD_PREP(SYSMON_CONFIG_TEMP_SAT_OSR, hw_val));
>> + if (ret)
>> + return ret;
>> +
>> + /*
>> + * Readback fence: the SysMon CONFIG register resides in the
>> + * PMC domain behind the NoC. A posted write may not reach the
>> + * hardware before the next MMIO access. Reading the register
>> + * back forces the interconnect to complete the write, preventing
>> + * a bus hang on the subsequent access.
>> + */
>> + regmap_read(sysmon->regmap, SYSMON_CONFIG, &readback);
>> +
>> + return sysmon_set_avg_enable(sysmon, SYSMON_TEMP_EN_AVG_BASE,
>> + SYSMON_TEMP_EN_AVG_COUNT,
>> + hw_val ? ~0U : 0);
>> + case IIO_VOLTAGE:
>> + ret = regmap_update_bits(sysmon->regmap, SYSMON_CONFIG,
>> + SYSMON_CONFIG_SUPPLY_OSR,
>> + FIELD_PREP(SYSMON_CONFIG_SUPPLY_OSR, hw_val));
>> + if (ret)
>> + return ret;
>> +
>> + /* Readback fence -- see above */
>> + regmap_read(sysmon->regmap, SYSMON_CONFIG, &readback);
>> +
>> + return sysmon_set_avg_enable(sysmon, SYSMON_SUPPLY_EN_AVG_BASE,
>> + SYSMON_SUPPLY_EN_AVG_COUNT,
>> + hw_val ? ~0U : 0);
>> + default:
>> + return -EINVAL;
>> + }
>> +}
>> +
>> +static int sysmon_write_raw(struct iio_dev *indio_dev,
>> + struct iio_chan_spec const *chan,
>> + int val, int val2, long mask)
>> +{
>> + struct sysmon *sysmon = iio_priv(indio_dev);
>> + unsigned int i;
>> + int ret;
>> +
>> + if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO)
>> + return -EINVAL;
>> +
>> + for (i = 0; i < ARRAY_SIZE(sysmon_oversampling_avail); i++) {
>> + if (val == sysmon_oversampling_avail[i])
>> + break;
>> + }
>> + if (i == ARRAY_SIZE(sysmon_oversampling_avail))
>> + return -EINVAL;
>> +
>> + guard(mutex)(&sysmon->lock);
>> +
>> + ret = sysmon_osr_write(sysmon, chan->type, val);
>> + if (ret)
>> + return ret;
>> +
>> + if (chan->type == IIO_TEMP)
>> + sysmon->temp_oversampling = val;
>> + else
>> + sysmon->supply_oversampling = val;
>> +
>> + return 0;
>> +}
prev parent reply other threads:[~2026-06-12 13:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 22:27 [PATCH v6 0/5] iio: adc: add AMD/Xilinx Versal SysMon driver Salih Erim
2026-06-11 22:27 ` [PATCH v6 1/5] dt-bindings: iio: adc: add xlnx,versal-sysmon binding Salih Erim
2026-06-11 22:27 ` [PATCH v6 2/5] iio: adc: add Versal SysMon driver Salih Erim
2026-06-12 12:10 ` Jonathan Cameron
2026-06-12 12:40 ` Erim, Salih
2026-06-11 22:27 ` [PATCH v6 3/5] iio: adc: versal-sysmon: add I2C driver Salih Erim
2026-06-11 22:37 ` sashiko-bot
2026-06-11 22:27 ` [PATCH v6 4/5] iio: adc: versal-sysmon: add threshold event support Salih Erim
2026-06-11 22:40 ` sashiko-bot
2026-06-12 12:52 ` Jonathan Cameron
2026-06-12 13:39 ` Erim, Salih
2026-06-12 13:43 ` Jonathan Cameron
2026-06-11 22:27 ` [PATCH v6 5/5] iio: adc: versal-sysmon: add oversampling support Salih Erim
2026-06-11 22:40 ` sashiko-bot
2026-06-12 12:58 ` Jonathan Cameron
2026-06-12 13:45 ` Erim, Salih [this message]
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=538eb304-6a55-4c52-b5b1-07a7788de6aa@amd.com \
--to=salih.erim@amd.com \
--cc=andy@kernel.org \
--cc=conall.ogriofa@amd.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=erimsalih@gmail.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=michal.simek@amd.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/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