mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Hungyu Lin <dennylin0707@gmail.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/2] iio: magnetometer: bmc150: use FIELD_PREP and FIELD_GET helpers
Date: Wed, 10 Jun 2026 16:32:30 +0100	[thread overview]
Message-ID: <20260610163230.51d5866c@jic23-huawei> (raw)
In-Reply-To: <20260610135831.91739-3-dennylin0707@gmail.com>

On Wed, 10 Jun 2026 13:58:31 +0000
Hungyu Lin <dennylin0707@gmail.com> wrote:

> Replace open-coded bitfield operations with FIELD_PREP() and
> FIELD_GET() helpers where appropriate.
> 
> Also simplify bmc150_magn_set_odr() by returning directly from
> the matching table entry.
> 
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
Andy mentioned in previous patch - slow down!  More than one version a day
is very rarely appropriate.  That creates a lot of noise on the list
and means that you aren't gathering up multiple bits of feedback before
posting a new verison.

Anything I apply for IIO is now 7.3 material so this isn't going upstream
for about 3 months anyway so take your time!

The alignment is not the preferred amount for pretty much all cases.
Rather than go to v7, applied but with this fix up:
Note that it is on the testing branch of iio.git which will get rebased
on rc1 once available in about 3 weeks time.

diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
index ee8092d4006c..32dff9cdd0f7 100644
--- a/drivers/iio/magnetometer/bmc150_magn.c
+++ b/drivers/iio/magnetometer/bmc150_magn.c
@@ -248,13 +248,13 @@ static int bmc150_magn_set_power_mode(struct bmc150_magn_data *data,
                                          BMC150_MAGN_REG_OPMODE_ODR,
                                          BMC150_MAGN_MASK_OPMODE,
                                          FIELD_PREP(BMC150_MAGN_MASK_OPMODE,
-                                                 BMC150_MAGN_MODE_SLEEP));
+                                                    BMC150_MAGN_MODE_SLEEP));
        case BMC150_MAGN_POWER_MODE_NORMAL:
                return regmap_update_bits(data->regmap,
                                          BMC150_MAGN_REG_OPMODE_ODR,
                                          BMC150_MAGN_MASK_OPMODE,
                                          FIELD_PREP(BMC150_MAGN_MASK_OPMODE,
-                                                 BMC150_MAGN_MODE_NORMAL));
+                                                    BMC150_MAGN_MODE_NORMAL));
        }
 
        return -EINVAL;
@@ -312,10 +312,10 @@ static int bmc150_magn_set_odr(struct bmc150_magn_data *data, int val)
                        continue;
 
                return regmap_update_bits(data->regmap,
-                                        BMC150_MAGN_REG_OPMODE_ODR,
-                                        BMC150_MAGN_MASK_ODR,
-                                        FIELD_PREP(BMC150_MAGN_MASK_ODR,
-                                                bmc150_magn_samp_freq_table[i].reg_val));
+                                         BMC150_MAGN_REG_OPMODE_ODR,
+                                         BMC150_MAGN_MASK_ODR,
+                                         FIELD_PREP(BMC150_MAGN_MASK_ODR,
+                                                    bmc150_magn_samp_freq_table[i].reg_val));
        }
 
> ---
>  drivers/iio/magnetometer/bmc150_magn.c | 33 ++++++++++++--------------
>  1 file changed, 15 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
> index f6639d7fab04..ee8092d4006c 100644
> --- a/drivers/iio/magnetometer/bmc150_magn.c
> +++ b/drivers/iio/magnetometer/bmc150_magn.c
> @@ -9,6 +9,7 @@
>   * (C) Copyright 2011~2014 Bosch Sensortec GmbH All Rights Reserved
>   */
>  
> +#include <linux/bitfield.h>
>  #include <linux/cleanup.h>
>  #include <linux/delay.h>
>  #include <linux/i2c.h>
> @@ -246,14 +247,14 @@ static int bmc150_magn_set_power_mode(struct bmc150_magn_data *data,
>  		return regmap_update_bits(data->regmap,
>  					  BMC150_MAGN_REG_OPMODE_ODR,
>  					  BMC150_MAGN_MASK_OPMODE,
> -					  BMC150_MAGN_MODE_SLEEP <<
> -					  BMC150_MAGN_SHIFT_OPMODE);
> +					  FIELD_PREP(BMC150_MAGN_MASK_OPMODE,
> +						  BMC150_MAGN_MODE_SLEEP));
Should be aligned as:
					  FIELD_PREP(BMC150_MAGN_MASK_OPMODE,
						     BMC150_MAGN_MODE_SLEEP));

