* [PATCH] gpio: gpio-pca953x: no interrupts with 4-bit devices
@ 2016-03-09 12:37 mrpace2
2016-03-09 13:05 ` Alexander Stein
0 siblings, 1 reply; 4+ messages in thread
From: mrpace2 @ 2016-03-09 12:37 UTC (permalink / raw)
To: linux-gpio
I/O expanders with less than 8 I/O (PCA9536 and PCA9537, currently) fail
to invoke interrupt handlers because the NBANK macro
#define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
incorrectly calculates no banks for these devices. As a result,
pca953x_irq_pending() never sets the trigger_seen flag.
The patch below fixed the issue by changing the NBANK() macro.
Signed-off-by: Frank Edelhaeuser <mrpace2 <at> gmail.com>
---
diff -Nur a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
--- a/drivers/gpio/gpio-pca953x.c 2016-03-08 00:00:00.000000000 +0000
+++ b/drivers/gpio/gpio-pca953x.c 2016-03-08 00:00:00.000000000 +0000
@@ -86,7 +86,7 @@
#define MAX_BANK 5
#define BANK_SZ 8
-#define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
+#define NBANK(chip) (((chip->gpio_chip.ngpio - 1) / BANK_SZ) + 1)
struct pca953x_chip {
unsigned gpio_start;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: gpio-pca953x: no interrupts with 4-bit devices
2016-03-09 12:37 [PATCH] gpio: gpio-pca953x: no interrupts with 4-bit devices mrpace2
@ 2016-03-09 13:05 ` Alexander Stein
2016-03-10 10:15 ` [PATCH v2] " mrpace2
0 siblings, 1 reply; 4+ messages in thread
From: Alexander Stein @ 2016-03-09 13:05 UTC (permalink / raw)
To: mrpace2; +Cc: linux-gpio
On Wednesday 09 March 2016 12:37:09, mrpace2@gmail.com wrote:
> I/O expanders with less than 8 I/O (PCA9536 and PCA9537, currently) fail
> to invoke interrupt handlers because the NBANK macro
>
> #define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
> incorrectly calculates no banks for these devices. As a result,
> pca953x_irq_pending() never sets the trigger_seen flag.
>
> The patch below fixed the issue by changing the NBANK() macro.
>
> Signed-off-by: Frank Edelhaeuser <mrpace2 <at> gmail.com>
> ---
> diff -Nur a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
> --- a/drivers/gpio/gpio-pca953x.c 2016-03-08 00:00:00.000000000 +0000
> +++ b/drivers/gpio/gpio-pca953x.c 2016-03-08 00:00:00.000000000 +0000
> @@ -86,7 +86,7 @@
> #define MAX_BANK 5
> #define BANK_SZ 8
>
> -#define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
> +#define NBANK(chip) (((chip->gpio_chip.ngpio - 1) / BANK_SZ) + 1)
If ngpio is 0 (e.g. wrong platform device) this underflows and gets a completly wrong result. But I see more of those "ngpio - 1" all over the place.
What about?
> #define NBANK(chip) (((chip->gpio_chip.ngpio + (BANK_SZ - 1)) / BANK_SZ))
Best regards,
Alexander
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] gpio: gpio-pca953x: no interrupts with 4-bit devices
2016-03-09 13:05 ` Alexander Stein
@ 2016-03-10 10:15 ` mrpace2
2016-03-10 18:02 ` Grygorii Strashko
0 siblings, 1 reply; 4+ messages in thread
From: mrpace2 @ 2016-03-10 10:15 UTC (permalink / raw)
To: linux-gpio
The NBANK macro can be extended in order to avoid the underflow:
#define NBANK(chip) (chip->gpio_chip.ngpio == 0 ? 0 : \
((chip->gpio_chip.ngpio + (BANK_SZ - 1)) / BANK_SZ))
Resending a modified patch.
Signed-off-by: Frank Edelhaeuser <mrpace2 <at> gmail.com>
---
diff -Nur a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
--- a/drivers/gpio/gpio-pca953x.c 2016-03-10 02:34:56.012345678 +0000
+++ b/drivers/gpio/gpio-pca953x.c 2016-03-10 02:34:56.012345678 +0000
@@ -86,7 +86,8 @@
#define MAX_BANK 5
#define BANK_SZ 8
-#define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
+#define NBANK(chip) (chip->gpio_chip.ngpio == 0 ? 0 : \
+ ((chip->gpio_chip.ngpio + (BANK_SZ - 1)) / BANK_SZ))
struct pca953x_chip {
unsigned gpio_start;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] gpio: gpio-pca953x: no interrupts with 4-bit devices
2016-03-10 10:15 ` [PATCH v2] " mrpace2
@ 2016-03-10 18:02 ` Grygorii Strashko
0 siblings, 0 replies; 4+ messages in thread
From: Grygorii Strashko @ 2016-03-10 18:02 UTC (permalink / raw)
To: mrpace2, linux-gpio
On 03/10/2016 05:15 PM, mrpace2@gmail.com wrote:
> The NBANK macro can be extended in order to avoid the underflow:
>
> #define NBANK(chip) (chip->gpio_chip.ngpio == 0 ? 0 : \
> ((chip->gpio_chip.ngpio + (BANK_SZ - 1)) / BANK_SZ))
> Resending a modified patch.
>
> Signed-off-by: Frank Edelhaeuser <mrpace2 <at> gmail.com>
> ---
> diff -Nur a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
> --- a/drivers/gpio/gpio-pca953x.c 2016-03-10 02:34:56.012345678 +0000
> +++ b/drivers/gpio/gpio-pca953x.c 2016-03-10 02:34:56.012345678 +0000
> @@ -86,7 +86,8 @@
> #define MAX_BANK 5
> #define BANK_SZ 8
>
> -#define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
> +#define NBANK(chip) (chip->gpio_chip.ngpio == 0 ? 0 : \
> + ((chip->gpio_chip.ngpio + (BANK_SZ - 1)) / BANK_SZ))
>
And finally this DIV_ROUND_UP:) Right?
--
regards,
-grygorii
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-03-10 18:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-09 12:37 [PATCH] gpio: gpio-pca953x: no interrupts with 4-bit devices mrpace2
2016-03-09 13:05 ` Alexander Stein
2016-03-10 10:15 ` [PATCH v2] " mrpace2
2016-03-10 18:02 ` Grygorii Strashko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox