Skip to contentSkip to conversation

reset: stm32: Fix bank and offset computation

PATCH In review Patrice Chotard 2 participants 4 messages Apr 28, 2021 – May 28, 2021

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

PATCH 1/1 reset: stm32: Fix bank and offset computation

BITS_PER_LONG is used to represent register's size which is 32. But when compiled on arch64, BITS_PER_LONG is then equal to 64.

Fix bank and offset computation to make it work on arch32 and arch64 and ensure that register's size is always equal to 32.

---

 drivers/reset/stm32-reset.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/reset/stm32-reset.c +4 -4
index daa2e47ebb..bbc6b135a9 100644
@@ -40,8 +40,8 @@ static int stm32_reset_free(struct reset_ctl *reset_ctl)
 static int stm32_reset_assert(struct reset_ctl *reset_ctl)
 {
 	struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
-	int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
-	int offset = reset_ctl->id % BITS_PER_LONG;
+	int bank = (reset_ctl->id / (sizeof(u32) * BITS_PER_BYTE)) * 4;
+	int offset = reset_ctl->id % (sizeof(u32) * BITS_PER_BYTE);
 
 	dev_dbg(reset_ctl->dev, "reset id = %ld bank = %d offset = %d)\n",
 		reset_ctl->id, bank, offset);
@@ -61,8 +61,8 @@ static int stm32_reset_assert(struct reset_ctl *reset_ctl)
 static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
 {
 	struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
-	int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
-	int offset = reset_ctl->id % BITS_PER_LONG;
+	int bank = (reset_ctl->id / (sizeof(u32) * BITS_PER_BYTE)) * 4;
+	int offset = reset_ctl->id % (sizeof(u32) * BITS_PER_BYTE);
 
 	dev_dbg(reset_ctl->dev, "reset id = %ld bank = %d offset = %d)\n",
 		reset_ctl->id, bank, offset);
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 reset: stm32: Fix bank and offset computation

Hi Patrice,

Quoted 29 lines · Patrice Chotard

BITS_PER_LONG is used to represent register's size which is 32. But when compiled on arch64, BITS_PER_LONG is then equal to 64.

Fix bank and offset computation to make it work on arch32 and arch64 and ensure that register's size is always equal to 32.

---

  drivers/reset/stm32-reset.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/reset/stm32-reset.c +2 -2
index daa2e47ebb..bbc6b135a9 100644
@@ -40,8 +40,8 @@ static int stm32_reset_free(struct reset_ctl *reset_ctl)
  static int stm32_reset_assert(struct reset_ctl *reset_ctl)
  {
  	struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
-	int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
-	int offset = reset_ctl->id % BITS_PER_LONG;
+	int bank = (reset_ctl->id / (sizeof(u32) * BITS_PER_BYTE)) * 4;
+	int offset = reset_ctl->id % (sizeof(u32) * BITS_PER_BYTE);
 
  	dev_dbg(reset_ctl->dev, "reset id = %ld bank = %d offset = %d)\n",
  		reset_ctl->id, bank, offset);

drivers/reset/stm32-reset.c static int stm32_reset_assert(struct reset_ctl *reset_ctl) · line 68

Quoted 10 lines
drivers/reset/stm32-reset.c +2 -2
@@ -61,8 +61,8 @@ static int stm32_reset_assert(struct reset_ctl *reset_ctl)
  static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
  {
  	struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
-	int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
-	int offset = reset_ctl->id % BITS_PER_LONG;
+	int bank = (reset_ctl->id / (sizeof(u32) * BITS_PER_BYTE)) * 4;
+	int offset = reset_ctl->id % (sizeof(u32) * BITS_PER_BYTE);
 
  	dev_dbg(reset_ctl->dev, "reset id = %ld bank = %d offset = %d)\n",
  		reset_ctl->id, bank, offset);

Thanks
Patrick

Reviewed-by on v1 1/1
#2 lore raw
In reply to Patrice Chotard

Hi,

Quoted 6 lines · Patrice Chotard

BITS_PER_LONG is used to represent register's size which is 32. But when compiled on arch64, BITS_PER_LONG is then equal to 64.

Fix bank and offset computation to make it work on arch32 and arch64 and ensure that register's size is always equal to 32.

Quoted 7 lines

---

  drivers/reset/stm32-reset.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

Thanks
Patrick

#3 lore raw
In reply to Patrice Chotard
Quoted 6 lines · Patrice Chotard

BITS_PER_LONG is used to represent register's size which is 32. But when compiled on arch64, BITS_PER_LONG is then equal to 64.

Fix bank and offset computation to make it work on arch32 and arch64 and ensure that register's size is always equal to 32.

Quoted 7 lines

---

  drivers/reset/stm32-reset.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

Applied to u-boot-stm/master, thanks!

Regards
Patrick