Skip to contentSkip to conversation

clk: microchip: core: fix issue with round_rate conversion and allow compile test

PATCH Superseded Brian Masney 3 participants 8 messages Dec 1, 2025 – Dec 5, 2025 Common clk

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover clk: microchip: core: fix issue with round_rate conversion and allow compile test

Here's a series that fixes an issue that fixes an issue with my round_rate conversion on this PIC32 driver, drops an unused include file, and a change that allows building this driver on other architectures with COMPILE_TEST enabled.

Changes in v2:
- Add new patch to drop unused asm/traps.h
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Brian Masney (3):
clk: microchip: core: remove duplicate determine_rate on pic32_sclk_ops
clk: microchip: core: remove unused include asm/traps.h
clk: microchip: core: allow driver to be compiled with COMPILE_TEST

 drivers/clk/microchip/Kconfig    |  2 +-
 drivers/clk/microchip/clk-core.c | 19 ++++++++-----------
 2 files changed, 9 insertions(+), 12 deletions(-)

---
base-commit: 92fd6e84175befa1775e5c0ab682938eca27c0b2
change-id: 20251125-clk-microchip-fixes-d0864e21ef0d

Best regards,

Signature · 1 line
Brian Masney <[email protected]>
#1 lore raw

PATCH v2 1/3 clk: microchip: core: remove duplicate determine_rate on pic32_sclk_ops

pic32_sclk_ops previously had a sclk_round_rate() member, and this was recently converted over to sclk_determine_rate() with the help of a Coccinelle semantic patch. pic32_sclk_ops now has two conflicting determine_rate ops members.

Prior to the conversion, pic32_sclk_ops already had a determine_rate member that points to __clk_mux_determine_rate(). When both the round_rate() and determine_rate() ops are defined, the clk core only uses the determine_rate() op. Let's go ahead and drop the recently converted sclk_determine_rate() to match the previous functionality prior to the conversion.

Fixes e9f039c08cdc ("clk: microchip: core: convert from round_rate() to determine_rate()")
---
 drivers/clk/microchip/clk-core.c | 10 ----------
 1 file changed, 10 deletions(-)
drivers/clk/microchip/clk-core.c +0 -10
index b34348d491f3e1b576b2b9a8a66bfddd8c2296ea..a0163441dfe5c1dfc27dae48e64cf3cb3d6b764f 100644
@@ -780,15 +780,6 @@ static unsigned long sclk_get_rate(struct clk_hw *hw, unsigned long parent_rate)
 	return parent_rate / div;
 }
 
