The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] iio: adc: ad7124: drop nr field
@ 2025-09-17 20:39 David Lechner
  2025-09-17 20:39 ` [PATCH 1/2] iio: adc: ad7124: inline ad7124_enable_channel() David Lechner
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: David Lechner @ 2025-09-17 20:39 UTC (permalink / raw)
  To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
	Andy Shevchenko
  Cc: linux-iio, linux-kernel, David Lechner

The motivation behind this series was to remove the `nr` field in struct
ad7124_channel since it is duplicating the same value as struct
iio_chan_spec.address (and duplicated again by .scan_index).

When it came to actually doing that though, I found that it was easier
to first clean things up by removing the ad7124_enable_channel()
function - which is a nice cleanup by itself. So ended up with 2 patches
that end with the same result without ever mentioning the duplication.

---
David Lechner (2):
      iio: adc: ad7124: inline ad7124_enable_channel()
      iio: adc: ad7124: remove unused `nr` field

 drivers/iio/adc/ad7124.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
---
base-commit: 561285d048053fec8a3d6d1e3ddc60df11c393a0
change-id: 20250917-iio-adc-ad7124-drop-nr-field-518102218a61

Best regards,
-- 
David Lechner <dlechner@baylibre.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] iio: adc: ad7124: inline ad7124_enable_channel()
  2025-09-17 20:39 [PATCH 0/2] iio: adc: ad7124: drop nr field David Lechner
@ 2025-09-17 20:39 ` David Lechner
  2025-09-17 20:39 ` [PATCH 2/2] iio: adc: ad7124: remove unused `nr` field David Lechner
  2025-09-18 10:25 ` [PATCH 0/2] iio: adc: ad7124: drop nr field Nuno Sá
  2 siblings, 0 replies; 5+ messages in thread
From: David Lechner @ 2025-09-17 20:39 UTC (permalink / raw)
  To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
	Andy Shevchenko
  Cc: linux-iio, linux-kernel, David Lechner

Inline ad7124_enable_channel() at the only call site. This simplifies
the code by avoiding a bit of extra indirection.

ch->nr is replaced by address as that is the same value and avoids more
indirection.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/adc/ad7124.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 910b40393f77de84afc77d406c17c6e5051a02cd..c61a95c5881a69e38c21ce4c340a0a61864de22b 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -627,14 +627,6 @@ static int ad7124_push_config(struct ad7124_state *st, struct ad7124_channel_con
 	return ad7124_write_config(st, cfg, free_cfg_slot);
 }
 
-static int ad7124_enable_channel(struct ad7124_state *st, struct ad7124_channel *ch)
-{
-	ch->cfg.live = true;
-	return ad_sd_write_reg(&st->sd, AD7124_CHANNEL(ch->nr), 2, ch->ain |
-			       FIELD_PREP(AD7124_CHANNEL_SETUP, ch->cfg.cfg_slot) |
-			       AD7124_CHANNEL_ENABLE);
-}
-
 static int ad7124_prepare_read(struct ad7124_state *st, int address)
 {
 	struct ad7124_channel_config *cfg = &st->channels[address].cfg;
@@ -654,7 +646,11 @@ static int ad7124_prepare_read(struct ad7124_state *st, int address)
 	}
 
 	/* point channel to the config slot and enable */
-	return ad7124_enable_channel(st, &st->channels[address]);
+	cfg->live = true;
+	return ad_sd_write_reg(&st->sd, AD7124_CHANNEL(address), 2,
+			       st->channels[address].ain |
+			       FIELD_PREP(AD7124_CHANNEL_SETUP, cfg->cfg_slot) |
+			       AD7124_CHANNEL_ENABLE);
 }
 
 static int __ad7124_set_channel(struct ad_sigma_delta *sd, unsigned int channel)
