pinctrl: at91: Add set_multiple GPIO chip feature
PATCH 1/2 pinctrl: at91: Add set_multiple GPIO chip feature
This adds the callback for set_multiple.
As this controller has a separate set and clear register, we can't write directly to PIO_ODSR as this would required a cached variable and would race with at91_gpio_set.
So build masks for the PIO_SODR and PIO_CODR registers and write them together.
---
This was tested by using an own test driver which uses gpiod_set_array_cansleep to set multiple GPIOs at once.
drivers/pinctrl/pinctrl-at91.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/pinctrl/pinctrl-at91.c +28 -0
@@ -1330,6 +1330,33 @@ static void at91_gpio_set(struct gpio_chip *chip, unsigned offset,writel_relaxed (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static void at91_gpio_set_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{ +struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip); +void __iomem *pio = at91_gpio->regbase; +unsigned long set_mask; +unsigned long clear_mask; +size_t i; + + set_mask =0 ; + clear_mask =0 ; + +for (i =0 ; i < chip->ngpio; i++) { +if (*mask ==0 ) +break ; +if (__test_and_clear_bit (i, mask)) { +if (test_bit (i, bits)) + set_mask |=BIT (i); +else + clear_mask |=BIT (i); + } + } + +writel_relaxed (set_mask, pio +PIO_SODR ); +writel_relaxed (clear_mask, pio +PIO_CODR ); +} +static int at91_gpio_direction_output (struct gpio_chip *chip,unsigned offset,int val) {
@@ -1692,6 +1719,7 @@ static struct gpio_chip at91_gpio_template = { .get = at91_gpio_get, .direction_output = at91_gpio_direction_output, .set = at91_gpio_set, + .set_multiple = at91_gpio_set_multiple, .dbg_show = at91_gpio_dbg_show, .can_sleep = false, .ngpio = MAX_NB_GPIO_PER_BANK,
Signature · 1 line
2.3.3
PATCH 2/2 pinctrl: at91: Add missing include
This fixes the sparse warning:drivers/pinctrl/pinctrl-at91.c:1556:6: warning: symbol
'at91_pinctrl_gpio_suspend' was not declared. Should it be static?drivers/pinctrl/pinctrl-at91.c:1580:6: warning: symbol
'at91_pinctrl_gpio_resume' was not declared. Should it be static?
--- drivers/pinctrl/pinctrl-at91.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/pinctrl/pinctrl-at91.c +2 -0
@@ -25,6 +25,8 @@/* Since we request GPIOs from ourself */ #include <linux/pinctrl/consumer.h> +#include <mach/hardware.h> +#include "pinctrl-at91.h" #include "core.h"
Signature · 1 line
2.3.3
PATCH 2/2 pinctrl: at91: Add missing include
Quoted 16 lines · Alexander Stein
This fixes the sparse warning:
drivers/pinctrl/pinctrl-at91.c:1556:6: warning: symbol
'at91_pinctrl_gpio_suspend' was not declared. Should it be static?drivers/pinctrl/pinctrl-at91.c:1580:6: warning: symbol
'at91_pinctrl_gpio_resume' was not declared. Should it be static?Signed-off-by Alexander Stein <[email protected]>--- drivers/pinctrl/pinctrl-at91.c | 2 ++ 1 file changed, 2 insertions(+)drivers/pinctrl/pinctrl-at91.c +0
-0
drivers/pinctrl/pinctrl-at91.c line 28
Quoted 4 lines
drivers/pinctrl/pinctrl-at91.c +1
-0@@ -25,6 +25,8 @@/* Since we request GPIOs from ourself */ #include <linux/pinctrl/consumer.h> +#include <mach/hardware.h>
NACK this will break multi arch support
Best Regards,
J.
Quoted 7 lines
drivers/pinctrl/pinctrl-at91.c +1
-0+#include "pinctrl-at91.h" #include "core.h" Signature · 1 line
2.3.3
PATCH 2/2 pinctrl: at91: Add missing include
On Thursday 02 April 2015, 10:19:41 wrote Jean-Christophe PLAGNIOL-VILLARD:
Quoted 20 lines · Alexander Stein
Quoted 19 lines
This fixes the sparse warning:
drivers/pinctrl/pinctrl-at91.c:1556:6: warning: symbol
'at91_pinctrl_gpio_suspend' was not declared. Should it be static?drivers/pinctrl/pinctrl-at91.c:1580:6: warning: symbol
'at91_pinctrl_gpio_resume' was not declared. Should it be static?Signed-off-by Alexander Stein <[email protected]>--- drivers/pinctrl/pinctrl-at91.c | 2 ++ 1 file changed, 2 insertions(+)drivers/pinctrl/pinctrl-at91.c +0
-0@@ -25,6 +25,8 @@/* Since we request GPIOs from ourself */ #include <linux/pinctrl/consumer.h>
Quoted 2 lines
drivers/pinctrl/pinctrl-at91.c line 28
Quoted 1 line
drivers/pinctrl/pinctrl-at91.c +1
-0+#include <mach/hardware.h> NACK this will break multi arch support
Mh, i see. So I guess this sparse warning will stay there then.
Best regards,
Alexander
PATCH 1/2 pinctrl: at91: Add set_multiple GPIO chip feature
In reply to Alexander SteinQuoted 11 lines · Alexander Stein
This adds the callback for
set_multiple.
As this controller has a separate set and clear register, we can't write directly toPIO_ODSRas this would required a cached variable and would race withat91_gpio_set.
So build masks for thePIO_SODRandPIO_CODRregisters and write them together.Signed-off-by Alexander Stein <[email protected]>---
This was tested by using an own test driver which usesgpiod_set_array_cansleepto set multiple GPIOs at once.
I remember J-C brought this up ages ago, so I hope he will be delighted to see we can now, FINALLY, do this!
J-C can I have your review on this?
Yours,
Linus Walleij
PATCH 1/2 pinctrl: at91: Add set_multiple GPIO chip feature
J
Quoted 16 lines · Linus Walleij
Quoted 11 lines · Alexander Stein
This adds the callback for
set_multiple.
As this controller has a separate set and clear register, we can't write directly toPIO_ODSRas this would required a cached variable and would race withat91_gpio_set.
So build masks for thePIO_SODRandPIO_CODRregisters and write them together.Signed-off-by Alexander Stein <[email protected]>---
This was tested by using an own test driver which usesgpiod_set_array_cansleepto set multiple GPIOs at once.
Quoted 4 lines
I remember J-C brought this up ages ago, so I hope he will be delighted to see we can now, FINALLY, do this!
J-C can I have your review on this?
I will check it tonight
Best Regards,
J.
PATCH 1/2 pinctrl: at91: Add set_multiple GPIO chip feature
In reply to Alexander SteinHi Alexander,
Quoted 6 lines · Alexander Stein
This adds the callback for
set_multiple.
As this controller has a separate set and clear register, we can't write directly toPIO_ODSRas this would required a cached variable and would race withat91_gpio_set.
So build masks for thePIO_SODRandPIO_CODRregisters and write them together.
Sure seems safer and easier to use SODR and CODR.
Quoted 2 lines
Signed-off-by Alexander Stein <[email protected]>
A question below.
Quoted 21 lines
---
This was tested by using an own test driver which usesgpiod_set_array_cansleepto set multiple GPIOs at once.drivers/pinctrl/pinctrl-at91.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/pinctrl/pinctrl-at91.c +6
-0@@ -1330,6 +1330,33 @@ static void at91_gpio_set(struct gpio_chip *chip, unsigned offset,writel_relaxed (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static void at91_gpio_set_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{ +struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip); +void __iomem *pio = at91_gpio->regbase; +unsigned long set_mask;
drivers/pinctrl/pinctrl-at91.c static void at91_gpio_set(struct gpio_chip *chip, unsigned offset, · line 1348
Quoted 10 lines
drivers/pinctrl/pinctrl-at91.c +10
-0+unsigned long clear_mask; +size_t i; + + set_mask =0 ; + clear_mask =0 ; + +for (i =0 ; i < chip->ngpio; i++) { +if (*mask ==0 ) +break ; +if (__test_and_clear_bit (i, mask)) {
For my knowledge, why do you need to clear the mask?
Quoted 29 lines
drivers/pinctrl/pinctrl-at91.c +12
-0+if (test_bit (i, bits)) + set_mask |=BIT (i); +else + clear_mask |=BIT (i); + } + } + +writel_relaxed (set_mask, pio +PIO_SODR ); +writel_relaxed (clear_mask, pio +PIO_CODR ); +} +static int at91_gpio_direction_output (struct gpio_chip *chip,unsigned offset,int val) {@@ -1692,6 +1719,7 @@ static struct gpio_chip at91_gpio_template = { .get = at91_gpio_get, .direction_output = at91_gpio_direction_output, .set = at91_gpio_set, + .set_multiple = at91_gpio_set_multiple, .dbg_show = at91_gpio_dbg_show, .can_sleep = false, .ngpio = MAX_NB_GPIO_PER_BANK,Signature · 6 lines
2.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/2 pinctrl: at91: Add set_multiple GPIO chip feature
Hello Ludovic,
On Friday 27 March 2015, 11:11:52 wrote Ludovic Desroches:
Quoted 41 lines · Alexander Stein
Quoted 6 lines
This adds the callback for
set_multiple.
As this controller has a separate set and clear register, we can't write directly toPIO_ODSRas this would required a cached variable and would race withat91_gpio_set.
So build masks for thePIO_SODRandPIO_CODRregisters and write them together.Sure seems safer and easier to use SODR and CODR.
Quoted 2 lines
Signed-off-by Alexander Stein <[email protected]>A question below.
Quoted 25 lines
---
This was tested by using an own test driver which usesgpiod_set_array_cansleepto set multiple GPIOs at once.drivers/pinctrl/pinctrl-at91.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/pinctrl/pinctrl-at91.c +10
-0@@ -1330,6 +1330,33 @@ static void at91_gpio_set(struct gpio_chip *chip, unsigned offset,writel_relaxed (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static void at91_gpio_set_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{ +struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip); +void __iomem *pio = at91_gpio->regbase; +unsigned long set_mask; +unsigned long clear_mask; +size_t i; + + set_mask =0 ;
Quoted 8 lines
drivers/pinctrl/pinctrl-at91.c static void at91_gpio_set(struct gpio_chip *chip, unsigned offset, · line 1348
Quoted 6 lines
drivers/pinctrl/pinctrl-at91.c +6
-0+ clear_mask =0 ; + +for (i =0 ; i < chip->ngpio; i++) { +if (*mask ==0 ) +break ; +if (__test_and_clear_bit (i, mask)) {For my knowledge, why do you need to clear the mask?
I tried to do the same as mpc8xxx_gpio_set_multiple. I think the reason is that an empty mask will quit that loop potentially earlier.
Best regards,
Alexander
PATCH 1/2 pinctrl: at91: Add set_multiple GPIO chip feature
In reply to Alexander SteinQuoted 27 lines · Alexander Stein
This adds the callback for
set_multiple.
As this controller has a separate set and clear register, we can't write directly toPIO_ODSRas this would required a cached variable and would race withat91_gpio_set.
So build masks for thePIO_SODRandPIO_CODRregisters and write them together.Signed-off-by Alexander Stein <[email protected]>---
This was tested by using an own test driver which usesgpiod_set_array_cansleepto set multiple GPIOs at once.drivers/pinctrl/pinctrl-at91.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/pinctrl/pinctrl-at91.c +4
-0@@ -1330,6 +1330,33 @@ static void at91_gpio_set(struct gpio_chip *chip, unsigned offset,writel_relaxed (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static void at91_gpio_set_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{ +struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip);
drivers/pinctrl/pinctrl-at91.c static void at91_gpio_set(struct gpio_chip *chip, unsigned offset, · line 1346
Quoted 10 lines
drivers/pinctrl/pinctrl-at91.c +10
-0+void __iomem *pio = at91_gpio->regbase; +unsigned long set_mask; +unsigned long clear_mask; +size_t i; + + set_mask =0 ; + clear_mask =0 ; + +for (i =0 ; i < chip->ngpio; i++) { +if (*mask ==0 )
so why do you loop?
drivers/pinctrl/pinctrl-at91.c static void at91_gpio_set(struct gpio_chip *chip, unsigned offset, · line 1354
Quoted 8 lines
drivers/pinctrl/pinctrl-at91.c +8
-0+break ; +if (__test_and_clear_bit (i, mask)) { +if (test_bit (i, bits)) + set_mask |=BIT (i); +else + clear_mask |=BIT (i); + } + }
just use mask to invert the mask for the CODR
#define BITS_MASK(bits) (((bits) == 32) ? ~0U : (BIT(bits) - 1))
uint32_t set_mask = *mask & BITS_MASK(chip->ngpio);; uint32_t clear_mask = ~set_mask; writel_relaxed(set_mask, pio + PIO_SODR); writel_relaxed(clear_mask, pio + PIO_CODR);
Best Regards,
J.
Quoted 19 lines
drivers/pinctrl/pinctrl-at91.c +6
-0+ +writel_relaxed (set_mask, pio +PIO_SODR ); +writel_relaxed (clear_mask, pio +PIO_CODR ); +} +static int at91_gpio_direction_output (struct gpio_chip *chip,unsigned offset,int val) {@@ -1692,6 +1719,7 @@ static struct gpio_chip at91_gpio_template = { .get = at91_gpio_get, .direction_output = at91_gpio_direction_output, .set = at91_gpio_set, + .set_multiple = at91_gpio_set_multiple, .dbg_show = at91_gpio_dbg_show, .can_sleep = false, .ngpio = MAX_NB_GPIO_PER_BANK,Signature · 1 line
2.3.3