mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-03 00:54:09 +08:00
iio: adis: Add adis_update_bits() APIs
This patch adds a `regmap_update_bits()` like API to the ADIS library. It provides locked and unlocked variant. Signed-off-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
698211065d
commit
b9c5eec725
@ -223,6 +223,31 @@ int __adis_read_reg(struct adis *adis, unsigned int reg,
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__adis_read_reg);
|
||||
/**
|
||||
* __adis_update_bits_base() - ADIS Update bits function - Unlocked version
|
||||
* @adis: The adis device
|
||||
* @reg: The address of the lower of the two registers
|
||||
* @mask: Bitmask to change
|
||||
* @val: Value to be written
|
||||
* @size: Size of the register to update
|
||||
*
|
||||
* Updates the desired bits of @reg in accordance with @mask and @val.
|
||||
*/
|
||||
int __adis_update_bits_base(struct adis *adis, unsigned int reg, const u32 mask,
|
||||
const u32 val, u8 size)
|
||||
{
|
||||
int ret;
|
||||
u32 __val;
|
||||
|
||||
ret = __adis_read_reg(adis, reg, &__val, size);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
__val = (__val & ~mask) | (val & mask);
|
||||
|
||||
return __adis_write_reg(adis, reg, __val, size);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__adis_update_bits_base);
|
||||
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
|
||||
|
@ -333,6 +333,65 @@ static inline int adis_read_reg_32(struct adis *adis, unsigned int reg,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int __adis_update_bits_base(struct adis *adis, unsigned int reg, const u32 mask,
|
||||
const u32 val, u8 size);
|
||||
/**
|
||||
* adis_update_bits_base() - ADIS Update bits function - Locked version
|
||||
* @adis: The adis device
|
||||
* @reg: The address of the lower of the two registers
|
||||
* @mask: Bitmask to change
|
||||
* @val: Value to be written
|
||||
* @size: Size of the register to update
|
||||
*
|
||||
* Updates the desired bits of @reg in accordance with @mask and @val.
|
||||
*/
|
||||
static inline int adis_update_bits_base(struct adis *adis, unsigned int reg,
|
||||
const u32 mask, const u32 val, u8 size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
mutex_lock(&adis->state_lock);
|
||||
ret = __adis_update_bits_base(adis, reg, mask, val, size);
|
||||
mutex_unlock(&adis->state_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* adis_update_bits() - Wrapper macro for adis_update_bits_base - Locked version
|
||||
* @adis: The adis device
|
||||
* @reg: The address of the lower of the two registers
|
||||
* @mask: Bitmask to change
|
||||
* @val: Value to be written
|
||||
*
|
||||
* This macro evaluates the sizeof of @val at compile time and calls
|
||||
* adis_update_bits_base() accordingly. Be aware that using MACROS/DEFINES for
|
||||
* @val can lead to undesired behavior if the register to update is 16bit.
|
||||
*/
|
||||
#define adis_update_bits(adis, reg, mask, val) ({ \
|
||||
BUILD_BUG_ON(sizeof(val) == 1 || sizeof(val) == 8); \
|
||||
__builtin_choose_expr(sizeof(val) == 4, \
|
||||
adis_update_bits_base(adis, reg, mask, val, 4), \
|
||||
adis_update_bits_base(adis, reg, mask, val, 2)); \
|
||||
})
|
||||
|
||||
/**
|
||||
* adis_update_bits() - Wrapper macro for adis_update_bits_base
|
||||
* @adis: The adis device
|
||||
* @reg: The address of the lower of the two registers
|
||||
* @mask: Bitmask to change
|
||||
* @val: Value to be written
|
||||
*
|
||||
* This macro evaluates the sizeof of @val at compile time and calls
|
||||
* adis_update_bits_base() accordingly. Be aware that using MACROS/DEFINES for
|
||||
* @val can lead to undesired behavior if the register to update is 16bit.
|
||||
*/
|
||||
#define __adis_update_bits(adis, reg, mask, val) ({ \
|
||||
BUILD_BUG_ON(sizeof(val) == 1 || sizeof(val) == 8); \
|
||||
__builtin_choose_expr(sizeof(val) == 4, \
|
||||
__adis_update_bits_base(adis, reg, mask, val, 4), \
|
||||
__adis_update_bits_base(adis, reg, mask, val, 2)); \
|
||||
})
|
||||
|
||||
int adis_enable_irq(struct adis *adis, bool enable);
|
||||
int __adis_check_status(struct adis *adis);
|
||||
int __adis_initial_startup(struct adis *adis);
|
||||
|
Loading…
Reference in New Issue
Block a user