This patch adds a `regmap_update_bits()` like API to the ADIS library. It provides locked and unlocked variant.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -333,6 +333,65 @@ static inline int adis_read_reg_32(struct adis *adis, unsigned int reg, · 332 unmodified lines | ||
| 333 | 333 | return ret; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | +int __adis_update_bits_base(struct adis *adis, unsigned int reg, const u32 mask, | |
| 337 | + const u32 val, u8 size); | |
| 338 | +/** | |
| 339 | + * adis_update_bits_base() - ADIS Update bits function - Locked version | |
| 340 | + * @adis: The adis device | |
| 341 | + * @reg: The address of the lower of the two registers | |
| 342 | + * @mask: Bitmask to change | |
| 343 | + * @val: Value to be written | |
| 344 | + * @size: Size of the register to update | |
| 345 | + * | |
| 346 | + * Updates the desired bits of @reg in accordance with @mask and @val. | |
| 347 | + */ | |
| 348 | +static inline int adis_update_bits_base(struct adis *adis, unsigned int reg, | |
| 349 | + const u32 mask, const u32 val, u8 size) | |
| 350 | +{ | |
| 351 | + int ret; | |
| 352 | + | |
| 353 | + mutex_lock(&adis->state_lock); | |
| 354 | + ret = __adis_update_bits_base(adis, reg, mask, val, size); | |
| 355 | + mutex_unlock(&adis->state_lock); | |
| 356 | + return ret; | |
| 357 | +} | |
| 358 | + | |
| 359 | +/** | |
| 360 | + * adis_update_bits() - Wrapper macro for adis_update_bits_base - Locked version | |
| 361 | + * @adis: The adis device | |
| 362 | + * @reg: The address of the lower of the two registers | |
| 363 | + * @mask: Bitmask to change | |
| 364 | + * @val: Value to be written | |
| 365 | + * | |
| 366 | + * This macro evaluates the sizeof of @val at compile time and calls | |
| 367 | + * adis_update_bits_base() accordingly. Be aware that using MACROS/DEFINES for | |
| 368 | + * @val can lead to undesired behavior if the register to update is 16bit. | |
| 369 | + */ | |
| 370 | +#define adis_update_bits(adis, reg, mask, val) ({ \ | |
| 371 | + BUILD_BUG_ON(sizeof(val) == 1 || sizeof(val) == 8); \ | |
| 372 | + __builtin_choose_expr(sizeof(val) == 4, \ | |
| 373 | + adis_update_bits_base(adis, reg, mask, val, 4), \ | |
| 374 | + adis_update_bits_base(adis, reg, mask, val, 2)); \ | |
| 375 | +}) | |
| 376 | + | |
| 377 | +/** | |
| 378 | + * adis_update_bits() - Wrapper macro for adis_update_bits_base | |
| 379 | + * @adis: The adis device | |
| 380 | + * @reg: The address of the lower of the two registers | |
| 381 | + * @mask: Bitmask to change | |
| 382 | + * @val: Value to be written | |
| 383 | + * | |
| 384 | + * This macro evaluates the sizeof of @val at compile time and calls | |
| 385 | + * adis_update_bits_base() accordingly. Be aware that using MACROS/DEFINES for | |
| 386 | + * @val can lead to undesired behavior if the register to update is 16bit. | |
| 387 | + */ | |
| 388 | +#define __adis_update_bits(adis, reg, mask, val) ({ \ | |
| 389 | + BUILD_BUG_ON(sizeof(val) == 1 || sizeof(val) == 8); \ | |
| 390 | + __builtin_choose_expr(sizeof(val) == 4, \ | |
| 391 | + __adis_update_bits_base(adis, reg, mask, val, 4), \ | |
| 392 | + __adis_update_bits_base(adis, reg, mask, val, 2)); \ | |
| 393 | +}) | |
| 394 | + | |
| 336 | 395 | int adis_enable_irq(struct adis *adis, bool enable); |
| 337 | 396 | int __adis_check_status(struct adis *adis); |
| 338 | 397 | int __adis_initial_startup(struct adis *adis); |