Skip to contentSkip to conversation

gpio: pxa: simplify BANK_OFF macro offset calculation

PATCH In review Rob Herring 3 participants 3 messages Mar 2, 2015 – Mar 9, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: pxa: simplify BANK_OFF macro offset calculation

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.

Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 drivers/gpio/gpio-pxa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/gpio-pxa.c +1 -2
index e45637b..d2324b9 100644
@@ -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;
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Rob Herring

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.

Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 drivers/gpio/gpio-pxa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/gpio-pxa.c +0 -0
index e45637b..d2324b9 100644

drivers/gpio/gpio-pxa.c line 64

Quoted 6 lines
drivers/gpio/gpio-pxa.c +1 -2
@@ -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.