Commit f70de486 authored by Sonic Zhang's avatar Sonic Zhang Committed by Steven Miao

Blackfin: bfin_gpio: Use proper mask for comparing pfunc

For BF537_FAMILY, when offset != 1, the mask is 1.
Thus add proper mask for comparing pfunc with function.

Also has small refactor for better readability.
In portmux_setup(), it looks odd having "pmux &= ~(3 << 1);"
while in current code we do pmux |= (function << offset);.
Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Signed-off-by: default avatarSonic Zhang <sonic.zhang@analog.com>
parent 5e01dc7b
...@@ -255,7 +255,7 @@ static int portmux_group_check(unsigned short per) ...@@ -255,7 +255,7 @@ static int portmux_group_check(unsigned short per)
u16 ident = P_IDENT(per); u16 ident = P_IDENT(per);
u16 function = P_FUNCT2MUX(per); u16 function = P_FUNCT2MUX(per);
s8 offset = port_mux[ident]; s8 offset = port_mux[ident];
u16 m, pmux, pfunc; u16 m, pmux, pfunc, mask;
if (offset < 0) if (offset < 0)
return 0; return 0;
...@@ -270,10 +270,12 @@ static int portmux_group_check(unsigned short per) ...@@ -270,10 +270,12 @@ static int portmux_group_check(unsigned short per)
continue; continue;
if (offset == 1) if (offset == 1)
pfunc = (pmux >> offset) & 3; mask = 3;
else else
pfunc = (pmux >> offset) & 1; mask = 1;
if (pfunc != function) {
pfunc = (pmux >> offset) & mask;
if (pfunc != (function & mask)) {
pr_err("pin group conflict! request pin %d func %d conflict with pin %d func %d\n", pr_err("pin group conflict! request pin %d func %d conflict with pin %d func %d\n",
ident, function, m, pfunc); ident, function, m, pfunc);
return -EINVAL; return -EINVAL;
...@@ -288,17 +290,20 @@ static void portmux_setup(unsigned short per) ...@@ -288,17 +290,20 @@ static void portmux_setup(unsigned short per)
u16 ident = P_IDENT(per); u16 ident = P_IDENT(per);
u16 function = P_FUNCT2MUX(per); u16 function = P_FUNCT2MUX(per);
s8 offset = port_mux[ident]; s8 offset = port_mux[ident];
u16 pmux; u16 pmux, mask;
if (offset == -1) if (offset == -1)
return; return;
pmux = bfin_read_PORT_MUX(); pmux = bfin_read_PORT_MUX();
if (offset != 1) if (offset == 1)
pmux &= ~(1 << offset); mask = 3;
else else
pmux &= ~(3 << 1); mask = 1;
pmux |= (function << offset);
pmux &= ~(mask << offset);
pmux |= ((function & mask) << offset);
bfin_write_PORT_MUX(pmux); bfin_write_PORT_MUX(pmux);
} }
#elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x) #elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment