iio: accel: bma400: Refactor GENINTR config and register macros
Subsystems (2)
v5 cover iio: accel: bma400: Refactor GENINTR config and register macros
This series refactors the BMA400 driver with a focus on generic interrupt configuration and related register usage. The main changes reduce usage of hard-coded values by introducing macros and formula-based register addressing, and add a centralized lookup indexed on iio event direction.
Alongside these updates, the series also reorganizes and renames register and field macros for consistency with the datasheet, and extends comments for additional clarity.
All patches are pure refactoring. No functional changes are intended.
Akshay Jindal (6):
iio: accel: bma400: Reorganize and rename register and field macros
iio: accel: bma400: Use macros for generic event configuration values
iio: accel: bma400: Use index-based register addressing and lookup
iio: accel: bma400: Replace bit shifts with FIELD_PREP() and FIELD_GET()
iio: accel: bma400: Rename activity_event_en() to generic_event_en()
iio: accel: bma400: Add detail to comments in GEN INTR configuration
Changes since v4:
- Add INT_STATx field macros corresponding to used INT_CONFIGx fields.
- Make INT_STATx field macro names consistent with others.
- Tied the INT_STATx field to correct INT_STAT register.
- Modified changelog of PATCH 1/6 due to addition of INT_STATx fields.
- Modified changelog of PATCH 4/6.
Changes since v3:
- Insert a new patch into the patch series for replacing explicit bit shifts with FIELD_GET and FIELD_PREP macros
- Assigned explicit values to reg field enums introduced.
Changes since v2:
- Split single patch into five smaller patches as suggested
- Addressed review comments related to trailing comma [Patch 2/5]
- Extended renaming of macros to TAP_CONFIG registers [Patch 1/5]
- Addressed review comment received regarding write then replace in activity_event_en() [Patch 3/5]
Testing Summary:
- Tested on raspberrypi 4b and 7-semi bma400 sensor breakout board.
- Since no functional impact is there, so before functionality is expected to be equal to after change functionality.
- Tested mapping of GEN1 and GEN2 both on INT1 pin as before.
- Tested both activity and inactivity detection by setting attributes events/in_accel_mag_falling_en as well as events/in_accel_mag_rising_en.
- Did read and writes on various attributes such that write_event_config(), write_event_value() and read_event_value() callbacks are triggered.
drivers/iio/accel/bma400.h | 155 +++++++++----- drivers/iio/accel/bma400_core.c | 349 ++++++++++++++++++-------------- 2 files changed, 292 insertions(+), 212 deletions(-)
Signature · 1 line
2.43.0
PATCH v5 1/6 iio: accel: bma400: Reorganize and rename register and field macros
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
- Add INT_STAT register fields corresponding to used INT_CONFIG fields
No functional changes are intended.
---
Changes since v4:
- Add INT_STATx field macros corresponding to used INT_CONFIGx fields.
- Make INT_STATx field macro names consistent with the overall convention used.
- Tied the INT_STATx field to correct INT_STAT register.
- Modified changelog of PATCH 1/6 due to addition of INT_STATx fields.
drivers/iio/accel/bma400.h | 117 ++++++++++-------- drivers/iio/accel/bma400_core.c | 212 ++++++++++++++++---------------- 2 files changed, 170 insertions(+), 159 deletions(-)
drivers/iio/accel/bma400.h +64 -53
@@ -16,31 +16,44 @@* Read-Only Registers */ +/* Chip ID of BMA 400 devices found in the chip ID register. */ +#define BMA400_ID_REG_VAL 0x90 +/* Status and ID registers */ #define BMA400_CHIP_ID_REG 0x00#define BMA400_ERR_REG 0x02#define BMA400_STATUS_REG 0x03/* Acceleration registers */ -#define BMA400_X_AXIS_LSB_REG 0x04 -#define BMA400_X_AXIS_MSB_REG 0x05 -#define BMA400_Y_AXIS_LSB_REG 0x06 -#define BMA400_Y_AXIS_MSB_REG 0x07 -#define BMA400_Z_AXIS_LSB_REG 0x08 -#define BMA400_Z_AXIS_MSB_REG 0x09 +#define BMA400_ACC_X_LSB_REG 0x04 +#define BMA400_ACC_X_MSB_REG 0x05 +#define BMA400_ACC_Y_LSB_REG 0x06 +#define BMA400_ACC_Y_MSB_REG 0x07 +#define BMA400_ACC_Z_LSB_REG 0x08 +#define BMA400_ACC_Z_MSB_REG 0x09/* Sensor time registers */ -#define BMA400_SENSOR_TIME0 0x0a -#define BMA400_SENSOR_TIME1 0x0b -#define BMA400_SENSOR_TIME2 0x0c +#define BMA400_SENSOR_TIME0_REG 0x0a +#define BMA400_SENSOR_TIME1_REG 0x0b +#define BMA400_SENSOR_TIME2_REG 0x0c/* Event and interrupt registers */ #define BMA400_EVENT_REG 0x0d +#define BMA400_INT_STAT0_REG 0x0e +#define BMA400_INT_STAT0_GEN1_MASK BIT(2) +#define BMA400_INT_STAT0_GEN2_MASK BIT(3) +#define BMA400_INT_STAT0_DRDY_MASK BIT(7) +#define BMA400_INT_STAT1_REG 0x0f +#define BMA400_INT_STAT1_STEP_INT_MASK GENMASK(9, 8) +#define BMA400_INT_STAT1_S_TAP_MASK BIT(10) +#define BMA400_INT_STAT1_D_TAP_MASK BIT(11) +#define BMA400_INT_STAT2_REG 0x10 -#define BMA400_INT12_MAP_REG 0x23 -#define BMA400_INT_ENG_OVRUN_MSK BIT(4) + +/* Bit present in all INT_STAT registers */ +#define BMA400_INT_STAT_ENG_OVRRUN_MASK BIT(4)/* Temperature register */ #define BMA400_TEMP_DATA_REG 0x11
@@ -55,70 +68,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 + +#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 +#define BMA400_ACC_CONFIG1_ACC_RANGE_MASK GENMASK(7, 6) +#define BMA400_ACC_RANGE_SHIFT 6 +#define BMA400_ACC_CONFIG2_REG 0x1b -#define BMA400_CMD_REG 0x7e/* Interrupt registers */ #define BMA400_INT_CONFIG0_REG 0x1f +#define BMA400_INT_CONFIG0_GEN1_MASK BIT(2) +#define BMA400_INT_CONFIG0_GEN2_MASK BIT(3) +#define BMA400_INT_CONFIG0_DRDY_MASK BIT(7) +#define BMA400_INT_CONFIG1_REG 0x20 +#define BMA400_INT_CONFIG1_STEP_INT_MASK BIT(0) +#define BMA400_INT_CONFIG1_S_TAP_MASK BIT(2) +#define BMA400_INT_CONFIG1_D_TAP_MASK BIT(3) +#define BMA400_INT1_MAP_REG 0x21 +#define BMA400_INT12_MAP_REG 0x23#define BMA400_INT_IO_CTRL_REG 0x24 -#define BMA400_INT_DRDY_MSK BIT(7) - -/* Chip ID of BMA 400 devices found in the chip ID register. */ -#define BMA400_ID_REG_VAL 0x90 - -#define BMA400_LP_OSR_SHIFT 5 -#define BMA400_NP_OSR_SHIFT 4 -#define BMA400_SCALE_SHIFT 6#define BMA400_TWO_BITS_MASK GENMASK(1, 0) -#define BMA400_LP_OSR_MASK GENMASK(6, 5) -#define BMA400_NP_OSR_MASK GENMASK(5, 4) -#define BMA400_ACC_ODR_MASK GENMASK(3, 0) -#define BMA400_ACC_SCALE_MASK GENMASK(7, 6) - -#define BMA400_ACC_ODR_MIN_RAW 0x05 -#define BMA400_ACC_ODR_LP_RAW 0x06 -#define BMA400_ACC_ODR_MAX_RAW 0x0b - -#define BMA400_ACC_ODR_MAX_HZ 800 -#define BMA400_ACC_ODR_MIN_WHOLE_HZ 25 -#define BMA400_ACC_ODR_MIN_HZ 12/* Generic interrupts register */ -#define BMA400_GEN1INT_CONFIG0 0x3f -#define BMA400_GEN2INT_CONFIG0 0x4A +#define BMA400_GEN1INT_CONFIG0_REG 0x3f +#define BMA400_GEN2INT_CONFIG0_REG 0x4A +#define BMA400_GENINT_CONFIG0_HYST_MASK GENMASK(1, 0) +#define BMA400_GEN_CONFIG1_OFF 0x01#define BMA400_GEN_CONFIG2_OFF 0x02#define BMA400_GEN_CONFIG3_OFF 0x03#define BMA400_GEN_CONFIG31_OFF 0x04 -#define BMA400_INT_GEN1_MSK BIT(2) -#define BMA400_INT_GEN2_MSK BIT(3) -#define BMA400_GEN_HYST_MSK GENMASK(1, 0)/* TAP config registers */ -#define BMA400_TAP_CONFIG 0x57 -#define BMA400_TAP_CONFIG1 0x58 -#define BMA400_S_TAP_MSK BIT(2) -#define BMA400_D_TAP_MSK BIT(3) -#define BMA400_INT_S_TAP_MSK BIT(10) -#define BMA400_INT_D_TAP_MSK BIT(11) -#define BMA400_TAP_SEN_MSK GENMASK(2, 0) -#define BMA400_TAP_TICSTH_MSK GENMASK(1, 0) -#define BMA400_TAP_QUIET_MSK GENMASK(3, 2) -#define BMA400_TAP_QUIETDT_MSK GENMASK(5, 4) +#define BMA400_TAP_CONFIG_REG 0x57 +#define BMA400_TAP_CONFIG_SEN_MASK GENMASK(2, 0) + +#define BMA400_TAP_CONFIG1_REG 0x58 +#define BMA400_TAP_CONFIG1_TICSTH_MASK GENMASK(1, 0) +#define BMA400_TAP_CONFIG1_QUIET_MASK GENMASK(3, 2) +#define BMA400_TAP_CONFIG1_QUIETDT_MASK GENMASK(5, 4)#define BMA400_TAP_TIM_LIST_LEN 4 +#define BMA400_CMD_REG 0x7e/* * BMA400_SCALE_MIN macro value represents m/s^2 for 1 LSB before * converting to micro values for +-2g range.
@@ -138,8 +149,8 @@* To select +-8g = 9577 << 2 = raw value to write is 2. * To select +-16g = 9577 << 3 = raw value to write is 3. */ -#define BMA400_SCALE_MIN 9577 -#define BMA400_SCALE_MAX 76617 +#define BMA400_ACC_SCALE_MIN 9577 +#define BMA400_ACC_SCALE_MAX 76617extern const struct regmap_config bma400_regmap_config;
drivers/iio/accel/bma400_core.c +106 -106
504 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v5 2/6 iio: accel: bma400: Use macros for generic event configuration values
In reply to Akshay JindalAdd macros and enums for configuration values used in generic event handling for activity and inactivity detection. Replace hard-coded values in activity_event_en() with the new definitions to make the configuration explicit.
No functional changes are intended.
---
Changes since v3:
- Assigned explicit values to reg field enums introduced.
drivers/iio/accel/bma400.h | 30 ++++++++++++++++++++++++++++++ drivers/iio/accel/bma400_core.c | 14 +++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-)
drivers/iio/accel/bma400.h +30 -0
@@ -113,8 +113,38 @@#define BMA400_GEN1INT_CONFIG0_REG 0x3f#define BMA400_GEN2INT_CONFIG0_REG 0x4A#define BMA400_GENINT_CONFIG0_HYST_MASK GENMASK(1, 0) +#define BMA400_GENINT_CONFIG0_REF_UPD_MODE_MASK GENMASK(3, 2) +#define BMA400_GENINT_CONFIG0_DATA_SRC_MASK BIT(4) +#define BMA400_GENINT_CONFIG0_X_EN_MASK BIT(5) +#define BMA400_GENINT_CONFIG0_Y_EN_MASK BIT(6) +#define BMA400_GENINT_CONFIG0_Z_EN_MASK BIT(7) + +enum bma400_accel_data_src { +ACCEL_FILT1 =0x0 , +ACCEL_FILT2 =0x1 , +}; + +enum bma400_ref_updt_mode { +BMA400_REF_MANUAL_UPDT_MODE =0x0 , +BMA400_REF_ONETIME_UPDT_MODE =0x1 , +BMA400_REF_EVERYTIME_UPDT_MODE =0x2 , +BMA400_REF_EVERYTIME_LP_UPDT_MODE =0x3 , +};#define BMA400_GEN_CONFIG1_OFF 0x01 +#define BMA400_GENINT_CONFIG1_AXES_COMB_MASK BIT(0) +#define BMA400_GENINT_CONFIG1_DETCT_CRIT_MASK BIT(1) + +enum bma400_genintr_acceleval_axescomb { +BMA400_EVAL_X_OR_Y_OR_Z =0x0 , +BMA400_EVAL_X_AND_Y_AND_Z =0x1 , +}; + +enum bma400_detect_criterion { +BMA400_DETECT_INACTIVITY =0x0 , +BMA400_DETECT_ACTIVITY =0x1 , +}; +#define BMA400_GEN_CONFIG2_OFF 0x02#define BMA400_GEN_CONFIG3_OFF 0x03#define BMA400_GEN_CONFIG31_OFF 0x04
drivers/iio/accel/bma400_core.c +11 -3
@@ -1166,14 +1166,16 @@ static int bma400_activity_event_en(struct bma400_data *data,case IIO_EV_DIR_RISING : reg =BMA400_GEN1INT_CONFIG0_REG ; msk =BMA400_INT_CONFIG0_GEN1_MASK ; - value =2 ; + value =FIELD_PREP (BMA400_GENINT_CONFIG1_AXES_COMB_MASK ,BMA400_EVAL_X_OR_Y_OR_Z ) | +FIELD_PREP (BMA400_GENINT_CONFIG1_DETCT_CRIT_MASK ,BMA400_DETECT_ACTIVITY );set_mask_bits (&field_value,BMA400_INT_CONFIG0_GEN1_MASK ,FIELD_PREP (BMA400_INT_CONFIG0_GEN1_MASK , state));break ;case IIO_EV_DIR_FALLING : reg =BMA400_GEN2INT_CONFIG0_REG ; msk =BMA400_INT_CONFIG0_GEN2_MASK ; - value =0 ; + value =FIELD_PREP (BMA400_GENINT_CONFIG1_AXES_COMB_MASK ,BMA400_EVAL_X_OR_Y_OR_Z ) | +FIELD_PREP (BMA400_GENINT_CONFIG1_DETCT_CRIT_MASK ,BMA400_DETECT_INACTIVITY );set_mask_bits (&field_value,BMA400_INT_CONFIG0_GEN2_MASK ,FIELD_PREP (BMA400_INT_CONFIG0_GEN2_MASK , state));break ;
@@ -1182,7 +1184,13 @@ static int bma400_activity_event_en(struct bma400_data *data, }/* Enabling all axis for interrupt evaluation */ - ret =regmap_write (data->regmap, reg,0xF8 ); + ret =regmap_write (data->regmap, reg, +BMA400_GENINT_CONFIG0_X_EN_MASK | +BMA400_GENINT_CONFIG0_Y_EN_MASK | +BMA400_GENINT_CONFIG0_Z_EN_MASK | +FIELD_PREP (BMA400_GENINT_CONFIG0_DATA_SRC_MASK ,ACCEL_FILT2 )| +FIELD_PREP (BMA400_GENINT_CONFIG0_REF_UPD_MODE_MASK , +BMA400_REF_EVERYTIME_UPDT_MODE ));if (ret)return ret;
Signature · 1 line
2.43.0
PATCH v5 3/6 iio: accel: bma400: Use index-based register addressing and lookup
In reply to Akshay JindalIntroduce formula-based macros to compute GEN INTR configuration register addresses from the interrupt number and register index. This reduces the need for 22 explicit register macros to three base definitions.
Add a centralized lookup table keyed by IIO event direction and replace get_gen_config_reg() with a helper integrated with this table.
Apply these changes across the affected callbacks to ensure consistent access to generic interrupt registers.
No functional changes are intended.
---
Changes since v3:
- Assigned explicit values to reg field enums introduced
drivers/iio/accel/bma400.h | 17 +++-- drivers/iio/accel/bma400_core.c | 131 +++++++++++++++++++------------- 2 files changed, 88 insertions(+), 60 deletions(-)
drivers/iio/accel/bma400.h +11 -6
@@ -98,6 +98,11 @@#define BMA400_INT_CONFIG0_GEN2_MASK BIT(3)#define BMA400_INT_CONFIG0_DRDY_MASK BIT(7) +enum bma400_generic_intr { +BMA400_GEN1_INTR =0x1 , +BMA400_GEN2_INTR =0x2 , +}; +#define BMA400_INT_CONFIG1_REG 0x20#define BMA400_INT_CONFIG1_STEP_INT_MASK BIT(0)#define BMA400_INT_CONFIG1_S_TAP_MASK BIT(2)
@@ -110,8 +115,12 @@#define BMA400_TWO_BITS_MASK GENMASK(1, 0)/* Generic interrupts register */ -#define BMA400_GEN1INT_CONFIG0_REG 0x3f -#define BMA400_GEN2INT_CONFIG0_REG 0x4A +#define BMA400_GENINT_CONFIG_REG_BASE 0x3f +#define BMA400_NUM_GENINT_CONFIG_REGS 11 +#define BMA400_GENINT_CONFIG_REG (gen_intr, config_idx) \ + (BMA400_GENINT_CONFIG_REG_BASE + \ + (gen_intr - 1) * BMA400_NUM_GENINT_CONFIG_REGS + \ + (config_idx))#define BMA400_GENINT_CONFIG0_HYST_MASK GENMASK(1, 0)#define BMA400_GENINT_CONFIG0_REF_UPD_MODE_MASK GENMASK(3, 2)#define BMA400_GENINT_CONFIG0_DATA_SRC_MASK BIT(4)
@@ -145,10 +154,6 @@ enum bma400_detect_criterion { BMA400_DETECT_ACTIVITY = 0x1, }; -#define BMA400_GEN_CONFIG2_OFF 0x02 -#define BMA400_GEN_CONFIG3_OFF 0x03 -#define BMA400_GEN_CONFIG31_OFF 0x04 -/* TAP config registers */ #define BMA400_TAP_CONFIG_REG 0x57#define BMA400_TAP_CONFIG_SEN_MASK GENMASK(2, 0)
drivers/iio/accel/bma400_core.c +77 -54
237 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v5 4/6 iio: accel: bma400: Replace bit shifts with FIELD_PREP() and FIELD_GET()
In reply to Akshay Jindalset_* functions involve left shift of param values into respective register fields before writing to register. Similarly get_* functions involve right shift to extract values from the respective bit fields. Replace these explicit shifting statements with standard kernel style macros FIELD_GET() and FIELD_PREP().
---
Changes since v4:
- Modified changelog of PATCH 4/6.
drivers/iio/accel/bma400.h | 3 --- drivers/iio/accel/bma400_core.c | 12 ++++++------ 2 files changed, 6 insertions(+), 9 deletions(-)
drivers/iio/accel/bma400.h +0 -3
@@ -75,7 +75,6 @@*/ #define BMA400_ACC_CONFIG0_REG 0x19#define BMA400_ACC_CONFIG0_LP_OSR_MASK GENMASK(6, 5) -#define BMA400_LP_OSR_SHIFT 5#define BMA400_ACC_CONFIG1_REG 0x1a#define BMA400_ACC_CONFIG1_ODR_MASK GENMASK(3, 0)
@@ -86,9 +85,7 @@#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#define BMA400_ACC_CONFIG1_ACC_RANGE_MASK GENMASK(7, 6) -#define BMA400_ACC_RANGE_SHIFT 6#define BMA400_ACC_CONFIG2_REG 0x1b
drivers/iio/accel/bma400_core.c +6 -6
@@ -627,7 +627,7 @@ static int bma400_get_accel_oversampling_ratio(struct bma400_data *data)return ret; } - osr = (val &BMA400_ACC_CONFIG0_LP_OSR_MASK ) >>BMA400_LP_OSR_SHIFT ; + osr =FIELD_GET (BMA400_ACC_CONFIG0_LP_OSR_MASK , val); data->oversampling_ratio = osr;return 0 ;
@@ -638,7 +638,7 @@ static int bma400_get_accel_oversampling_ratio(struct bma400_data *data)return ret; } - osr = (val &BMA400_ACC_CONFIG1_NP_OSR_MASK ) >>BMA400_NP_OSR_SHIFT ; + osr =FIELD_GET (BMA400_ACC_CONFIG1_NP_OSR_MASK , val); data->oversampling_ratio = osr;return 0 ;
@@ -673,7 +673,7 @@ static int bma400_set_accel_oversampling_ratio(struct bma400_data *data, ret =regmap_write (data->regmap,BMA400_ACC_CONFIG0_REG , (acc_config & ~BMA400_ACC_CONFIG0_LP_OSR_MASK ) | - (val <<BMA400_LP_OSR_SHIFT )); +FIELD_PREP (BMA400_ACC_CONFIG0_LP_OSR_MASK , val));if (ret) {dev_err (data->dev,"Failed to write out OSR\n" );return ret;
@@ -689,7 +689,7 @@ static int bma400_set_accel_oversampling_ratio(struct bma400_data *data, ret =regmap_write (data->regmap,BMA400_ACC_CONFIG1_REG , (acc_config & ~BMA400_ACC_CONFIG1_NP_OSR_MASK ) | - (val <<BMA400_NP_OSR_SHIFT )); +FIELD_PREP (BMA400_ACC_CONFIG1_NP_OSR_MASK , val));if (ret) {dev_err (data->dev,"Failed to write out OSR\n" );return ret;
@@ -730,7 +730,7 @@ static int bma400_get_accel_scale(struct bma400_data *data)if (ret)return ret; - raw_scale = (val &BMA400_ACC_CONFIG1_ACC_RANGE_MASK ) >>BMA400_ACC_RANGE_SHIFT ; + raw_scale =FIELD_GET (BMA400_ACC_CONFIG1_ACC_RANGE_MASK , val);if (raw_scale >BMA400_TWO_BITS_MASK )return -EINVAL ;
@@ -755,7 +755,7 @@ static int bma400_set_accel_scale(struct bma400_data *data, unsigned int val) ret =regmap_write (data->regmap,BMA400_ACC_CONFIG1_REG , (acc_config & ~BMA400_ACC_CONFIG1_ACC_RANGE_MASK ) | - (raw <<BMA400_ACC_RANGE_SHIFT )); +FIELD_PREP (BMA400_ACC_CONFIG1_ACC_RANGE_MASK , raw));if (ret)return ret;
Signature · 1 line
2.43.0
PATCH v5 5/6 iio: accel: bma400: Rename activity_event_en() to generic_event_en()
In reply to Akshay JindalThe function activity_event_en() configures the generic interrupts GEN1 and GEN2, which are used for activity and inactivity detection as per the datasheet. The existing name is misleading, since the device also provides activity change and activity recognition interrupts. Activity change interrupt is not supported yet whereas Activity recognition interrupt is configured in a different function.
Rename activity_event_en() to generic_event_en() to better reflect its actual purpose.
No functional changes intended.
--- drivers/iio/accel/bma400_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/accel/bma400_core.c +4 -4
@@ -1190,9 +1190,9 @@ static int bma400_steps_event_enable(struct bma400_data *data, int state)return 0 ; } -static int bma400_activity_event_en (struct bma400_data *data, -enum iio_event_direction dir, -int state) +static int bma400_generic_event_en (struct bma400_data *data, +enum iio_event_direction dir, +int state) {int ret;unsigned int intrmask, regval;
@@ -1337,7 +1337,7 @@ static int bma400_write_event_config(struct iio_dev *indio_dev,switch (type) {case IIO_EV_TYPE_MAG :mutex_lock (&data->mutex); - ret =bma400_activity_event_en (data, dir, state); + ret =bma400_generic_event_en (data, dir, state);mutex_unlock (&data->mutex);return ret;case IIO_EV_TYPE_GESTURE :
Signature · 1 line
2.43.0
PATCH v5 6/6 iio: accel: bma400: Add detail to comments in GEN INTR configuration
In reply to Akshay JindalAppend additional information to existing comments in the generic interrupt configuration code to provide more context.
--- drivers/iio/accel/bma400_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/accel/bma400_core.c +8 -2
@@ -1208,7 +1208,10 @@ static int bma400_generic_event_en(struct bma400_data *data, detect_criterion = bma400_genintr->detect_mode; intrmask = bma400_genintr->intrmask; -/* Enabling all axis for interrupt evaluation */ +/* +* Enabling all axis for interrupt evaluation +* Acc_filt2 is recommended as data source in datasheet (Section 4.7) +*/ ret = regmap_write(data->regmap, BMA400_GENINT_CONFIG_REG(genintr, 0), BMA400_GENINT_CONFIG0_X_EN_MASK | BMA400_GENINT_CONFIG0_Y_EN_MASK |
@@ -1226,7 +1229,10 @@ static int bma400_generic_event_en(struct bma400_data *data,if (ret)return ret; -/* Initial value to avoid interrupts while enabling*/ +/* +* Initial value to avoid interrupts while enabling +* Value is in units of 8mg/lsb, i.e. effective val is val * 8mg/lsb +*/ ret =regmap_write (data->regmap,BMA400_GENINT_CONFIG_REG (genintr,2 ),0x0A );if (ret)return ret;
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerQuoted 11 lines · On Sun, 12 Oct 2025 23:36:07 +0530 Akshay Jindal <[email protected]> wrote:
This series refactors the BMA400 driver with a focus on generic interrupt configuration and related register usage. The main changes reduce usage of hard-coded values by introducing macros and formula-based register addressing, and add a centralized lookup indexed on iio event direction.
Alongside these updates, the series also reorganizes and renames register and field macros for consistency with the datasheet, and extends comments for additional clarity.
All patches are pure refactoring. No functional changes are intended.
Applied to the togreg branch of iio.git but pushed out as testing for 0-day to take a first look.
Thanks,
Jonathan