In many instances regmap_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).
Unified · Split
| @@ -2936,6 +2936,28 @@ int regmap_update_bits_base(struct regmap *map, unsigned int reg, · 2935 unmodified lines | ||
| 2936 | 2936 | } |
| 2937 | 2937 | EXPORT_SYMBOL_GPL(regmap_update_bits_base); |
| 2938 | 2938 | |
| 2939 | +/** | |
| 2940 | + * regmap_test_bits() - Check if all specified bits are set in a register. | |
| 2941 | + * | |
| 2942 | + * @map: Register map to operate on | |
| 2943 | + * @reg: Register to read from | |
| 2944 | + * @bits: Bits to test | |
| 2945 | + * | |
| 2946 | + * Returns -1 if the underlying regmap_read() fails, 0 if at least one of the | |
| 2947 | + * tested bits is not set and 1 if all tested bits are set. | |
| 2948 | + */ | |
| 2949 | +int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits) | |
| 2950 | +{ | |
| 2951 | + unsigned int val, ret; | |
| 2952 | + | |
| 2953 | + ret = regmap_read(map, reg, &val); | |
| 2954 | + if (ret) | |
| 2955 | + return ret; | |
| 2956 | + | |
| 2957 | + return (val & bits) == bits; | |
| 2958 | +} | |
| 2959 | +EXPORT_SYMBOL_GPL(regmap_test_bits); | |
| 2960 | + | |
| 2939 | 2961 | void regmap_async_complete_cb(struct regmap_async *async, int ret) |
| 2940 | 2962 | { |
| 2941 | 2963 | struct regmap *map = async->map; |
| @@ -1111,6 +1111,21 @@ bool regmap_reg_in_ranges(unsigned int reg, · 1110 unmodified lines | ||
| 1111 | 1111 | const struct regmap_range *ranges, |
| 1112 | 1112 | unsigned int nranges); |
| 1113 | 1113 | |
| 1114 | +static inline int regmap_set_bits(struct regmap *map, | |
| 1115 | + unsigned int reg, unsigned int bits) | |
| 1116 | +{ | |
| 1117 | + return regmap_update_bits_base(map, reg, bits, bits, | |
| 1118 | + NULL, false, false); | |
| 1119 | +} | |
| 1120 | + | |
| 1121 | +static inline int regmap_clear_bits(struct regmap *map, | |
| 1122 | + unsigned int reg, unsigned int bits) | |
| 1123 | +{ | |
| 1124 | + return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false); | |
| 1125 | +} | |
| 1126 | + | |
| 1127 | +int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits); | |
| 1128 | + | |
| 1114 | 1129 | /** |
| 1115 | 1130 | * struct reg_field - Description of an register field |
| 1116 | 1131 | * |
| @@ -1410,6 +1425,27 @@ static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg, · 293 unmodified lines | ||
| 1410 | 1425 | return -EINVAL; |
| 1411 | 1426 | } |
| 1412 | 1427 | |
| 1428 | +static inline int regmap_set_bits(struct regmap *map, | |
| 1429 | + unsigned int reg, unsigned int bits) | |
| 1430 | +{ | |
| 1431 | + WARN_ONCE(1, "regmap API is disabled"); | |
| 1432 | + return -EINVAL; | |
| 1433 | +} | |
| 1434 | + | |
| 1435 | +static inline int regmap_clear_bits(struct regmap *map, | |
| 1436 | + unsigned int reg, unsigned int bits) | |
| 1437 | +{ | |
| 1438 | + WARN_ONCE(1, "regmap API is disabled"); | |
| 1439 | + return -EINVAL; | |
| 1440 | +} | |
| 1441 | + | |
| 1442 | +static inline int regmap_test_bits(struct regmap *map, | |
| 1443 | + unsigned int reg, unsigned int bits) | |
| 1444 | +{ | |
| 1445 | + WARN_ONCE(1, "regmap API is disabled"); | |
| 1446 | + return -EINVAL; | |
| 1447 | +} | |
| 1448 | + | |
| 1413 | 1449 | static inline int regmap_field_update_bits_base(struct regmap_field *field, |
| 1414 | 1450 | unsigned int mask, unsigned int val, |
| 1415 | 1451 | bool *change, bool async, bool force) |