mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
iio: magnetometer: bmc150: use FIELD_PREP and FIELD_GET helpers
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> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
7dfa980242
commit
2766d92b05
|
|
@ -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));
|
||||
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));
|
||||
}
|
||||
|
||||
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, ®_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));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user