Commit acebb82f authored by William Breathitt Gray's avatar William Breathitt Gray Committed by Linus Torvalds

gpio: ws16c48: utilize for_each_set_clump8 macro

Replace verbose implementation in get_multiple/set_multiple callbacks
with for_each_set_clump8 macro to simplify code and improve clarity.

Link: http://lkml.kernel.org/r/7a0d2c964e7f2d289b16c63ff6b06fc1f4c50d4d.1570641097.git.vilhelm.gray@gmail.comSigned-off-by: default avatarWilliam Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Lukas Wunner <lukas@wunner.de>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Mathias Duckeck <m.duckeck@kunbus.de>
Cc: Morten Hein Tiljeset <morten.tiljeset@prevas.dk>
Cc: Phil Reid <preid@electromag.com.au>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Sean Nyekjaer <sean.nyekjaer@prevas.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b0f49e9b
...@@ -129,42 +129,19 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip, ...@@ -129,42 +129,19 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip,
unsigned long *mask, unsigned long *bits) unsigned long *mask, unsigned long *bits)
{ {
struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip);
const unsigned int gpio_reg_size = 8; unsigned long offset;
size_t i; unsigned long gpio_mask;
const size_t num_ports = chip->ngpio / gpio_reg_size; unsigned int port_addr;
unsigned int bits_offset;
size_t word_index;
unsigned int word_offset;
unsigned long word_mask;
const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
unsigned long port_state; unsigned long port_state;
/* clear bits array to a clean slate */ /* clear bits array to a clean slate */
bitmap_zero(bits, chip->ngpio); bitmap_zero(bits, chip->ngpio);
/* get bits are evaluated a gpio port register at a time */ for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) {
for (i = 0; i < num_ports; i++) { port_addr = ws16c48gpio->base + offset / 8;
/* gpio offset in bits array */ port_state = inb(port_addr) & gpio_mask;
bits_offset = i * gpio_reg_size;
/* word index for bits array */ bitmap_set_value8(bits, port_state, offset);
word_index = BIT_WORD(bits_offset);
/* gpio offset within current word of bits array */
word_offset = bits_offset % BITS_PER_LONG;
/* mask of get bits for current gpio within current word */
word_mask = mask[word_index] & (port_mask << word_offset);
if (!word_mask) {
/* no get bits in this port so skip to next one */
continue;
}
/* read bits from current gpio port */
port_state = inb(ws16c48gpio->base + i);
/* store acquired bits at respective bits array offset */
bits[word_index] |= (port_state << word_offset) & word_mask;
} }
return 0; return 0;
...@@ -198,39 +175,29 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip, ...@@ -198,39 +175,29 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip,
unsigned long *mask, unsigned long *bits) unsigned long *mask, unsigned long *bits)
{ {
struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip);
unsigned int i; unsigned long offset;
const unsigned int gpio_reg_size = 8; unsigned long gpio_mask;
unsigned int port; size_t index;
unsigned int iomask; unsigned int port_addr;
unsigned int bitmask; unsigned long bitmask;
unsigned long flags; unsigned long flags;
/* set bits are evaluated a gpio register size at a time */ for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) {
for (i = 0; i < chip->ngpio; i += gpio_reg_size) { index = offset / 8;
/* no more set bits in this mask word; skip to the next word */ port_addr = ws16c48gpio->base + index;
if (!mask[BIT_WORD(i)]) {
i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
continue;
}
port = i / gpio_reg_size;
/* mask out GPIO configured for input */ /* mask out GPIO configured for input */
iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port]; gpio_mask &= ~ws16c48gpio->io_state[index];
bitmask = iomask & bits[BIT_WORD(i)]; bitmask = bitmap_get_value8(bits, offset) & gpio_mask;
raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); raw_spin_lock_irqsave(&ws16c48gpio->lock, flags);
/* update output state data and set device gpio register */ /* update output state data and set device gpio register */
ws16c48gpio->out_state[port] &= ~iomask; ws16c48gpio->out_state[index] &= ~gpio_mask;
ws16c48gpio->out_state[port] |= bitmask; ws16c48gpio->out_state[index] |= bitmask;
outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); outb(ws16c48gpio->out_state[index], port_addr);
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
/* prepare for next gpio register set */
mask[BIT_WORD(i)] >>= gpio_reg_size;
bits[BIT_WORD(i)] >>= gpio_reg_size;
} }
} }
......
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