Skip to content

Commit 93b9299

Browse files
committed
Merge series "regmap: provide simple bitops and use them in a driver" from Bartosz Golaszewski <[email protected]>
Bartosz Golaszewski <[email protected]>: From: Bartosz Golaszewski <[email protected]> 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: 8f3d9f3 -- 2.26.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
2 parents 626ceee + aa2ff9d commit 93b9299

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

drivers/base/regmap/regmap.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,6 +2937,28 @@ int regmap_update_bits_base(struct regmap *map, unsigned int reg,
29372937
}
29382938
EXPORT_SYMBOL_GPL(regmap_update_bits_base);
29392939

2940+
/**
2941+
* regmap_test_bits() - Check if all specified bits are set in a register.
2942+
*
2943+
* @map: Register map to operate on
2944+
* @reg: Register to read from
2945+
* @bits: Bits to test
2946+
*
2947+
* Returns -1 if the underlying regmap_read() fails, 0 if at least one of the
2948+
* tested bits is not set and 1 if all tested bits are set.
2949+
*/
2950+
int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits)
2951+
{
2952+
unsigned int val, ret;
2953+
2954+
ret = regmap_read(map, reg, &val);
2955+
if (ret)
2956+
return ret;
2957+
2958+
return (val & bits) == bits;
2959+
}
2960+
EXPORT_SYMBOL_GPL(regmap_test_bits);
2961+
29402962
void regmap_async_complete_cb(struct regmap_async *async, int ret)
29412963
{
29422964
struct regmap *map = async->map;

include/linux/regmap.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,21 @@ bool regmap_reg_in_ranges(unsigned int reg,
10891089
const struct regmap_range *ranges,
10901090
unsigned int nranges);
10911091

1092+
static inline int regmap_set_bits(struct regmap *map,
1093+
unsigned int reg, unsigned int bits)
1094+
{
1095+
return regmap_update_bits_base(map, reg, bits, bits,
1096+
NULL, false, false);
1097+
}
1098+
1099+
static inline int regmap_clear_bits(struct regmap *map,
1100+
unsigned int reg, unsigned int bits)
1101+
{
1102+
return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
1103+
}
1104+
1105+
int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
1106+
10921107
/**
10931108
* struct reg_field - Description of an register field
10941109
*
@@ -1405,6 +1420,27 @@ static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
14051420
return -EINVAL;
14061421
}
14071422

1423+
static inline int regmap_set_bits(struct regmap *map,
1424+
unsigned int reg, unsigned int bits)
1425+
{
1426+
WARN_ONCE(1, "regmap API is disabled");
1427+
return -EINVAL;
1428+
}
1429+
1430+
static inline int regmap_clear_bits(struct regmap *map,
1431+
unsigned int reg, unsigned int bits)
1432+
{
1433+
WARN_ONCE(1, "regmap API is disabled");
1434+
return -EINVAL;
1435+
}
1436+
1437+
static inline int regmap_test_bits(struct regmap *map,
1438+
unsigned int reg, unsigned int bits)
1439+
{
1440+
WARN_ONCE(1, "regmap API is disabled");
1441+
return -EINVAL;
1442+
}
1443+
14081444
static inline int regmap_field_update_bits_base(struct regmap_field *field,
14091445
unsigned int mask, unsigned int val,
14101446
bool *change, bool async, bool force)

0 commit comments

Comments
 (0)