Commit 93b92992 authored by Mark Brown's avatar Mark Brown

Merge series "regmap: provide simple bitops and use them in a driver" from...

Merge series "regmap: provide simple bitops and use them in a driver" from Bartosz Golaszewski <brgl@bgdev.pl>
Bartosz Golaszewski <bgolaszewski@baylibre.com>:

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

I noticed that oftentimes I use regmap_update_bits() for simple bit
setting or clearing. In this case the fourth argument is superfluous as
it's always 0 or equal to the mask argument.

This series proposes to add simple bit operations for setting, clearing
and testing specific bits with regmap.

The second patch uses all three in a driver that got recently picked into
the net-next tree.

The patches obviously target different trees so - if you're ok with
the change itself - I propose you pick the first one into your regmap
tree for v5.8 and then I'll resend the second patch to add the first
user for these macros for v5.9.

v1 -> v2:
- convert the new macros to static inline functions

v2 -> v3:
- drop unneeded ternary operator

Bartosz Golaszewski (2):
  regmap: provide helpers for simple bit operations
  net: ethernet: mtk-star-emac: use regmap bitops

 drivers/base/regmap/regmap.c                  | 22 +++++
 drivers/net/ethernet/mediatek/mtk_star_emac.c | 80 ++++++++-----------
 include/linux/regmap.h                        | 36 +++++++++
 3 files changed, 93 insertions(+), 45 deletions(-)

base-commit: 8f3d9f35

--
2.26.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
parents 626ceee3 aa2ff9db
...@@ -2937,6 +2937,28 @@ int regmap_update_bits_base(struct regmap *map, unsigned int reg, ...@@ -2937,6 +2937,28 @@ int regmap_update_bits_base(struct regmap *map, unsigned int reg,
} }
EXPORT_SYMBOL_GPL(regmap_update_bits_base); EXPORT_SYMBOL_GPL(regmap_update_bits_base);
/**
* regmap_test_bits() - Check if all specified bits are set in a register.
*
* @map: Register map to operate on
* @reg: Register to read from
* @bits: Bits to test
*
* Returns -1 if the underlying regmap_read() fails, 0 if at least one of the
* tested bits is not set and 1 if all tested bits are set.
*/
int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits)
{
unsigned int val, ret;
ret = regmap_read(map, reg, &val);
if (ret)
return ret;
return (val & bits) == bits;
}
EXPORT_SYMBOL_GPL(regmap_test_bits);
void regmap_async_complete_cb(struct regmap_async *async, int ret) void regmap_async_complete_cb(struct regmap_async *async, int ret)
{ {
struct regmap *map = async->map; struct regmap *map = async->map;
......
...@@ -1089,6 +1089,21 @@ bool regmap_reg_in_ranges(unsigned int reg, ...@@ -1089,6 +1089,21 @@ bool regmap_reg_in_ranges(unsigned int reg,
const struct regmap_range *ranges, const struct regmap_range *ranges,
unsigned int nranges); unsigned int nranges);
static inline int regmap_set_bits(struct regmap *map,
unsigned int reg, unsigned int bits)
{
return regmap_update_bits_base(map, reg, bits, bits,
NULL, false, false);
}
static inline int regmap_clear_bits(struct regmap *map,
unsigned int reg, unsigned int bits)
{
return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
}
int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
/** /**
* struct reg_field - Description of an register field * struct reg_field - Description of an register field
* *
...@@ -1405,6 +1420,27 @@ static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg, ...@@ -1405,6 +1420,27 @@ static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
return -EINVAL; return -EINVAL;
} }
static inline int regmap_set_bits(struct regmap *map,
unsigned int reg, unsigned int bits)
{
WARN_ONCE(1, "regmap API is disabled");
return -EINVAL;
}
static inline int regmap_clear_bits(struct regmap *map,
unsigned int reg, unsigned int bits)
{
WARN_ONCE(1, "regmap API is disabled");
return -EINVAL;
}
static inline int regmap_test_bits(struct regmap *map,
unsigned int reg, unsigned int bits)
{
WARN_ONCE(1, "regmap API is disabled");
return -EINVAL;
}
static inline int regmap_field_update_bits_base(struct regmap_field *field, static inline int regmap_field_update_bits_base(struct regmap_field *field,
unsigned int mask, unsigned int val, unsigned int mask, unsigned int val,
bool *change, bool async, bool force) bool *change, bool async, bool force)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment