Skip to content

Commit

Permalink
gpio: max3191x: utilize the for_each_set_clump8 macro
Browse files Browse the repository at this point in the history
Replace verbose implementation in get_multiple callback with
for_each_set_clump8 macro to simplify code and improve clarity.

Link: http://lkml.kernel.org/r/c2b1ed62caf6fce6e5681809a50c05ce6acdf2a6.1570641097.git.vilhelm.gray@gmail.com
Signed-off-by: William Breathitt Gray <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Mathias Duckeck <[email protected]>
Cc: Lukas Wunner <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Masahiro Yamada <[email protected]>
Cc: Morten Hein Tiljeset <[email protected]>
Cc: Phil Reid <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Sean Nyekjaer <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
vilhelmgray authored and torvalds committed Dec 5, 2019
1 parent 608bd5f commit d077c78
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions drivers/gpio/gpio-max3191x.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

#include <linux/bitmap.h>
#include <linux/bitops.h>
#include <linux/crc8.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
Expand Down Expand Up @@ -232,29 +233,29 @@ static int max3191x_get_multiple(struct gpio_chip *gpio, unsigned long *mask,
unsigned long *bits)
{
struct max3191x_chip *max3191x = gpiochip_get_data(gpio);
int ret, bit = 0, wordlen = max3191x_wordlen(max3191x);
const unsigned int wordlen = max3191x_wordlen(max3191x);
int ret;
unsigned long bit;
unsigned long gpio_mask;
unsigned long in;

mutex_lock(&max3191x->lock);
ret = max3191x_readout_locked(max3191x);
if (ret)
goto out_unlock;

while ((bit = find_next_bit(mask, gpio->ngpio, bit)) != gpio->ngpio) {
bitmap_zero(bits, gpio->ngpio);
for_each_set_clump8(bit, gpio_mask, mask, gpio->ngpio) {
unsigned int chipnum = bit / MAX3191X_NGPIO;
unsigned long in, shift, index;

if (max3191x_chip_is_faulting(max3191x, chipnum)) {
ret = -EIO;
goto out_unlock;
}

in = ((u8 *)max3191x->xfer.rx_buf)[chipnum * wordlen];
shift = round_down(bit % BITS_PER_LONG, MAX3191X_NGPIO);
index = bit / BITS_PER_LONG;
bits[index] &= ~(mask[index] & (0xff << shift));
bits[index] |= mask[index] & (in << shift); /* copy bits */

bit = (chipnum + 1) * MAX3191X_NGPIO; /* go to next chip */
in &= gpio_mask;
bitmap_set_value8(bits, in, bit);
}

out_unlock:
Expand Down

0 comments on commit d077c78

Please sign in to comment.