Skip to contentSkip to conversation

drivers: clk: agilex: Correct EMAC clock source selection

PATCH Superseded Naresh Kumar Ravulapalli 4 participants 6 messages Aug 28, 2025 – Sep 2, 2025 Common clk

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drivers: clk: agilex: Correct EMAC clock source selection

Fix the incorrect bit masking and bit shift used to compute EMAC control which in turn is used to select EMAC clock from EMAC source A or B.

---
 drivers/clk/altera/clk-agilex.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/clk/altera/clk-agilex.c +6 -7
index e1ddd02f356..2ad8cfd8856 100644
@@ -1,6 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
  */
 
 #include <log.h>
@@ -11,6 +12,7 @@
 #include <dm/lists.h>
 #include <dm/util.h>
 #include <dt-bindings/clock/agilex-clock.h>
+#include <linux/bitfield.h>
 #include <linux/bitops.h>
 
 #include <asm/arch/clock_manager.h>
@@ -515,14 +517,11 @@ static u32 clk_get_emac_clk_hz(struct socfpga_clk_plat *plat, u32 emac_id)
 	/* Get EMAC clock source */
 	ctl = CM_REG_READL(plat, CLKMGR_PERPLL_EMACCTL);
 	if (emac_id == AGILEX_EMAC0_CLK)
-		ctl = (ctl >> CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_OFFSET) &
-		       CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_MASK;
+		ctl = FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_MASK, ctl);
 	else if (emac_id == AGILEX_EMAC1_CLK)
-		ctl = (ctl >> CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_OFFSET) &
-		       CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_MASK;
+		ctl = FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_MASK, ctl);
 	else if (emac_id == AGILEX_EMAC2_CLK)
-		ctl = (ctl >> CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_OFFSET) &
-		       CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_MASK;
+		ctl = FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_MASK, ctl);
 	else
 		return 0;
 
Signature · 1 line
2.35.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 68 lines

-----Original Message-----
From: Ravulapalli, Naresh Kumar <[email protected]>
Sent: Thursday, August 28, 2025 9:52 PM
To: [email protected]
Cc: Marek Vasut <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Tom Rini <[email protected]>; Ravulapalli, Naresh Kumar <[email protected]>
Subject: [PATCH v2] drivers: clk: agilex: Correct EMAC clock source selection

Fix the incorrect bit masking and bit shift used to compute EMAC control which in turn is used to select EMAC clock from EMAC source A or B.

Signed-off-by: Naresh Kumar Ravulapalli
<[email protected]>

---
 drivers/clk/altera/clk-agilex.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/clk/altera/clk-agilex.c +3 -2
index e1ddd02f356..2ad8cfd8856 100644
@@ -1,6 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
  */
 
 #include <log.h>
@@ -11,6 +12,7 @@
 #include <dm/lists.h>
 #include <dm/util.h>
 #include <dt-bindings/clock/agilex-clock.h>
+#include <linux/bitfield.h>
 #include <linux/bitops.h>
 
 #include <asm/arch/clock_manager.h>
@@ -515,14 +517,11 @@ static u32 clk_get_emac_clk_hz(struct
 socfpga_clk_plat *plat, u32 emac_id)
 	/* Get EMAC clock source */
 	ctl = CM_REG_READL(plat, CLKMGR_PERPLL_EMACCTL);
 	if (emac_id == AGILEX_EMAC0_CLK)
-		ctl = (ctl >>

CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_OFFSET) &

drivers/clk/altera/clk-agilex.c +1 -1
-		       CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_MASK;
+		ctl =

FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_MASK, ctl);

drivers/clk/altera/clk-agilex.c +0 -1
 	else if (emac_id == AGILEX_EMAC1_CLK)
-		ctl = (ctl >>

CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_OFFSET) &

drivers/clk/altera/clk-agilex.c +1 -1
-		       CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_MASK;
+		ctl =

FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_MASK, ctl);

drivers/clk/altera/clk-agilex.c +0 -1
 	else if (emac_id == AGILEX_EMAC2_CLK)
-		ctl = (ctl >>

CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_OFFSET) &

drivers/clk/altera/clk-agilex.c +1 -1
-		       CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_MASK;
+		ctl =

FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_MASK, ctl);

drivers/clk/altera/clk-agilex.c +0 -1
 	else
 		return 0;
 
--
Quoted 1 line

2.35.3

Best regards,
Tien Fong

#2 lore raw
Quoted 33 lines · Tien Fong
Quoted 33 lines

-----Original Message-----
From: Ravulapalli, Naresh Kumar <[email protected]>
Sent: Thursday, August 28, 2025 9:52 PM
To: [email protected]
Cc: Marek Vasut <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Tom Rini <[email protected]>; Ravulapalli, Naresh Kumar <[email protected]>
Subject: [PATCH v2] drivers: clk: agilex: Correct EMAC clock source selection

Fix the incorrect bit masking and bit shift used to compute EMAC control which in turn is used to select EMAC clock from EMAC source A or B.

Signed-off-by: Naresh Kumar Ravulapalli
<[email protected]>

---
 drivers/clk/altera/clk-agilex.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/clk/altera/clk-agilex.c +2 -1
index e1ddd02f356..2ad8cfd8856 100644
@@ -1,6 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
  */
 
Quoted 1 line

drivers/clk/altera/clk-agilex.c line 7

Quoted 1 line
drivers/clk/altera/clk-agilex.c +0 -0
 #include <log.h>

This is a NAK here. You can't just change the license, especially without calling it out in the commit message. And I'm not pleased with "make a small change, add/extend copyright". I'm not going to run around NAK'ing everything else you've sent but I'm going to ask you to stop doing that for changes that are not significant in size or scope.

Signature · 1 line
Tom
#3 lore raw

