mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-24 05:01:03 +02:00
regmap: provide regmap_field helpers for simple bit operations
We have set/clear/test operations for regmap, but not for regmap_field yet. So let's introduce regmap_field helpers too. In many instances regmap_field_update_bits() is used for simple bit setting and clearing. In these cases the last argument is redundant and we can hide it with a static inline function. This adds three new helpers for simple bit operations: set_bits, clear_bits and test_bits (the last one defined as a regular function). Signed-off-by: Li Chen <lchen@ambarella.com> Link: https://lore.kernel.org/r/180eef422c3.deae9cd960729.8518395646822099769@zohomail.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
@@ -2220,6 +2220,28 @@ int regmap_field_update_bits_base(struct regmap_field *field,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(regmap_field_update_bits_base);
|
EXPORT_SYMBOL_GPL(regmap_field_update_bits_base);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* regmap_field_test_bits() - Check if all specified bits are set in a
|
||||||
|
* register field.
|
||||||
|
*
|
||||||
|
* @field: Register field to operate on
|
||||||
|
* @bits: Bits to test
|
||||||
|
*
|
||||||
|
* Returns -1 if the underlying regmap_field_read() fails, 0 if at least one of the
|
||||||
|
* tested bits is not set and 1 if all tested bits are set.
|
||||||
|
*/
|
||||||
|
int regmap_field_test_bits(struct regmap_field *field, unsigned int bits)
|
||||||
|
{
|
||||||
|
unsigned int val, ret;
|
||||||
|
|
||||||
|
ret = regmap_field_read(field, &val);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return (val & bits) == bits;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(regmap_field_test_bits);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* regmap_fields_update_bits_base() - Perform a read/modify/write cycle a
|
* regmap_fields_update_bits_base() - Perform a read/modify/write cycle a
|
||||||
* register field with port ID
|
* register field with port ID
|
||||||
|
@@ -1336,6 +1336,22 @@ static inline int regmap_field_update_bits(struct regmap_field *field,
|
|||||||
NULL, false, false);
|
NULL, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int regmap_field_set_bits(struct regmap_field *field,
|
||||||
|
unsigned int bits)
|
||||||
|
{
|
||||||
|
return regmap_field_update_bits_base(field, bits, bits, NULL, false,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int regmap_field_clear_bits(struct regmap_field *field,
|
||||||
|
unsigned int bits)
|
||||||
|
{
|
||||||
|
return regmap_field_update_bits_base(field, bits, 0, NULL, false,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int regmap_field_test_bits(struct regmap_field *field, unsigned int bits);
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
regmap_field_force_update_bits(struct regmap_field *field,
|
regmap_field_force_update_bits(struct regmap_field *field,
|
||||||
unsigned int mask, unsigned int val)
|
unsigned int mask, unsigned int val)
|
||||||
@@ -1769,6 +1785,27 @@ regmap_field_force_update_bits(struct regmap_field *field,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int regmap_field_set_bits(struct regmap_field *field,
|
||||||
|
unsigned int bits)
|
||||||
|
{
|
||||||
|
WARN_ONCE(1, "regmap API is disabled");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int regmap_field_clear_bits(struct regmap_field *field,
|
||||||
|
unsigned int bits)
|
||||||
|
{
|
||||||
|
WARN_ONCE(1, "regmap API is disabled");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int regmap_field_test_bits(struct regmap_field *field,
|
||||||
|
unsigned int bits)
|
||||||
|
{
|
||||||
|
WARN_ONCE(1, "regmap API is disabled");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int regmap_fields_write(struct regmap_field *field,
|
static inline int regmap_fields_write(struct regmap_field *field,
|
||||||
unsigned int id, unsigned int val)
|
unsigned int id, unsigned int val)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user