linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension
@ 2020-09-30 14:20 Andy Shevchenko
  2020-09-30 14:20 ` [PATCH v1 2/2] gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andy Shevchenko @ 2020-09-30 14:20 UTC (permalink / raw)
  To: Linus Walleij, linux-gpio, Bartosz Golaszewski; +Cc: Andy Shevchenko

In IRQ handler we have to clear bitmap before use. Currently
the GCC extension has been used for that. For sake of the consistency
switch to bitmap API. As expected bloat-o-meter shows no difference
in the object size.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pca953x.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 0a49ab62cbbd..3f24cfabb1d7 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -814,10 +814,12 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
 {
 	struct pca953x_chip *chip = devid;
 	struct gpio_chip *gc = &chip->gpio_chip;
-	DECLARE_BITMAP(pending, MAX_LINE) = {};
+	DECLARE_BITMAP(pending, MAX_LINE);
 	int level;
 	bool ret;
 
+	bitmap_zero(pending, MAX_LINE);
+
 	mutex_lock(&chip->i2c_lock);
 	ret = pca953x_irq_pending(chip, pending);
 	mutex_unlock(&chip->i2c_lock);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 2/2] gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x
  2020-09-30 14:20 [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension Andy Shevchenko
@ 2020-09-30 14:20 ` Andy Shevchenko
  2020-10-01  7:27   ` Bartosz Golaszewski
  2020-10-01  7:26 ` [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension Bartosz Golaszewski
  2020-10-01  8:02 ` Linus Walleij
  2 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2020-09-30 14:20 UTC (permalink / raw)
  To: Linus Walleij, linux-gpio, Bartosz Golaszewski; +Cc: Andy Shevchenko

When driver has been converted to the bitmap API the non-bitmap functions
started behaving differently on 32-bit BE architectures since the bytes in
two consequent unsigned longs are in different order in comparison to byte
array. Hence if the chip had had more than 32 lines the memset() call over
it would have not set up upper lines correctly.
Although it's currently a theoretical case (no supported chips of this type
has 32+ lines), it's better to provide a clean code to avoid people thinking
this is okay and potentially producing not fully working things.

Fixes: 35d13d94893f ("gpio: pca953x: convert to use bitmap API")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pca953x.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 3f24cfabb1d7..6263a4d55f8b 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -942,6 +942,7 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert)
 static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
 {
 	DECLARE_BITMAP(val, MAX_LINE);
+	unsigned int i;
 	int ret;
 
 	ret = device_pca95xx_init(chip, invert);
@@ -949,7 +950,9 @@ static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
 		goto out;
 
 	/* To enable register 6, 7 to control pull up and pull down */
-	memset(val, 0x02, NBANK(chip));
+	for (i = 0; i < NBANK(chip); i++)
+		bitmap_set_value8(val, 0x02, i * BANK_SZ);
+
 	ret = pca953x_write_regs(chip, PCA957X_BKEN, val);
 	if (ret)
 		goto out;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension
  2020-09-30 14:20 [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension Andy Shevchenko
  2020-09-30 14:20 ` [PATCH v1 2/2] gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x Andy Shevchenko
@ 2020-10-01  7:26 ` Bartosz Golaszewski
  2020-10-01  8:02 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2020-10-01  7:26 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Linus Walleij, linux-gpio

On Wed, Sep 30, 2020 at 4:20 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> In IRQ handler we have to clear bitmap before use. Currently
> the GCC extension has been used for that. For sake of the consistency
> switch to bitmap API. As expected bloat-o-meter shows no difference
> in the object size.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpio-pca953x.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
> index 0a49ab62cbbd..3f24cfabb1d7 100644
> --- a/drivers/gpio/gpio-pca953x.c
> +++ b/drivers/gpio/gpio-pca953x.c
> @@ -814,10 +814,12 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
>  {
>         struct pca953x_chip *chip = devid;
>         struct gpio_chip *gc = &chip->gpio_chip;
> -       DECLARE_BITMAP(pending, MAX_LINE) = {};
> +       DECLARE_BITMAP(pending, MAX_LINE);
>         int level;
>         bool ret;
>
> +       bitmap_zero(pending, MAX_LINE);
> +
>         mutex_lock(&chip->i2c_lock);
>         ret = pca953x_irq_pending(chip, pending);
>         mutex_unlock(&chip->i2c_lock);
> --
> 2.28.0
>

Makes sense.

Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 2/2] gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x
  2020-09-30 14:20 ` [PATCH v1 2/2] gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x Andy Shevchenko
@ 2020-10-01  7:27   ` Bartosz Golaszewski
  0 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2020-10-01  7:27 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Linus Walleij, linux-gpio

On Wed, Sep 30, 2020 at 4:20 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> When driver has been converted to the bitmap API the non-bitmap functions
> started behaving differently on 32-bit BE architectures since the bytes in
> two consequent unsigned longs are in different order in comparison to byte
> array. Hence if the chip had had more than 32 lines the memset() call over
> it would have not set up upper lines correctly.
> Although it's currently a theoretical case (no supported chips of this type
> has 32+ lines), it's better to provide a clean code to avoid people thinking
> this is okay and potentially producing not fully working things.
>
> Fixes: 35d13d94893f ("gpio: pca953x: convert to use bitmap API")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpio-pca953x.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
> index 3f24cfabb1d7..6263a4d55f8b 100644
> --- a/drivers/gpio/gpio-pca953x.c
> +++ b/drivers/gpio/gpio-pca953x.c
> @@ -942,6 +942,7 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert)
>  static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
>  {
>         DECLARE_BITMAP(val, MAX_LINE);
> +       unsigned int i;
>         int ret;
>
>         ret = device_pca95xx_init(chip, invert);
> @@ -949,7 +950,9 @@ static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
>                 goto out;
>
>         /* To enable register 6, 7 to control pull up and pull down */
> -       memset(val, 0x02, NBANK(chip));
> +       for (i = 0; i < NBANK(chip); i++)
> +               bitmap_set_value8(val, 0x02, i * BANK_SZ);
> +
>         ret = pca953x_write_regs(chip, PCA957X_BKEN, val);
>         if (ret)
>                 goto out;
> --
> 2.28.0
>

Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension
  2020-09-30 14:20 [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension Andy Shevchenko
  2020-09-30 14:20 ` [PATCH v1 2/2] gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x Andy Shevchenko
  2020-10-01  7:26 ` [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension Bartosz Golaszewski
@ 2020-10-01  8:02 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2020-10-01  8:02 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: open list:GPIO SUBSYSTEM, Bartosz Golaszewski

On Wed, Sep 30, 2020 at 4:20 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> In IRQ handler we have to clear bitmap before use. Currently
> the GCC extension has been used for that. For sake of the consistency
> switch to bitmap API. As expected bloat-o-meter shows no difference
> in the object size.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Both patches applied!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-01  8:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 14:20 [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension Andy Shevchenko
2020-09-30 14:20 ` [PATCH v1 2/2] gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x Andy Shevchenko
2020-10-01  7:27   ` Bartosz Golaszewski
2020-10-01  7:26 ` [PATCH v1 1/2] gpio: pca953x: Use bitmap API over implicit GCC extension Bartosz Golaszewski
2020-10-01  8:02 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).