From: "Erim, Salih" <salih.erim@amd.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Andy Shevchenko" <andy@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>, "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Conall O'Griofa" <conall.ogriofa@amd.com>,
"Michal Simek" <michal.simek@amd.com>,
"Guenter Roeck" <linux@roeck-us.net>,
"Salih Erim" <erimsalih@gmail.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 5/5] iio: adc: versal-sysmon: add oversampling support
Date: Sun, 7 Jun 2026 23:29:23 +0100 [thread overview]
Message-ID: <3a550d80-b4e5-4e94-ab11-cddafad023c2@amd.com> (raw)
In-Reply-To: <aiUi4jRd2C8kczkt@ashevche-desk.local>
Hi Andy,
On 07/06/2026 08:50, Andy Shevchenko wrote:
>
> On Sat, Jun 06, 2026 at 06:17:07AM +0100, Salih Erim 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
>
> ...
>
>> +static int sysmon_set_avg_enable(struct sysmon *sysmon,
>> + u32 base, u32 count, u32 val)
>> +{
>> + int ret;
>> +
>> + for (unsigned int i = 0; i < count; i++) {
>> + ret = regmap_write(sysmon->regmap,
>> + base + (i * SYSMON_REG_STRIDE), val);
>
> Unneeded parentheses.
Accepted.
>
>> + if (ret)
>> + return ret;
>> + }
>
> Also you can use temporary for regmap
>
> struct regmap *map = sysmon->regmap;
> int ret;
>
> for (unsigned int i = 0; i < count; i++) {
> ret = regmap_write(map, base + i * SYSMON_REG_STRIDE, val);
> if (ret)
> return ret;
> }
>
>> + return 0;
>> +}
>
> And use this trick in other places where appropriate, it makes code easier
> to read.
Accepted. Will use a local regmap pointer in functions with
repeated sysmon->regmap access.
>
> ...
>
>> +static int sysmon_osr_write(struct sysmon *sysmon, int channel_type, int val)
>> +{
>> + /*
>> + * 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;
>> + int ret;
>> +
>> + if (channel_type == 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;
>> +
>> + return sysmon_set_avg_enable(sysmon, SYSMON_TEMP_EN_AVG_BASE,
>> + SYSMON_TEMP_EN_AVG_COUNT,
>> + hw_val ? ~0U : 0);
>
>> + }
>> +
>> + if (channel_type == IIO_VOLTAGE) {
>
> Can channel_type be both TEMP and VOLTAGE here? No. Why do we check it twice?
Good point. Will restructure to use switch or if/else to
make it clear only one path executes.
Thanks,
Salih
>
>> + ret = regmap_update_bits(sysmon->regmap, SYSMON_CONFIG,
>> + SYSMON_CONFIG_SUPPLY_OSR,
>> + FIELD_PREP(SYSMON_CONFIG_SUPPLY_OSR,
>> + hw_val));
>> + if (ret)
>> + return ret;
>> +
>> + return sysmon_set_avg_enable(sysmon, SYSMON_SUPPLY_EN_AVG_BASE,
>> + SYSMON_SUPPLY_EN_AVG_COUNT,
>> + hw_val ? ~0U : 0);
>> + }
>> + return -EINVAL;
>> +}
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
prev parent reply other threads:[~2026-06-07 22:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-06 5:17 [PATCH v4 0/5] iio: adc: add AMD/Xilinx Versal SysMon driver Salih Erim
2026-06-06 5:17 ` [PATCH v4 1/5] dt-bindings: iio: adc: add xlnx,versal-sysmon binding Salih Erim
2026-06-06 5:27 ` sashiko-bot
2026-06-06 5:17 ` [PATCH v4 2/5] iio: adc: add Versal SysMon driver Salih Erim
2026-06-07 8:06 ` Andy Shevchenko
2026-06-07 8:08 ` Andy Shevchenko
2026-06-07 20:55 ` Erim, Salih
2026-06-07 20:45 ` Erim, Salih
2026-06-09 17:34 ` Andy Shevchenko
2026-06-06 5:17 ` [PATCH v4 3/5] iio: adc: versal-sysmon: add I2C driver Salih Erim
2026-06-06 5:27 ` sashiko-bot
2026-06-06 18:34 ` Andy Shevchenko
2026-06-07 10:27 ` Erim, Salih
2026-06-06 5:17 ` [PATCH v4 4/5] iio: adc: versal-sysmon: add threshold event support Salih Erim
2026-06-06 5:31 ` sashiko-bot
2026-06-07 7:31 ` Andy Shevchenko
2026-06-07 21:02 ` Erim, Salih
2026-06-09 17:31 ` Andy Shevchenko
2026-06-10 11:46 ` Erim, Salih
2026-06-10 13:51 ` Andy Shevchenko
2026-06-06 5:17 ` [PATCH v4 5/5] iio: adc: versal-sysmon: add oversampling support Salih Erim
2026-06-06 5:30 ` sashiko-bot
2026-06-07 7:50 ` Andy Shevchenko
2026-06-07 22:29 ` 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=3a550d80-b4e5-4e94-ab11-cddafad023c2@amd.com \
--to=salih.erim@amd.com \
--cc=andriy.shevchenko@intel.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