Skip to contentSkip to conversation

pinctrl: aspeed: Fix ast2500 strap register write logic

PATCH Superseded Yong Li 2 participants 2 messages Aug 11, 2017 – Aug 14, 2017

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Yong Li

author
#0 lore raw

PATCH v2 1/1 pinctrl: aspeed: Fix ast2500 strap register write logic

On AST2500, the hardware strap register(SCU70) only accepts write ‘1’, to clear it to ‘0’, must set bits(write ‘1’) to SCU7C

---
 drivers/pinctrl/aspeed/pinctrl-aspeed.c | 20 ++++++++++++++++++--
 drivers/pinctrl/aspeed/pinctrl-aspeed.h |  1 +
 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/pinctrl/aspeed/pinctrl-aspeed.c +18 -2
index a86a4d6..9d2b2e9 100644
@@ -183,6 +183,7 @@ static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr,
 {
 	int ret;
 	int i;
+	unsigned int rev_id;
 
 	for (i = 0; i < expr->ndescs; i++) {
 		const struct aspeed_sig_desc *desc = &expr->descs[i];
@@ -213,8 +214,23 @@ static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr,
 		if (desc->ip == ASPEED_IP_SCU && desc->reg == HW_STRAP2)
 			continue;
 
-		ret = regmap_update_bits(maps[desc->ip], desc->reg,
-					 desc->mask, val);
+		/* On AST2500, Set bits in SCU7C are cleared from SCU70 */
+		if (desc->ip == ASPEED_IP_SCU && desc->reg == HW_STRAP1 &&
+			val == 0) {
+			ret = regmap_read(maps[ASPEED_IP_SCU],
+				HW_REVISION_ID, &rev_id);
+			if (ret < 0)
+				return ret;
+
+			if (0x04 == ((rev_id >> 24) & 0xff))
+				ret = regmap_update_bits(maps[desc->ip],
+					HW_REVISION_ID, desc->mask, desc->mask);
+			else
+				ret = regmap_update_bits(maps[desc->ip],
+					desc->reg, desc->mask, val);
+		} else
+			ret = regmap_update_bits(maps[desc->ip], desc->reg,
+				desc->mask, val);
 
 		if (ret)
 			return ret;
drivers/pinctrl/aspeed/pinctrl-aspeed.h +1 -0
index fa125db..d4d7f03 100644
@@ -251,6 +251,7 @@
 #define SCU3C           0x3C /* System Reset Control/Status Register */
 #define SCU48           0x48 /* MAC Interface Clock Delay Setting */
 #define HW_STRAP1       0x70 /* AST2400 strapping is 33 bits, is split */
+#define HW_REVISION_ID  0x7C /* Silicon revision ID register */
 #define SCU80           0x80 /* Multi-function Pin Control #1 */
 #define SCU84           0x84 /* Multi-function Pin Control #2 */
 #define SCU88           0x88 /* Multi-function Pin Control #3 */
Signature · 1 line
2.7.4
#1 lore raw

Hi Yong,

Quoted 29 lines · Yong Li

On AST2500, the hardware strap register(SCU70) only accepts write ‘1’, to clear it to ‘0’, must set bits(write  ‘1’) to SCU7C

Quoted 1 line

---
 drivers/pinctrl/aspeed/pinctrl-aspeed.c | 20 ++++++++++++++++++-- drivers/pinctrl/aspeed/pinctrl-aspeed.h |  1 +

 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/pinctrl/aspeed/pinctrl-aspeed.c +0 -0
index a86a4d6..9d2b2e9 100644
@@ -183,6 +183,7 @@ static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr,
  {
 >  	int ret;
 >  	int i;
 > +	unsigned int rev_id;

Quoted 2 lines

  for (i = 0; i < expr->ndescs; i++) {
  const struct aspeed_sig_desc *desc = &expr->descs[i];

drivers/pinctrl/aspeed/pinctrl-aspeed.c +0 -0
@@ -213,8 +214,23 @@ static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr,
 >  		if (desc->ip == ASPEED_IP_SCU && desc->reg == HW_STRAP2)
 >  			continue;

Quoted 4 lines
drivers/pinctrl/aspeed/pinctrl-aspeed.c +2 -2
-		ret = regmap_update_bits(maps[desc->ip], desc->reg,
-					 desc->mask, val);
+		/* On AST2500, Set bits in SCU7C are cleared from SCU70 */
+		if (desc->ip == ASPEED_IP_SCU && desc->reg == HW_STRAP1 &&

drivers/pinctrl/aspeed/pinctrl-aspeed.c static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr, · line 219

Quoted 1 line
drivers/pinctrl/aspeed/pinctrl-aspeed.c +1 -0
+			val == 0) {

The AST2500 strapping register contains several multi-bit bit-fields. Currently we know we'll only reach this test if we're modifying the GPIO passthrough bits for bank D and E (bits 21 and 22 respectively), so the 'val == 0' test is functional but I wonder if we shouldn't be more flexible. If we're more flexible here then we may only need to modify the strap register test above this hunk to change the behaviour, rather than needing to rework your additions here as well. More on this below.

drivers/pinctrl/aspeed/pinctrl-aspeed.c static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr, · line 227

Quoted 8 lines
drivers/pinctrl/aspeed/pinctrl-aspeed.c +1 -0
+			ret = regmap_read(maps[ASPEED_IP_SCU],

drivers/pinctrl/aspeed/pinctrl-aspeed.c static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr, · line 223

Quoted 3 lines
drivers/pinctrl/aspeed/pinctrl-aspeed.c +3 -0
+				HW_REVISION_ID, &rev_id);
+			if (ret < 0)
+				return ret;

+

Quoted 2 lines
(quoted diff) +2 -0
+			if (0x04 == ((rev_id >> 24) & 0xff))
+				ret = regmap_update_bits(maps[desc->ip],
drivers/pinctrl/aspeed/pinctrl-aspeed.c +1 -0
+					HW_REVISION_ID, desc->mask, desc->mask);

regmap_update_bits() will do a read-modify-write operation whilst only taking the regmap lock once, making the modification atomic. However, HW_REVISION_ID is a W1C (write 1 to clear) register associated with SCU70, so we don't actually need the read operation under the lock. We can simply use regmap_write() here.

Addressing my comment on 'val == 0' above, I think we can remove that test if we instead write this as:

    ret = regmap_write(maps[    desc->ip], HW_REVISION_ID, (~val & desc->mask));

That way if we ever expand the HW_STRAP1 capabilites to cover the bitfields (e.g. maybe we want to be able to dynamically switch SPI into debug mode) the code should (hopefully) just work.

Cheers,

Andrew

Quoted 21 lines
drivers/pinctrl/aspeed/pinctrl-aspeed.c +1 -0
+			else
Quoted 3 lines
drivers/pinctrl/aspeed/pinctrl-aspeed.c +3 -0
+				ret = regmap_update_bits(maps[desc->ip],
+					desc->reg, desc->mask, val);
+		} else
drivers/pinctrl/aspeed/pinctrl-aspeed.c +1 -0
+			ret = regmap_update_bits(maps[desc->ip], desc->reg,

drivers/pinctrl/aspeed/pinctrl-aspeed.c static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr, · line 233

Quoted 1 line
drivers/pinctrl/aspeed/pinctrl-aspeed.c +1 -0
+				desc->mask, val);

Quoted 2 lines

  if (ret)
  return ret;

drivers/pinctrl/aspeed/pinctrl-aspeed.h +1 -0
index fa125db..d4d7f03 100644
@@ -251,6 +251,7 @@
  #define SCU3C           0x3C /* System Reset Control/Status Register */
  #define SCU48           0x48 /* MAC Interface Clock Delay Setting */
  #define HW_STRAP1       0x70 /* AST2400 strapping is 33 bits, is split */
+#define HW_REVISION_ID  0x7C /* Silicon revision ID register */
  #define SCU80           0x80 /* Multi-function Pin Control #1 */
  #define SCU84           0x84 /* Multi-function Pin Control #2 */
  #define SCU88           0x88 /* Multi-function Pin Control #3 */