>  	case BMC150_MAGN_POWER_MODE_NORMAL:
>  		return regmap_update_bits(data->regmap,
>  					  BMC150_MAGN_REG_OPMODE_ODR,
>  					  BMC150_MAGN_MASK_OPMODE,
> -					  BMC150_MAGN_MODE_NORMAL <<
> -					  BMC150_MAGN_SHIFT_OPMODE);
> +					  FIELD_PREP(BMC150_MAGN_MASK_OPMODE,
> +						  BMC150_MAGN_MODE_NORMAL));
Same here.

>  	}
>  
>  	return -EINVAL;
> @@ -291,7 +292,7 @@ static int bmc150_magn_get_odr(struct bmc150_magn_data *data, int *val)
>  	ret = regmap_read(data->regmap, BMC150_MAGN_REG_OPMODE_ODR, &reg_val);
>  	if (ret < 0)
>  		return ret;
> -	odr_val = (reg_val & BMC150_MAGN_MASK_ODR) >> BMC150_MAGN_SHIFT_ODR;
> +	odr_val = FIELD_GET(BMC150_MAGN_MASK_ODR, reg_val);
>  
>  	for (i = 0; i < ARRAY_SIZE(bmc150_magn_samp_freq_table); i++)
>  		if (bmc150_magn_samp_freq_table[i].reg_val == odr_val) {
> @@ -304,21 +305,17 @@ static int bmc150_magn_get_odr(struct bmc150_magn_data *data, int *val)
>  
>  static int bmc150_magn_set_odr(struct bmc150_magn_data *data, int val)
>  {
> -	int ret;
>  	u8 i;
>  
>  	for (i = 0; i < ARRAY_SIZE(bmc150_magn_samp_freq_table); i++) {
> -		if (bmc150_magn_samp_freq_table[i].freq == val) {
> -			ret = regmap_update_bits(data->regmap,
> -						 BMC150_MAGN_REG_OPMODE_ODR,
> -						 BMC150_MAGN_MASK_ODR,
> -						 bmc150_magn_samp_freq_table[i].
> -						 reg_val <<
> -						 BMC150_MAGN_SHIFT_ODR);
> -			if (ret < 0)
> -				return ret;
> -			return 0;
> -		}
> +		if (bmc150_magn_samp_freq_table[i].freq != val)
> +			continue;
> +
> +		return regmap_update_bits(data->regmap,
> +					 BMC150_MAGN_REG_OPMODE_ODR,
> +					 BMC150_MAGN_MASK_ODR,
> +					 FIELD_PREP(BMC150_MAGN_MASK_ODR,
> +						 bmc150_magn_samp_freq_table[i].reg_val));
and here should be
		return regmap_update_bits(data->regmap,
					  BMC150_MAGN_REG_OPMODE_ODR,
					  BMC150_MAGN_MASK_ODR,
					  FIELD_PREP(BMC150_MAGN_MASK_ODR,
						     bmc150_magn_samp_freq_table[i].reg_val));

>  	}
>  
>  	return -EINVAL;
> @@ -801,7 +798,7 @@ static int bmc150_magn_data_rdy_trigger_set_state(struct iio_trigger *trig,
>  
>  	ret = regmap_update_bits(data->regmap, BMC150_MAGN_REG_INT_DRDY,
>  				 BMC150_MAGN_MASK_DRDY_EN,
> -				 state << BMC150_MAGN_SHIFT_DRDY_EN);
> +				 FIELD_PREP(BMC150_MAGN_MASK_DRDY_EN, state));
>  	if (ret < 0)
>  		return ret;
>  


  reply	other threads:[~2026-06-10 15:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10 13:58 [PATCH v6 0/2] " Hungyu Lin
2026-06-10 13:58 ` [PATCH v6 1/2] iio: magnetometer: bmc150: sort includes Hungyu Lin
2026-06-10 13:58 ` [PATCH v6 2/2] iio: magnetometer: bmc150: use FIELD_PREP and FIELD_GET helpers Hungyu Lin
2026-06-10 15:32   ` Jonathan Cameron [this message]
2026-06-10 17:28     ` Hungyu Lin
2026-06-10 14:10 ` [PATCH v6 0/2] " 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=20260610163230.51d5866c@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dennylin0707@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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

all inboxes | Powered by JetHome®