diff mbox series

[v2,2/3] gpio: thunderx: Utilize for_each_set_clump macro

Message ID 3fc5bd83322c94eb2a4f48677f6d762bf81d0652.1613134924.git.syednwaris@gmail.com
State Superseded
Headers show
Series Introduce the for_each_set_clump macro | expand

Commit Message

Syed Nayyar Waris Feb. 12, 2021, 1:21 p.m. UTC
This patch reimplements the thunderx_gpio_set_multiple function in
drivers/gpio/gpio-thunderx.c to use the new for_each_set_clump macro.
Instead of looping for each bank in thunderx_gpio_set_multiple
function, now we can skip bank which is not set and save cycles.

Cc: William Breathitt Gray <vilhelm.gray@gmail.com>
Cc: Robert Richter <rrichter@marvell.com>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Syed Nayyar Waris <syednwaris@gmail.com>
---
 drivers/gpio/gpio-thunderx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

William Breathitt Gray Feb. 14, 2021, 6:46 a.m. UTC | #1
On Fri, Feb 12, 2021 at 06:51:04PM +0530, Syed Nayyar Waris wrote:
> This patch reimplements the thunderx_gpio_set_multiple function in

> drivers/gpio/gpio-thunderx.c to use the new for_each_set_clump macro.

> Instead of looping for each bank in thunderx_gpio_set_multiple

> function, now we can skip bank which is not set and save cycles.

> 

> Cc: William Breathitt Gray <vilhelm.gray@gmail.com>

> Cc: Robert Richter <rrichter@marvell.com>

> Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>

> Signed-off-by: Syed Nayyar Waris <syednwaris@gmail.com>


Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>


> ---

>  drivers/gpio/gpio-thunderx.c | 13 ++++++++-----

>  1 file changed, 8 insertions(+), 5 deletions(-)

> 

> diff --git a/drivers/gpio/gpio-thunderx.c b/drivers/gpio/gpio-thunderx.c

> index 9f66deab46ea..0398b2d2af4b 100644

> --- a/drivers/gpio/gpio-thunderx.c

> +++ b/drivers/gpio/gpio-thunderx.c

> @@ -16,7 +16,7 @@

>  #include <linux/pci.h>

>  #include <linux/spinlock.h>

>  #include <asm-generic/msi.h>

> -

> +#include "gpiolib.h"

>  

>  #define GPIO_RX_DAT	0x0

>  #define GPIO_TX_SET	0x8

> @@ -275,12 +275,15 @@ static void thunderx_gpio_set_multiple(struct gpio_chip *chip,

>  				       unsigned long *bits)

>  {

>  	int bank;

> -	u64 set_bits, clear_bits;

> +	unsigned long set_bits, clear_bits, gpio_mask;

> +	unsigned long offset;

> +

>  	struct thunderx_gpio *txgpio = gpiochip_get_data(chip);

>  

> -	for (bank = 0; bank <= chip->ngpio / 64; bank++) {

> -		set_bits = bits[bank] & mask[bank];

> -		clear_bits = ~bits[bank] & mask[bank];

> +	for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, 64) {

> +		bank = offset / 64;

> +		set_bits = bits[bank] & gpio_mask;

> +		clear_bits = ~bits[bank] & gpio_mask;

>  		writeq(set_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET);

>  		writeq(clear_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_CLR);

>  	}

> -- 

> 2.29.0

>
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-thunderx.c b/drivers/gpio/gpio-thunderx.c
index 9f66deab46ea..0398b2d2af4b 100644
--- a/drivers/gpio/gpio-thunderx.c
+++ b/drivers/gpio/gpio-thunderx.c
@@ -16,7 +16,7 @@ 
 #include <linux/pci.h>
 #include <linux/spinlock.h>
 #include <asm-generic/msi.h>
-
+#include "gpiolib.h"
 
 #define GPIO_RX_DAT	0x0
 #define GPIO_TX_SET	0x8
@@ -275,12 +275,15 @@  static void thunderx_gpio_set_multiple(struct gpio_chip *chip,
 				       unsigned long *bits)
 {
 	int bank;
-	u64 set_bits, clear_bits;
+	unsigned long set_bits, clear_bits, gpio_mask;
+	unsigned long offset;
+
 	struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
 
-	for (bank = 0; bank <= chip->ngpio / 64; bank++) {
-		set_bits = bits[bank] & mask[bank];
-		clear_bits = ~bits[bank] & mask[bank];
+	for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, 64) {
+		bank = offset / 64;
+		set_bits = bits[bank] & gpio_mask;
+		clear_bits = ~bits[bank] & gpio_mask;
 		writeq(set_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET);
 		writeq(clear_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_CLR);
 	}