From: Jonathan Cameron <jic23@kernel.org>
To: Akshay Jindal <akshayaj.lkd@gmail.com>
Cc: dan@dlrobertson.com, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, shuah@kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/5] iio: accel: bma400: Reorganize and rename register and field macros
Date: Sat, 4 Oct 2025 13:53:12 +0100 [thread overview]
Message-ID: <20251004135312.41858380@jic23-huawei> (raw)
In-Reply-To: <20251002184120.495193-2-akshayaj.lkd@gmail.com>
On Fri, 3 Oct 2025 00:11:02 +0530
Akshay Jindal <akshayaj.lkd@gmail.com> wrote:
> Reorganize register and field macros to improve consistency with the
> datasheet and naming style:
>
> - Move field macros next to their corresponding register macros
> - Reorder register macros to follow address order from the datasheet
> - Rename field macros to include the register name in the macro name
> - Add a _REG suffix to register macros where missing
>
> No functional changes are intended.
>
> Signed-off-by: Akshay Jindal <akshayaj.lkd@gmail.com>
This is much easier to review. Thanks for breaking it all up.
> ---
> drivers/iio/accel/bma400.h | 110 +++++++++--------
> drivers/iio/accel/bma400_core.c | 212 ++++++++++++++++----------------
> 2 files changed, 163 insertions(+), 159 deletions(-)
>
> diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h
> index 932358b45f17..ae3411c090c9 100644
> --- a/drivers/iio/accel/bma400.h
> +++ b/drivers/iio/accel/bma400.h
> @@ -16,31 +16,37 @@
> /* Event and interrupt registers */
> #define BMA400_EVENT_REG 0x0d
> +
> #define BMA400_INT_STAT0_REG 0x0e
> #define BMA400_INT_STAT1_REG 0x0f
> #define BMA400_INT_STAT2_REG 0x10
> -#define BMA400_INT12_MAP_REG 0x23
> -#define BMA400_INT_ENG_OVRUN_MSK BIT(4)
> +#define BMA400_ENG_OVRUN_INT_STAT_MASK BIT(4)
This is an odd field as it applies to all the INT_STATX registers
However I would still try to make that connection with a name
such as BMA500_INT_STAT_OVRUN_MASK
> +#define BMA400_STEP_INT_STAT_MASK GENMASK(9, 8)
This bit is a little odd. We are treating INT_STAT0 and INT_STAT1
(but not 2) as a single 16 bit register. That makes it hard to
associate the field with the register name. I wonder if we shouldn't
break that and just handle it as a pair of u8 instead.
> +#define BMA400_S_TAP_INT_STAT_MASK BIT(10)
> +#define BMA400_D_TAP_INT_STAT_MASK BIT(11)
>
> /* Temperature register */
> #define BMA400_TEMP_DATA_REG 0x11
> @@ -55,70 +61,68 @@
> #define BMA400_STEP_CNT1_REG 0x16
> #define BMA400_STEP_CNT3_REG 0x17
> #define BMA400_STEP_STAT_REG 0x18
> -#define BMA400_STEP_INT_MSK BIT(0)
> #define BMA400_STEP_RAW_LEN 0x03
> -#define BMA400_STEP_STAT_MASK GENMASK(9, 8)
>
> /*
> * Read-write configuration registers
> */
> -#define BMA400_ACC_CONFIG0_REG 0x19
> -#define BMA400_ACC_CONFIG1_REG 0x1a
> +#define BMA400_ACC_CONFIG0_REG 0x19
> +#define BMA400_ACC_CONFIG0_LP_OSR_MASK GENMASK(6, 5)
> +#define BMA400_LP_OSR_SHIFT 5
#
Should never need a explicit shift. Use FIELD_PREP() and FIELD_GET() to
allow the MASK to be used in all cases.
> +
> +#define BMA400_ACC_CONFIG1_REG 0x1a
> +#define BMA400_ACC_CONFIG1_ODR_MASK GENMASK(3, 0)
> +#define BMA400_ACC_CONFIG1_ODR_MIN_RAW 0x05
> +#define BMA400_ACC_CONFIG1_ODR_LP_RAW 0x06
> +#define BMA400_ACC_CONFIG1_ODR_MAX_RAW 0x0b
> +#define BMA400_ACC_CONFIG1_ODR_MAX_HZ 800
> +#define BMA400_ACC_CONFIG1_ODR_MIN_WHOLE_HZ 25
> +#define BMA400_ACC_CONFIG1_ODR_MIN_HZ 12
> +#define BMA400_ACC_CONFIG1_NP_OSR_MASK GENMASK(5, 4)
> +#define BMA400_NP_OSR_SHIFT 4
Similarly on this shift.
> +#define BMA400_ACC_CONFIG1_ACC_RANGE_MASK GENMASK(7, 6)
> +#define BMA400_ACC_RANGE_SHIFT 6
and this one. Might be a good idea to switch away from using the shifts
as a precursor patch as it's really a different sort of change from
the rest of this.
> +
> #define BMA400_ACC_CONFIG2_REG 0x1b
> -#define BMA400_CMD_REG 0x7e
>
...
> - osr = (val & BMA400_LP_OSR_MASK) >> BMA400_LP_OSR_SHIFT;
> + osr = (val & BMA400_ACC_CONFIG0_LP_OSR_MASK) >> BMA400_LP_OSR_SHIFT;
Here is one of those cases with the shift that could just be
osr = FIELD_GET(BMA400_ACC_CONFIG0_LP_OSR_MASK, val);
>
> data->oversampling_ratio = osr;
> return 0;
> @@ -603,7 +603,7 @@ static int bma400_get_accel_oversampling_ratio(struct bma400_data *data)
> return ret;
> }
>
> - osr = (val & BMA400_NP_OSR_MASK) >> BMA400_NP_OSR_SHIFT;
> + osr = (val & BMA400_ACC_CONFIG1_NP_OSR_MASK) >> BMA400_NP_OSR_SHIFT;
her as well.
>
> data->oversampling_ratio = osr;
> return 0;
> @@ -637,7 +637,7 @@ static int bma400_set_accel_oversampling_ratio(struct bma400_data *data,
> return ret;
>
> ret = regmap_write(data->regmap, BMA400_ACC_CONFIG0_REG,
> - (acc_config & ~BMA400_LP_OSR_MASK) |
> + (acc_config & ~BMA400_ACC_CONFIG0_LP_OSR_MASK) |
> (val << BMA400_LP_OSR_SHIFT));
FIELD_PREP for this one.
> if (ret) {
> dev_err(data->dev, "Failed to write out OSR\n");
> @@ -653,7 +653,7 @@ static int bma400_set_accel_oversampling_ratio(struct bma400_data *data,
> return ret;
>
> ret = regmap_write(data->regmap, BMA400_ACC_CONFIG1_REG,
> - (acc_config & ~BMA400_NP_OSR_MASK) |
> + (acc_config & ~BMA400_ACC_CONFIG1_NP_OSR_MASK) |
> (val << BMA400_NP_OSR_SHIFT));
here as well. Anyhow, from a quick look it appears that getting rid of the _SHIFT defines
should be easy.
> if (ret) {
> dev_err(data->dev, "Failed to write out OSR\n");
>
>
> @@ -786,8 +786,8 @@ static int bma400_enable_steps(struct bma400_data *data, int val)
> return 0;
>
> ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG1_REG,
> - BMA400_STEP_INT_MSK,
> - FIELD_PREP(BMA400_STEP_INT_MSK, val ? 1 : 0));
> + BMA400_INT_CONFIG1_STEP_INT_MASK,
> + FIELD_PREP(BMA400_INT_CONFIG1_STEP_INT_MASK, val ? 1 : 0));
Could use regmap_assign_bits() to simplify this a bit - but separate change
so different patch.
> if (ret)
> return ret;
next prev parent reply other threads:[~2025-10-04 12:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-02 18:41 [PATCH v3 0/5] iio: accel: bma400: Refactor GENINTR config and register macros Akshay Jindal
2025-10-02 18:41 ` [PATCH v3 1/5] iio: accel: bma400: Reorganize and rename register and field macros Akshay Jindal
2025-10-04 12:53 ` Jonathan Cameron [this message]
2025-10-07 6:39 ` Akshay Jindal
2025-10-12 14:02 ` Jonathan Cameron
2025-10-02 18:41 ` [PATCH v3 2/5] iio: accel: bma400: Use macros for generic event configuration values Akshay Jindal
2025-10-04 12:58 ` Jonathan Cameron
2025-10-07 6:46 ` Akshay Jindal
2025-10-12 14:04 ` Jonathan Cameron
2025-10-02 18:41 ` [PATCH v3 3/5] iio: accel: bma400: Use index-based register addressing and lookup Akshay Jindal
2025-10-04 13:08 ` Jonathan Cameron
2025-10-07 6:45 ` Akshay Jindal
2025-10-02 18:41 ` [PATCH v3 4/5] iio: accel: bma400: Rename activity_event_en() to generic_event_en() Akshay Jindal
2025-10-02 18:41 ` [PATCH v3 5/5] iio: accel: bma400: Add detail to comments in GEN INTR configuration Akshay Jindal
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=20251004135312.41858380@jic23-huawei \
--to=jic23@kernel.org \
--cc=akshayaj.lkd@gmail.com \
--cc=andy@kernel.org \
--cc=dan@dlrobertson.com \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=shuah@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