regmap: Add regmap_field helpers for simple bit operations

Add simple bit operations for setting, clearing and testing specific
 bits with regmap_field.
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmKpskgACgkQJNaLcl1U
 h9BF7Af7Bg1qhqvTJQKvfc1TU7pRnO2Mt90MJTTAFMgiMP/+FZhiaDrKm12SBTPh
 w8Gomg8X+EYVpiqtywFoc0mZIUe03g9+8RpuKyK2EOReaguhU2qHQPDo2Dhx6x5p
 VnNY9w/rhQsrX8153c6ICZ8YqrxNqCbgCh7eulMeXz74wbxwbrNdZbbCaM9+WCS/
 fTWtNUwZ+3JtaSP55UCX/ITNrLct0gPdWqkRpLExv9HdOf1HaBRUTZH69ftQg82S
 PHsxEBpPWKbViflSU7V5/UgeBCTS7FjRpwB6OEX69V+VGhRIey9IgZqbSsX9KoXX
 RYPKj5DZD9JtPNA0W5Dzs0KyUIlDtA==
 =vniQ
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmKqENwACgkQJNaLcl1U
 h9D1pQf/cbMWcZeRe6eRxvDueIhyMYXwhahxEHMCL6EOR5SLLARB40klJq5DDPlM
 D7SZlPES1oXXQ8zm8rpBahfQf3AAeiUMZ4+bOMMU45xaNTKeOGPuihiP69PQxzp1
 RryrB6/AN+qKepHaWsnhOyarVnJ2XUDJ58QBmYwee5UFdxiPPIzjMLC0FVEgLhIc
 Ng75dFIur3SknYyoYyd9gsH/VydlaEiYQ9s3GRKtq+D0P/fbsylPp1w5Lup3tXWh
 kGYyJroz9doevY5K+TeMsVqSJhES3VJkz9GVxkdwCB6qhrXzGkbdnU7ZF1MZGlnf
 bOC6+lE+CxoDWx/apLmdJg6ZmnHxdQ==
 =CWeE
 -----END PGP SIGNATURE-----

Merge tag 'regmap-field-bit-helpers' of https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap into regmap-5.20

regmap: Add regmap_field helpers for simple bit operations

Add simple bit operations for setting, clearing and testing specific
bits with regmap_field.
This commit is contained in:
Mark Brown 2022-06-15 18:03:19 +01:00
commit 26968e614a
2 changed files with 59 additions and 0 deletions

View File

@ -2220,6 +2220,28 @@ int regmap_field_update_bits_base(struct regmap_field *field,
}
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
* register field with port ID

View File

@ -1336,6 +1336,22 @@ static inline int regmap_field_update_bits(struct regmap_field *field,
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
regmap_field_force_update_bits(struct regmap_field *field,
unsigned int mask, unsigned int val)
@ -1769,6 +1785,27 @@ regmap_field_force_update_bits(struct regmap_field *field,
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,
unsigned int id, unsigned int val)
{