public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Guilherme Ivo Bozi <guilherme.bozi@usp.br>
Cc: "Salih Erim" <salih.erim@amd.com>,
	"Conall O'Griofa" <conall.ogriofa@amd.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Michal Simek" <michal.simek@amd.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] iio: adc: xilinx-ams: refactor alarm mapping to table-driven approach
Date: Tue, 14 Apr 2026 13:04:34 +0300	[thread overview]
Message-ID: <ad4RMqwGR3Mya0vY@ashevche-desk.local> (raw)
In-Reply-To: <20260414093018.7153-4-guilherme.bozi@usp.br>

On Tue, Apr 14, 2026 at 06:29:30AM -0300, Guilherme Ivo Bozi wrote:
> Replace multiple open-coded switch statements that map between
> scan_index, alarm bits, and register offsets with a centralized
> table-driven approach.
> 
> Introduce a struct-based alarm_map to describe the relationship
> between scan indices and alarm offsets, and add a helper to
> translate scan_index to event IDs. This removes duplicated logic
> across ams_get_alarm_offset(), ams_event_to_channel(), and
> ams_get_alarm_mask().
> 
> The new approach improves maintainability, reduces code size,
> and makes it easier to extend or modify alarm mappings in the
> future, while preserving existing behavior.

...

> +#define AMS_ALARM_INVALID		-1

This value sounds like out of the range, also signed.
Can't 0x000 be used instead?

#define AMS_ALARM_NONE			0x000 /* not a real offset */

>  #define AMS_ALARM_TEMP			0x140
>  #define AMS_ALARM_SUPPLY1		0x144
>  #define AMS_ALARM_SUPPLY2		0x148

...

> +struct ams_alarm_map {
> +	enum ams_ps_pl_seq scan_index;
> +	int base_offset;

With the above we put this as u32 (or whatever is used for offsets).

> +};

...

> +static int ams_scan_index_to_event(int scan_index)
> +{
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(alarm_map); i++) {

	for (unsigned int i = 0; i < ARRAY_SIZE(alarm_map); i++) {

> +		if (alarm_map[i].base_offset == AMS_ALARM_INVALID)
> +			continue;
> +
> +		if (alarm_map[i].scan_index == scan_index)
> +			return i;
> +	}
> +
> +	return -EINVAL;
> +}

-- 
With Best Regards,
Andy Shevchenko




  reply	other threads:[~2026-04-14 10:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-14  9:29 [PATCH 0/3] iio: adc: xilinx-ams: refactor alarm handling to table-driven design Guilherme Ivo Bozi
2026-04-14  9:29 ` [PATCH 1/3] iio: adc: xilinx-ams: fix out-of-bounds channel lookup in event handling Guilherme Ivo Bozi
2026-04-14  9:58   ` Andy Shevchenko
2026-04-14  9:29 ` [PATCH 2/3] iio: adc: xilinx-ams: use guard(mutex) for automatic locking Guilherme Ivo Bozi
2026-04-14  9:59   ` Andy Shevchenko
2026-04-14  9:29 ` [PATCH 3/3] iio: adc: xilinx-ams: refactor alarm mapping to table-driven approach Guilherme Ivo Bozi
2026-04-14 10:04   ` Andy Shevchenko [this message]
2026-04-14 10:29 ` [PATCH v2 0/3] iio: adc: xilinx-ams: refactor alarm handling to table-driven design Guilherme Ivo Bozi
2026-04-14 10:29   ` [PATCH v2 1/3] iio: adc: xilinx-ams: fix out-of-bounds channel lookup in event handling Guilherme Ivo Bozi
2026-04-14 18:37     ` Andy Shevchenko
2026-04-14 10:29   ` [PATCH v2 2/3] iio: adc: xilinx-ams: use guard(mutex) for automatic locking Guilherme Ivo Bozi
2026-04-14 10:29   ` [PATCH v2 3/3] iio: adc: xilinx-ams: refactor alarm mapping to table-driven approach Guilherme Ivo Bozi
2026-04-14 18:40     ` Andy Shevchenko
2026-04-14 11:33   ` [PATCH v2 0/3] iio: adc: xilinx-ams: refactor alarm handling to table-driven design 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=ad4RMqwGR3Mya0vY@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=conall.ogriofa@amd.com \
    --cc=dlechner@baylibre.com \
    --cc=guilherme.bozi@usp.br \
    --cc=jic23@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@amd.com \
    --cc=nuno.sa@analog.com \
    --cc=salih.erim@amd.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