-static int sclk_determine_rate(struct clk_hw *hw,
-			       struct clk_rate_request *req)
-{
-	req->rate = calc_best_divided_rate(req->rate, req->best_parent_rate,
-					   SLEW_SYSDIV, 1);
-
-	return 0;
-}
-
 static int sclk_set_rate(struct clk_hw *hw,
 			 unsigned long rate, unsigned long parent_rate)
 {
@@ -912,7 +903,6 @@ static int sclk_init(struct clk_hw *hw)
 const struct clk_ops pic32_sclk_ops = {
 	.get_parent	= sclk_get_parent,
 	.set_parent	= sclk_set_parent,
-	.determine_rate = sclk_determine_rate,
 	.set_rate	= sclk_set_rate,
 	.recalc_rate	= sclk_get_rate,
 	.init		= sclk_init,
Signature · 1 line
2.51.1
#2 lore raw

PATCH v2 2/3 clk: microchip: core: remove unused include asm/traps.h

In reply to Brian Masney

The asm/traps.h include file is not actually used, so let's go ahead and remove it.

---
 drivers/clk/microchip/clk-core.c | 1 -
 1 file changed, 1 deletion(-)
drivers/clk/microchip/clk-core.c +0 -1
index a0163441dfe5c1dfc27dae48e64cf3cb3d6b764f..664663d9d7765ee0c61203ea11211da54b709377 100644
@@ -10,7 +10,6 @@
 #include <linux/io.h>
 #include <linux/iopoll.h>
 #include <asm/mach-pic32/pic32.h>
-#include <asm/traps.h>
 
 #include "clk-core.h"
 
Signature · 1 line
2.51.1
#3 lore raw

PATCH v2 3/3 clk: microchip: core: allow driver to be compiled with COMPILE_TEST

In reply to Brian Masney

This driver currently only supports builds against a PIC32 target. To avoid future breakage in the future, let's update the Kconfig and the driver so that it can be built with CONFIG_COMPILE_TEST enabled.

---
 drivers/clk/microchip/Kconfig    | 2 +-
 drivers/clk/microchip/clk-core.c | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/clk/microchip/Kconfig +1 -1
index 1b9e43eb54976b219a0277cc971f353fd6af226a..1e56a057319d97e20440fe4e107d26fa85c95ab1 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 config COMMON_CLK_PIC32
-	def_bool COMMON_CLK && MACH_PIC32
+	def_bool (COMMON_CLK && MACH_PIC32) || COMPILE_TEST
 
 config MCHP_CLK_MPFS
 	bool "Clk driver for PolarFire SoC"
drivers/clk/microchip/clk-core.c +8 -0
index 664663d9d7765ee0c61203ea11211da54b709377..49c7b8b487ed6bc0e43d7177cb7c4cee9008f544 100644
@@ -9,7 +9,15 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
+
+#if !defined(CONFIG_MACH_PIC32) && defined(CONFIG_COMPILE_TEST)
+#define PIC32_CLR(_reg)		((_reg) + 0x04)
+#define PIC32_SET(_reg)		((_reg) + 0x08)
+#define PIC32_INV(_reg)		((_reg) + 0x0C)
+#define pic32_syskey_unlock()
+#else
 #include <asm/mach-pic32/pic32.h>
+#endif
 
 #include "clk-core.h"
 
Signature · 1 line
2.51.1
build bot
#4 lore raw

Re: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST

BCC: [email protected] CC: [email protected] In-Reply-To: <[email protected]> References: <[email protected]>…

BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Brian Masney <[email protected]>
TO: Michael Turquette <[email protected]>
TO: Stephen Boyd <[email protected]>
TO: Maxime Ripard <[email protected]>
TO: Claudiu Beznea <[email protected]>
TO: Conor Dooley <[email protected]>
CC: [email protected]
CC: [email protected]
CC: Brian Masney <[email protected]>

Hi Brian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 92fd6e84175befa1775e5c0ab682938eca27c0b2]

url:    https://github.com/intel-lab-lkp/linux/commits/Brian-Masney/clk-microchip-core-remove-duplicate-determine_rate-on-pic32_sclk_ops/20251202-060924
base:   92fd6e84175befa1775e5c0ab682938eca27c0b2
patch link:    https://lore.kernel.org/r/20251201-clk-microchip-fixes-v2-3-9d5a0daadd98%40redhat.com
patch subject: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST

:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: arm-randconfig-r071-20251204 (https://download.01.org/0day-ci/archive/20251205/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.5.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/clk/microchip/clk-core.c:300 roclk_get_parent() warn: signedness bug returning '(-22)' drivers/clk/microchip/clk-core.c:833 sclk_get_parent() warn: signedness bug returning '(-22)'

vim +300 drivers/clk/microchip/clk-core.c

ce6e11884659988 Purna Chandra Mandal 2016-05-13  285  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  286  static u8 roclk_get_parent(struct clk_hw *hw)
ce6e11884659988 Purna Chandra Mandal 2016-05-13  287  {
ce6e11884659988 Purna Chandra Mandal 2016-05-13  288  	struct pic32_ref_osc *refo = clkhw_to_refosc(hw);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  289  	u32 v, i;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  290  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  291  	v = (readl(refo->ctrl_reg) >> REFO_SEL_SHIFT) & REFO_SEL_MASK;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  292  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  293  	if (!refo->parent_map)
ce6e11884659988 Purna Chandra Mandal 2016-05-13  294  		return v;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  295  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  296  	for (i = 0; i < clk_hw_get_num_parents(hw); i++)
ce6e11884659988 Purna Chandra Mandal 2016-05-13  297  		if (refo->parent_map[i] == v)
ce6e11884659988 Purna Chandra Mandal 2016-05-13  298  			return i;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  299  

ce6e11884659988 Purna Chandra Mandal 2016-05-13 @300 return -EINVAL;
ce6e11884659988 Purna Chandra Mandal 2016-05-13 301 } ce6e11884659988 Purna Chandra Mandal 2016-05-13 302

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

Re: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST

Quoted 25 lines · Dan Carpenter

smatch warnings:
drivers/clk/microchip/clk-core.c:300 roclk_get_parent() warn: signedness bug returning '(-22)' drivers/clk/microchip/clk-core.c:833 sclk_get_parent() warn: signedness bug returning '(-22)'

vim +300 drivers/clk/microchip/clk-core.c

ce6e11884659988 Purna Chandra Mandal 2016-05-13 286 static u8 roclk_get_parent(struct clk_hw *hw)

                                                             ^^

returns a u8.

ce6e11884659988 Purna Chandra Mandal 2016-05-13  287  {
ce6e11884659988 Purna Chandra Mandal 2016-05-13  288  	struct pic32_ref_osc *refo = clkhw_to_refosc(hw);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  289  	u32 v, i;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  290  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  291  	v = (readl(refo->ctrl_reg) >> REFO_SEL_SHIFT) & REFO_SEL_MASK;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  292  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  293  	if (!refo->parent_map)
ce6e11884659988 Purna Chandra Mandal 2016-05-13  294  		return v;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  295  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  296  	for (i = 0; i < clk_hw_get_num_parents(hw); i++)
ce6e11884659988 Purna Chandra Mandal 2016-05-13  297  		if (refo->parent_map[i] == v)
ce6e11884659988 Purna Chandra Mandal 2016-05-13  298  			return i;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  299  
ce6e11884659988 Purna Chandra Mandal 2016-05-13 @300  	return -EINVAL;
                                                        ^^^^^^^^^^^^^^^
Quoted 3 lines

So it can't return negative error codes.

ce6e11884659988 Purna Chandra Mandal 2016-05-13 301 }

This was an existing bug in the driver. Since I'm making changes to this driver, I'll go ahead and fix this as well.

Brian

#6 lore raw

Re: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST

In reply to Brian Masney
kernel test robot noticed the following build errors:

Hi Brian,

kernel test robot noticed the following build errors:

[auto build test ERROR on 92fd6e84175befa1775e5c0ab682938eca27c0b2]

url:    https://github.com/intel-lab-lkp/linux/commits/Brian-Masney/clk-microchip-core-remove-duplicate-determine_rate-on-pic32_sclk_ops/20251202-060924
base:   92fd6e84175befa1775e5c0ab682938eca27c0b2
patch link:    https://lore.kernel.org/r/20251201-clk-microchip-fixes-v2-3-9d5a0daadd98%40redhat.com
patch subject: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST
config: openrisc-allmodconfig (https://download.01.org/0day-ci/archive/20251205/[email protected]/config)
compiler: or1k-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251205/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/clk/microchip/clk-core.c: Assembler messages:

>> drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction `nop'
>> drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction `nop'
>> drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction `nop'
>> drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction `nop'
>> drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction `nop'

drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop'

vim +721 drivers/clk/microchip/clk-core.c

ce6e11884659988 Purna Chandra Mandal 2016-05-13  682  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  683  static int spll_clk_set_rate(struct clk_hw *hw, unsigned long rate,
ce6e11884659988 Purna Chandra Mandal 2016-05-13  684  			     unsigned long parent_rate)
ce6e11884659988 Purna Chandra Mandal 2016-05-13  685  {
ce6e11884659988 Purna Chandra Mandal 2016-05-13  686  	struct pic32_sys_pll *pll = clkhw_to_spll(hw);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  687  	unsigned long ret, flags;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  688  	u32 mult, odiv, v;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  689  	int err;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  690  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  691  	ret = spll_calc_mult_div(pll, rate, parent_rate, &mult, &odiv);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  692  	if (!ret)
ce6e11884659988 Purna Chandra Mandal 2016-05-13  693  		return -EINVAL;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  694  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  695  	/*
ce6e11884659988 Purna Chandra Mandal 2016-05-13  696  	 * We can't change SPLL counters when it is in-active use
ce6e11884659988 Purna Chandra Mandal 2016-05-13  697  	 * by SYSCLK. So check before applying new counters/rate.
ce6e11884659988 Purna Chandra Mandal 2016-05-13  698  	 */
ce6e11884659988 Purna Chandra Mandal 2016-05-13  699  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  700  	/* Is spll_clk active parent of sys_clk ? */
ce6e11884659988 Purna Chandra Mandal 2016-05-13  701  	if (unlikely(clk_hw_get_parent(pic32_sclk_hw) == hw)) {
ce6e11884659988 Purna Chandra Mandal 2016-05-13  702  		pr_err("%s: failed, clk in-use\n", __func__);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  703  		return -EBUSY;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  704  	}
ce6e11884659988 Purna Chandra Mandal 2016-05-13  705  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  706  	spin_lock_irqsave(&pll->core->reg_lock, flags);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  707  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  708  	/* apply new multiplier & divisor */
ce6e11884659988 Purna Chandra Mandal 2016-05-13  709  	v = readl(pll->ctrl_reg);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  710  	v &= ~(PLL_MULT_MASK << PLL_MULT_SHIFT);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  711  	v &= ~(PLL_ODIV_MASK << PLL_ODIV_SHIFT);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  712  	v |= (mult << PLL_MULT_SHIFT) | (odiv << PLL_ODIV_SHIFT);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  713  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  714  	/* sys unlock before write */
ce6e11884659988 Purna Chandra Mandal 2016-05-13  715  	pic32_syskey_unlock();
ce6e11884659988 Purna Chandra Mandal 2016-05-13  716  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  717  	writel(v, pll->ctrl_reg);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  718  	cpu_relax();
ce6e11884659988 Purna Chandra Mandal 2016-05-13  719  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  720  	/* insert few nops (5-stage) to ensure CPU does not hang */
ce6e11884659988 Purna Chandra Mandal 2016-05-13 @721  	cpu_nop5();
ce6e11884659988 Purna Chandra Mandal 2016-05-13  722  	cpu_nop5();
ce6e11884659988 Purna Chandra Mandal 2016-05-13  723  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  724  	/* Wait until PLL is locked (maximum 100 usecs). */
ce6e11884659988 Purna Chandra Mandal 2016-05-13  725  	err = readl_poll_timeout_atomic(pll->status_reg, v,
ce6e11884659988 Purna Chandra Mandal 2016-05-13  726  					v & pll->lock_mask, 1, 100);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  727  	spin_unlock_irqrestore(&pll->core->reg_lock, flags);
ce6e11884659988 Purna Chandra Mandal 2016-05-13  728  
ce6e11884659988 Purna Chandra Mandal 2016-05-13  729  	return err;
ce6e11884659988 Purna Chandra Mandal 2016-05-13  730  }
ce6e11884659988 Purna Chandra Mandal 2016-05-13  731  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

Re: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST

Quoted 6 lines · kernel test robot

drivers/clk/microchip/clk-core.c: Assembler messages:

Quoted 5 lines
Quoted 5 lines

drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:721: Error: unrecognized instruction `nop'

Quoted 10 lines

drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:722: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop' drivers/clk/microchip/clk-core.c:862: Error: unrecognized instruction nop'

That's related to these calls: __asm__ __volatile__("nop"); In the case of compile test, I'll just make this a noop. I'll post a new version.

Brian