Hi Tom

Quoted 33 lines · Tom Rini
Quoted 32 lines · Tien Fong
Quoted 32 lines

-----Original Message-----
From: Ravulapalli, Naresh Kumar<[email protected]>
Sent: Thursday, August 28, 2025 9:52 PM
To:[email protected]
Cc: Marek Vasut<[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Tom Rini<[email protected]>; Ravulapalli, Naresh Kumar<[email protected]>
Subject: [PATCH v2] drivers: clk: agilex: Correct EMAC clock source selection

Fix the incorrect bit masking and bit shift used to compute EMAC control which in turn is used to select EMAC clock from EMAC source A or B.

Signed-off-by: Naresh Kumar Ravulapalli
<[email protected]>

---
  drivers/clk/altera/clk-agilex.c | 13 ++++++-------
  1 file changed, 6 insertions(+), 7 deletions(-)
drivers/clk/altera/clk-agilex.c +2 -1
index e1ddd02f356..2ad8cfd8856 100644
@@ -1,6 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0+
  /*
   * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
   */
 
Quoted 6 lines
Quoted 1 line

drivers/clk/altera/clk-agilex.c line 7

Quoted 1 line
drivers/clk/altera/clk-agilex.c +0 -0
  #include <log.h>

This is a NAK here. You can't just change the license, especially without calling it out in the commit message. And I'm not pleased with "make a small change, add/extend copyright". I'm not going to run around NAK'ing everything else you've sent but I'm going to ask you to stop doing that for changes that are not significant in size or scope.

Patch is about an important bug fix but I agree with your thoughts on license extension. I will revert the changes.

Kind Regards
Naresh

#4 lore raw
In reply to Naresh Kumar Ravulapalli
Quoted 35 lines · Naresh Kumar Ravulapalli

Fix the incorrect bit masking and bit shift used to compute EMAC control which in turn is used to select EMAC clock from EMAC source A or B.

---
  drivers/clk/altera/clk-agilex.c | 13 ++++++-------
  1 file changed, 6 insertions(+), 7 deletions(-)
drivers/clk/altera/clk-agilex.c +3 -2
index e1ddd02f356..2ad8cfd8856 100644
@@ -1,6 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0+
  /*
   * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
   */
 
  #include <log.h>
@@ -11,6 +12,7 @@
  #include <dm/lists.h>
  #include <dm/util.h>
  #include <dt-bindings/clock/agilex-clock.h>
+#include <linux/bitfield.h>
  #include <linux/bitops.h>
 
  #include <asm/arch/clock_manager.h>
@@ -515,14 +517,11 @@ static u32 clk_get_emac_clk_hz(struct socfpga_clk_plat *plat, u32 emac_id)
  	/* Get EMAC clock source */
  	ctl = CM_REG_READL(plat, CLKMGR_PERPLL_EMACCTL);
  	if (emac_id == AGILEX_EMAC0_CLK)
-		ctl = (ctl >> CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_OFFSET) &

drivers/clk/altera/clk-agilex.c static u32 clk_get_emac_clk_hz(struct socfpga_clk_plat *plat, u32 emac_id) · line 524

Quoted 10 lines
drivers/clk/altera/clk-agilex.c +3 -5
-		       CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_MASK;
+		ctl = FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_MASK, ctl);
  	else if (emac_id == AGILEX_EMAC1_CLK)
-		ctl = (ctl >> CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_OFFSET) &
-		       CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_MASK;
+		ctl = FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_MASK, ctl);
  	else if (emac_id == AGILEX_EMAC2_CLK)
-		ctl = (ctl >> CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_OFFSET) &
-		       CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_MASK;
+		ctl = FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_MASK, ctl);

Please do the actual fix separately from FIELD_GET() conversion.

#5 lore raw

Hi Marek

Quoted 44 lines · Marek Vasut
Quoted 42 lines · Naresh Kumar Ravulapalli

Fix the incorrect bit masking and bit shift used to compute EMAC control which in turn is used to select EMAC clock from EMAC source A or B.

---
  drivers/clk/altera/clk-agilex.c | 13 ++++++-------

  1 file changed, 6 insertions(+), 7 deletions(-)
drivers/clk/altera/clk-agilex.c +4 -5
index e1ddd02f356..2ad8cfd8856 100644
@@ -1,6 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0+
   /*
    * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
    */
 
   #include <log.h>
@@ -11,6 +12,7 @@
   #include <dm/lists.h>
   #include <dm/util.h>
   #include <dt-bindings/clock/agilex-clock.h>
+#include <linux/bitfield.h>
   #include <linux/bitops.h>
 
   #include <asm/arch/clock_manager.h>
@@ -515,14 +517,11 @@ static u32 clk_get_emac_clk_hz(struct 
 socfpga_clk_plat *plat, u32 emac_id)
       /* Get EMAC clock source */
       ctl = CM_REG_READL(plat, CLKMGR_PERPLL_EMACCTL);
       if (emac_id == AGILEX_EMAC0_CLK)
-             ctl = (ctl >> CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_OFFSET) &
-                    CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_MASK;
+             ctl = FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_MASK, 
 ctl);
       else if (emac_id == AGILEX_EMAC1_CLK)
-             ctl = (ctl >> CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_OFFSET) &
-                    CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_MASK;
Quoted 8 lines
Quoted 7 lines
drivers/clk/altera/clk-agilex.c +2 -2
+             ctl = FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_MASK, 
 ctl);
       else if (emac_id == AGILEX_EMAC2_CLK)
-             ctl = (ctl >> CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_OFFSET) &
-                    CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_MASK;
+             ctl = FIELD_GET(CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_MASK, 

ctl);

Please do the actual fix separately from FIELD_GET() conversion.

Sure, will make the change.

Kind Regards
Naresh