Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1651462 > unrolled thread

[PATCH v3 08/10] gpio: exar: Refactor address and bit calculations

Started byJan Kiszka <jan.kiszka@siemens.com>
First post2017-05-26 18:10 +0200
Last post2017-05-29 14:40 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v3 08/10] gpio: exar: Refactor address and bit calculations Jan Kiszka <jan.kiszka@siemens.com> - 2017-05-26 18:10 +0200
    Re: [PATCH v3 08/10] gpio: exar: Refactor address and bit calculations Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-05-27 15:50 +0200
    Re: [PATCH v3 08/10] gpio: exar: Refactor address and bit calculations Linus Walleij <linus.walleij@linaro.org> - 2017-05-29 14:40 +0200

#1651462 — [PATCH v3 08/10] gpio: exar: Refactor address and bit calculations

FromJan Kiszka <jan.kiszka@siemens.com>
Date2017-05-26 18:10 +0200
Subject[PATCH v3 08/10] gpio: exar: Refactor address and bit calculations
Message-ID<tLpYn-83M-37@gated-at.bofh.it>
Make the address and bit calculation more friendly for introducing a
"first pin" offset later on. The new form is also more compact and
regular.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 drivers/gpio/gpio-exar.c | 38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c
index 1a629831d45b..d13bf20b8639 100644
--- a/drivers/gpio/gpio-exar.c
+++ b/drivers/gpio/gpio-exar.c
@@ -51,11 +51,11 @@ static void exar_update(struct gpio_chip *chip, unsigned int reg, int val,
 static int exar_set_direction(struct gpio_chip *chip, int direction,
 			      unsigned int offset)
 {
-	unsigned int bank = offset / 8;
-	unsigned int addr;
+	unsigned int addr = offset / 8 ?
+		EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
+	unsigned int bit  = offset % 8;
 
-	addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
-	exar_update(chip, addr, direction, offset % 8);
+	exar_update(chip, addr, direction, bit);
 	return 0;
 }
 
@@ -73,36 +73,30 @@ static int exar_get(struct gpio_chip *chip, unsigned int reg)
 
 static int exar_get_direction(struct gpio_chip *chip, unsigned int offset)
 {
-	unsigned int bank = offset / 8;
-	unsigned int addr;
-	int val;
+	unsigned int addr = offset / 8 ?
+		EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
+	unsigned int bit  = offset % 8;
 
-	addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
-	val = exar_get(chip, addr) & BIT(offset % 8);
-
-	return !!val;
+	return !!(exar_get(chip, addr) & BIT(bit));
 }
 
 static int exar_get_value(struct gpio_chip *chip, unsigned int offset)
 {
-	unsigned int bank = offset / 8;
-	unsigned int addr;
-	int val;
-
-	addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
-	val = exar_get(chip, addr) & BIT(offset % 8);
+	unsigned int addr = offset / 8 ?
+		EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
+	unsigned int bit  = offset % 8;
 
-	return !!val;
+	return !!(exar_get(chip, addr) & BIT(bit));
 }
 
 static void exar_set_value(struct gpio_chip *chip, unsigned int offset,
 			   int value)
 {
-	unsigned int bank = offset / 8;
-	unsigned int addr;
+	unsigned int addr = offset / 8 ?
+		EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
+	unsigned int bit  = offset % 8;
 
-	addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
-	exar_update(chip, addr, value, offset % 8);
+	exar_update(chip, addr, value, bit);
 }
 
 static int exar_direction_output(struct gpio_chip *chip, unsigned int offset,
-- 
2.12.0

[toc] | [next] | [standalone]


#1651878

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-05-27 15:50 +0200
Message-ID<tLKgp-4Gs-1@gated-at.bofh.it>
In reply to#1651462
On Fri, May 26, 2017 at 7:02 PM, Jan Kiszka <jan.kiszka@siemens.com> wrote:
> Make the address and bit calculation more friendly for introducing a
> "first pin" offset later on. The new form is also more compact and
> regular.

I think this should be folded to patch 9 since the latter touches near
all lines you touched here.

-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [next] | [standalone]


#1652496

FromLinus Walleij <linus.walleij@linaro.org>
Date2017-05-29 14:40 +0200
Message-ID<tMs7M-8i4-29@gated-at.bofh.it>
In reply to#1651462
On Fri, May 26, 2017 at 6:02 PM, Jan Kiszka <jan.kiszka@siemens.com> wrote:

> Make the address and bit calculation more friendly for introducing a
> "first pin" offset later on. The new form is also more compact and
> regular.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

Acked-by: Linus Walleij <linus.walleij@linaro.org>

Whether you go with a separate patch or as Andy suggests.

Yours,
Linus Walleij

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web