Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: accel: bma400: Replace bit shifts with FIELD_PREP() and FIELD_GET()

set_* 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().

Signed-off-by: Akshay Jindal <akshayaj.lkd@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Akshay Jindal and committed by
Jonathan Cameron
1a7a6c5d e03d2138

+6 -9
-3
drivers/iio/accel/bma400.h
··· 75 75 */ 76 76 #define BMA400_ACC_CONFIG0_REG 0x19 77 77 #define BMA400_ACC_CONFIG0_LP_OSR_MASK GENMASK(6, 5) 78 - #define BMA400_LP_OSR_SHIFT 5 79 78 80 79 #define BMA400_ACC_CONFIG1_REG 0x1a 81 80 #define BMA400_ACC_CONFIG1_ODR_MASK GENMASK(3, 0) ··· 85 86 #define BMA400_ACC_CONFIG1_ODR_MIN_WHOLE_HZ 25 86 87 #define BMA400_ACC_CONFIG1_ODR_MIN_HZ 12 87 88 #define BMA400_ACC_CONFIG1_NP_OSR_MASK GENMASK(5, 4) 88 - #define BMA400_NP_OSR_SHIFT 4 89 89 #define BMA400_ACC_CONFIG1_ACC_RANGE_MASK GENMASK(7, 6) 90 - #define BMA400_ACC_RANGE_SHIFT 6 91 90 92 91 #define BMA400_ACC_CONFIG2_REG 0x1b 93 92
+6 -6
drivers/iio/accel/bma400_core.c
··· 627 627 return ret; 628 628 } 629 629 630 - osr = (val & BMA400_ACC_CONFIG0_LP_OSR_MASK) >> BMA400_LP_OSR_SHIFT; 630 + osr = FIELD_GET(BMA400_ACC_CONFIG0_LP_OSR_MASK, val); 631 631 632 632 data->oversampling_ratio = osr; 633 633 return 0; ··· 638 638 return ret; 639 639 } 640 640 641 - osr = (val & BMA400_ACC_CONFIG1_NP_OSR_MASK) >> BMA400_NP_OSR_SHIFT; 641 + osr = FIELD_GET(BMA400_ACC_CONFIG1_NP_OSR_MASK, val); 642 642 643 643 data->oversampling_ratio = osr; 644 644 return 0; ··· 673 673 674 674 ret = regmap_write(data->regmap, BMA400_ACC_CONFIG0_REG, 675 675 (acc_config & ~BMA400_ACC_CONFIG0_LP_OSR_MASK) | 676 - (val << BMA400_LP_OSR_SHIFT)); 676 + FIELD_PREP(BMA400_ACC_CONFIG0_LP_OSR_MASK, val)); 677 677 if (ret) { 678 678 dev_err(data->dev, "Failed to write out OSR\n"); 679 679 return ret; ··· 689 689 690 690 ret = regmap_write(data->regmap, BMA400_ACC_CONFIG1_REG, 691 691 (acc_config & ~BMA400_ACC_CONFIG1_NP_OSR_MASK) | 692 - (val << BMA400_NP_OSR_SHIFT)); 692 + FIELD_PREP(BMA400_ACC_CONFIG1_NP_OSR_MASK, val)); 693 693 if (ret) { 694 694 dev_err(data->dev, "Failed to write out OSR\n"); 695 695 return ret; ··· 730 730 if (ret) 731 731 return ret; 732 732 733 - raw_scale = (val & BMA400_ACC_CONFIG1_ACC_RANGE_MASK) >> BMA400_ACC_RANGE_SHIFT; 733 + raw_scale = FIELD_GET(BMA400_ACC_CONFIG1_ACC_RANGE_MASK, val); 734 734 if (raw_scale > BMA400_TWO_BITS_MASK) 735 735 return -EINVAL; 736 736 ··· 755 755 756 756 ret = regmap_write(data->regmap, BMA400_ACC_CONFIG1_REG, 757 757 (acc_config & ~BMA400_ACC_CONFIG1_ACC_RANGE_MASK) | 758 - (raw << BMA400_ACC_RANGE_SHIFT)); 758 + FIELD_PREP(BMA400_ACC_CONFIG1_ACC_RANGE_MASK, raw)); 759 759 if (ret) 760 760 return ret; 761 761