@@ -1555,7 +1551,7 @@ static int __ad7124_calibrate_all(struct ad7124_state *st, struct iio_dev *indio
 			 * after full-scale calibration because the next
 			 * ad_sd_calibrate() call overwrites this via
 			 * ad_sigma_delta_set_channel() -> ad7124_set_channel()
-			 * ... -> ad7124_enable_channel().
+			 * -> ad7124_prepare_read().
 			 */
 			ret = ad_sd_read_reg(&st->sd, AD7124_GAIN(st->channels[i].cfg.cfg_slot), 3,
 					     &st->channels[i].cfg.calibration_gain);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] iio: adc: ad7124: remove unused `nr` field
  2025-09-17 20:39 [PATCH 0/2] iio: adc: ad7124: drop nr field David Lechner
  2025-09-17 20:39 ` [PATCH 1/2] iio: adc: ad7124: inline ad7124_enable_channel() David Lechner
@ 2025-09-17 20:39 ` David Lechner
  2025-09-18 10:25 ` [PATCH 0/2] iio: adc: ad7124: drop nr field Nuno Sá
  2 siblings, 0 replies; 5+ messages in thread
From: David Lechner @ 2025-09-17 20:39 UTC (permalink / raw)
  To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
	Andy Shevchenko
  Cc: linux-iio, linux-kernel, David Lechner

Remove the unused `nr` field from the `ad7124_channel` struct. There
are no more users of this field (it is only assigned to but never read)
so can be removed.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/adc/ad7124.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index c61a95c5881a69e38c21ce4c340a0a61864de22b..1d93ab500a7b80bdcf18db645c3afdaea999cf48 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -199,7 +199,6 @@ struct ad7124_channel_config {
 };
 
 struct ad7124_channel {
-	unsigned int nr;
 	struct ad7124_channel_config cfg;
 	unsigned int ain;
 	unsigned int slot;
@@ -1301,7 +1300,6 @@ static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
 			return dev_err_probe(dev, -EINVAL,
 					     "diff-channels property of %pfwP contains invalid data\n", child);
 
-		st->channels[channel].nr = channel;
 		st->channels[channel].ain = FIELD_PREP(AD7124_CHANNEL_AINP, ain[0]) |
 			FIELD_PREP(AD7124_CHANNEL_AINM, ain[1]);
 
@@ -1328,7 +1326,6 @@ static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
 
 	if (num_channels < AD7124_MAX_CHANNELS) {
 		st->channels[num_channels] = (struct ad7124_channel) {
-			.nr = num_channels,
 			.ain = FIELD_PREP(AD7124_CHANNEL_AINP, AD7124_CHANNEL_AINx_TEMPSENSOR) |
 				FIELD_PREP(AD7124_CHANNEL_AINM, AD7124_CHANNEL_AINx_AVSS),
 			.cfg = {

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] iio: adc: ad7124: drop nr field
  2025-09-17 20:39 [PATCH 0/2] iio: adc: ad7124: drop nr field David Lechner
  2025-09-17 20:39 ` [PATCH 1/2] iio: adc: ad7124: inline ad7124_enable_channel() David Lechner
  2025-09-17 20:39 ` [PATCH 2/2] iio: adc: ad7124: remove unused `nr` field David Lechner
@ 2025-09-18 10:25 ` Nuno Sá
  2025-09-20 11:04   ` Jonathan Cameron
  2 siblings, 1 reply; 5+ messages in thread
From: Nuno Sá @ 2025-09-18 10:25 UTC (permalink / raw)
  To: David Lechner, Michael Hennerich, Jonathan Cameron, Nuno Sá,
	Andy Shevchenko
  Cc: linux-iio, linux-kernel

On Wed, 2025-09-17 at 15:39 -0500, David Lechner wrote:
> The motivation behind this series was to remove the `nr` field in struct
> ad7124_channel since it is duplicating the same value as struct
> iio_chan_spec.address (and duplicated again by .scan_index).
> 
> When it came to actually doing that though, I found that it was easier
> to first clean things up by removing the ad7124_enable_channel()
> function - which is a nice cleanup by itself. So ended up with 2 patches
> that end with the same result without ever mentioning the duplication.
> 
> ---
> David Lechner (2):
>       iio: adc: ad7124: inline ad7124_enable_channel()
>       iio: adc: ad7124: remove unused `nr` field
> 
>  drivers/iio/adc/ad7124.c | 19 ++++++-------------
>  1 file changed, 6 insertions(+), 13 deletions(-)
> ---
> base-commit: 561285d048053fec8a3d6d1e3ddc60df11c393a0
> change-id: 20250917-iio-adc-ad7124-drop-nr-field-518102218a61
> 
> Best regards,

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] iio: adc: ad7124: drop nr field
  2025-09-18 10:25 ` [PATCH 0/2] iio: adc: ad7124: drop nr field Nuno Sá
@ 2025-09-20 11:04   ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2025-09-20 11:04 UTC (permalink / raw)
  To: Nuno Sá
  Cc: David Lechner, Michael Hennerich, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On Thu, 18 Sep 2025 11:25:27 +0100
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Wed, 2025-09-17 at 15:39 -0500, David Lechner wrote:
> > The motivation behind this series was to remove the `nr` field in struct
> > ad7124_channel since it is duplicating the same value as struct
> > iio_chan_spec.address (and duplicated again by .scan_index).
> > 
> > When it came to actually doing that though, I found that it was easier
> > to first clean things up by removing the ad7124_enable_channel()
> > function - which is a nice cleanup by itself. So ended up with 2 patches
> > that end with the same result without ever mentioning the duplication.
> > 
> > ---
> > David Lechner (2):
> >       iio: adc: ad7124: inline ad7124_enable_channel()
> >       iio: adc: ad7124: remove unused `nr` field
> > 
> >  drivers/iio/adc/ad7124.c | 19 ++++++-------------
> >  1 file changed, 6 insertions(+), 13 deletions(-)
> > ---
> > base-commit: 561285d048053fec8a3d6d1e3ddc60df11c393a0
> > change-id: 20250917-iio-adc-ad7124-drop-nr-field-518102218a61
> > 
> > Best regards,  
> 
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>

Applied to iio.git/testing

Thanks

J

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-20 11:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-17 20:39 [PATCH 0/2] iio: adc: ad7124: drop nr field David Lechner
2025-09-17 20:39 ` [PATCH 1/2] iio: adc: ad7124: inline ad7124_enable_channel() David Lechner
2025-09-17 20:39 ` [PATCH 2/2] iio: adc: ad7124: remove unused `nr` field David Lechner
2025-09-18 10:25 ` [PATCH 0/2] iio: adc: ad7124: drop nr field Nuno Sá
2025-09-20 11:04   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox