Skip to contentSkip to conversation

blackfin: gpio: Use proper mask for comparing function

PATCH New Axel Lin 2 participants 2 messages Jun 28, 2013 – Jul 1, 2013

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 blackfin: gpio: Use proper mask for comparing function

The function return from P_FUNCT2MUX(per) takes 2 bits, however for BF537_FAMILY with offset != 1 the function is 1 bit.

Also has small refactor for better readability.
In portmux_setup(), it looks odd having "muxreg &= ~(3 << 1);" while in current code we do muxreg |= (function << offset);.

---
 arch/blackfin/cpu/gpio.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/blackfin/cpu/gpio.c +6 -5
index f74a0b7..c4cddaf 100644
@@ -247,7 +247,7 @@ static struct {
 
 static void portmux_setup(unsigned short per)
 {
-	u16 y, offset, muxreg;
+	u16 y, offset, muxreg, mask;
 	u16 function = P_FUNCT2MUX(per);
 
 	for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) {
@@ -258,12 +258,13 @@ static void portmux_setup(unsigned short per)
 			offset = port_mux_lut[y].offset;
 			muxreg = bfin_read_PORT_MUX();
 
-			if (offset != 1)
-				muxreg &= ~(1 << offset);
+			if (offset == 1)
+				mask = 3;
 			else
-				muxreg &= ~(3 << 1);
+				mask = 1;
 
-			muxreg |= (function << offset);
+			muxreg &= ~(mask << offset);
+			muxreg |= ((function & mask) << offset);
 			bfin_write_PORT_MUX(muxreg);
 		}
 	}
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH 1/1 blackfin: gpio: Use proper mask for comparing function

Quoted 52 lines · Axel Lin

The function return from P_FUNCT2MUX(per) takes 2 bits, however for BF537_FAMILY with offset != 1 the function is 1 bit.

Also has small refactor for better readability.
In portmux_setup(), it looks odd having "muxreg &= ~(3 << 1);" while in current code we do muxreg |= (function << offset);.

---
 arch/blackfin/cpu/gpio.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/blackfin/cpu/gpio.c +6 -6
index f74a0b7..c4cddaf 100644
@@ -247,7 +247,7 @@ static struct {
 
 static void portmux_setup(unsigned short per)
 {
-       u16 y, offset, muxreg;
+       u16 y, offset, muxreg, mask;
        u16 function = P_FUNCT2MUX(per);
 
        for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) {
@@ -258,12 +258,13 @@ static void portmux_setup(unsigned short per)
                        offset = port_mux_lut[y].offset;
                        muxreg = bfin_read_PORT_MUX();
 
-                       if (offset != 1)
-                               muxreg &= ~(1 << offset);
+                       if (offset == 1)
+                               mask = 3;
                        else
-                               muxreg &= ~(3 << 1);
+                               mask = 1;
 
-                       muxreg |= (function << offset);
+                       muxreg &= ~(mask << offset);
+                       muxreg |= ((function & mask) << offset);
                        bfin_write_PORT_MUX(muxreg);
                }
        }
--

1.8.1.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot