gpio: pxa: simplify BANK_OFF macro offset calculation
diff mbox

Message ID 1425331858-6018-1-git-send-email-robh@kernel.org
State New
Headers show

Commit Message

Rob Herring March 2, 2015, 9:30 p.m. UTC
The macro BANK_OFF which calculates the base offset for each GPIO port.
The macro is needlessly complex and unreadable. Simplify the
calculation to a simple math operation.

Signed-off-by: Rob Herring <robh@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Alexandre Courbot <gnurou@gmail.com>
Cc: linux-gpio@vger.kernel.org
---
 drivers/gpio/gpio-pxa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Alexandre Courbot March 3, 2015, 7:50 a.m. UTC | #1
On Tue, Mar 3, 2015 at 6:30 AM, Rob Herring <robh@kernel.org> wrote:
> The macro BANK_OFF which calculates the base offset for each GPIO port.
> The macro is needlessly complex and unreadable. Simplify the
> calculation to a simple math operation.
>
> Signed-off-by: Rob Herring <robh@kernel.org>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Alexandre Courbot <gnurou@gmail.com>
> Cc: linux-gpio@vger.kernel.org
> ---
>  drivers/gpio/gpio-pxa.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
> index e45637b..d2324b9 100644
> --- a/drivers/gpio/gpio-pxa.c
> +++ b/drivers/gpio/gpio-pxa.c
> @@ -61,8 +61,7 @@
>  #define GAFR_OFFSET    0x54
>  #define ED_MASK_OFFSET 0x9C    /* GPIO edge detection for AP side */
>
> -#define BANK_OFF(n)    (((n) < 3) ? (n) << 2 : ((n) > 5 ? 0x200 : 0x100)       \
> -                       + (((n) % 3) << 2))
> +#define BANK_OFF(n)    (((n) / 3) << 8) + (((n) % 3) << 2)

Seems to indeed compute the same output as the previous macro in a
more readable way.

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij March 9, 2015, 1:42 p.m. UTC | #2
On Mon, Mar 2, 2015 at 10:30 PM, Rob Herring <robh@kernel.org> wrote:

> The macro BANK_OFF which calculates the base offset for each GPIO port.
> The macro is needlessly complex and unreadable. Simplify the
> calculation to a simple math operation.
>
> Signed-off-by: Rob Herring <robh@kernel.org>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Alexandre Courbot <gnurou@gmail.com>
> Cc: linux-gpio@vger.kernel.org

Patch applied, thanks Rob.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index e45637b..d2324b9 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -61,8 +61,7 @@ 
 #define GAFR_OFFSET	0x54
 #define ED_MASK_OFFSET	0x9C	/* GPIO edge detection for AP side */
 
-#define BANK_OFF(n)	(((n) < 3) ? (n) << 2 : ((n) > 5 ? 0x200 : 0x100)	\
-			+ (((n) % 3) << 2))
+#define BANK_OFF(n)	(((n) / 3) << 8) + (((n) % 3) << 2)
 
 int pxa_last_gpio;
 static int irq_base;