Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: xilinx: Replace custom variants of bitmap_read()/bitmap_write()

Relatively recently bitmap APIs were expanded by introduction of
bitmap_read() and bitmap_write(). These APIs are generic ones
that may replace custom functions in this driver, i.e. xgpio_get_value32()
and xgpio_set_value32(). Do replace them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20250205093200.373709-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

Andy Shevchenko and committed by
Bartosz Golaszewski
c11708e2 2af1f667

+12 -26
+12 -26
drivers/gpio/gpio-xilinx.c
··· 71 71 struct clk *clk; 72 72 }; 73 73 74 - static inline u32 xgpio_get_value32(const unsigned long *map, int bit) 75 - { 76 - const size_t index = BIT_WORD(bit); 77 - const unsigned long offset = (bit % BITS_PER_LONG) & BIT(5); 78 - 79 - return (map[index] >> offset) & 0xFFFFFFFFul; 80 - } 81 - 82 - static inline void xgpio_set_value32(unsigned long *map, int bit, u32 v) 83 - { 84 - const size_t index = BIT_WORD(bit); 85 - const unsigned long offset = (bit % BITS_PER_LONG) & BIT(5); 86 - 87 - map[index] &= ~(0xFFFFFFFFul << offset); 88 - map[index] |= (unsigned long)v << offset; 89 - } 90 - 91 74 static inline int xgpio_regoffset(struct xgpio_instance *chip, int ch) 92 75 { 93 76 switch (ch) { ··· 86 103 static void xgpio_read_ch(struct xgpio_instance *chip, int reg, int bit, unsigned long *a) 87 104 { 88 105 void __iomem *addr = chip->regs + reg + xgpio_regoffset(chip, bit / 32); 106 + unsigned long value = xgpio_readreg(addr); 89 107 90 - xgpio_set_value32(a, bit, xgpio_readreg(addr)); 108 + bitmap_write(a, value, round_down(bit, 32), 32); 91 109 } 92 110 93 111 static void xgpio_write_ch(struct xgpio_instance *chip, int reg, int bit, unsigned long *a) 94 112 { 95 113 void __iomem *addr = chip->regs + reg + xgpio_regoffset(chip, bit / 32); 114 + unsigned long value = bitmap_read(a, round_down(bit, 32), 32); 96 115 97 - xgpio_writereg(addr, xgpio_get_value32(a, bit)); 116 + xgpio_writereg(addr, value); 98 117 } 99 118 100 119 static void xgpio_read_ch_all(struct xgpio_instance *chip, int reg, unsigned long *a) ··· 370 385 unsigned long flags; 371 386 struct xgpio_instance *chip = irq_data_get_irq_chip_data(irq_data); 372 387 int irq_offset = irqd_to_hwirq(irq_data); 373 - unsigned long bit = find_nth_bit(chip->map, 64, irq_offset); 388 + unsigned long bit = find_nth_bit(chip->map, 64, irq_offset), enable; 374 389 u32 mask = BIT(bit / 32), temp; 375 390 376 391 raw_spin_lock_irqsave(&chip->gpio_lock, flags); 377 392 378 393 __clear_bit(bit, chip->enable); 379 394 380 - if (xgpio_get_value32(chip->enable, bit) == 0) { 395 + enable = bitmap_read(chip->enable, round_down(bit, 32), 32); 396 + if (enable == 0) { 381 397 /* Disable per channel interrupt */ 382 398 temp = xgpio_readreg(chip->regs + XGPIO_IPIER_OFFSET); 383 399 temp &= ~mask; ··· 398 412 unsigned long flags; 399 413 struct xgpio_instance *chip = irq_data_get_irq_chip_data(irq_data); 400 414 int irq_offset = irqd_to_hwirq(irq_data); 401 - unsigned long bit = find_nth_bit(chip->map, 64, irq_offset); 402 - u32 old_enable = xgpio_get_value32(chip->enable, bit); 415 + unsigned long bit = find_nth_bit(chip->map, 64, irq_offset), enable; 403 416 u32 mask = BIT(bit / 32), val; 404 417 405 418 gpiochip_enable_irq(&chip->gc, irq_offset); 406 419 407 420 raw_spin_lock_irqsave(&chip->gpio_lock, flags); 408 421 409 - __set_bit(bit, chip->enable); 410 - 411 - if (old_enable == 0) { 422 + enable = bitmap_read(chip->enable, round_down(bit, 32), 32); 423 + if (enable == 0) { 412 424 /* Clear any existing per-channel interrupts */ 413 425 val = xgpio_readreg(chip->regs + XGPIO_IPISR_OFFSET); 414 426 val &= mask; ··· 420 436 val |= mask; 421 437 xgpio_writereg(chip->regs + XGPIO_IPIER_OFFSET, val); 422 438 } 439 + 440 + __set_bit(bit, chip->enable); 423 441 424 442 raw_spin_unlock_irqrestore(&chip->gpio_lock, flags); 425 443 }