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

Brian Masney posted 3 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST
Posted by Brian Masney 2 months, 1 week ago
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.

Signed-off-by: Brian Masney <bmasney@redhat.com>
---
 drivers/clk/microchip/Kconfig    | 2 +-
 drivers/clk/microchip/clk-core.c | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/microchip/Kconfig b/drivers/clk/microchip/Kconfig
index 1b9e43eb54976b219a0277cc971f353fd6af226a..1e56a057319d97e20440fe4e107d26fa85c95ab1 100644
--- a/drivers/clk/microchip/Kconfig
+++ b/drivers/clk/microchip/Kconfig
@@ -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"
diff --git a/drivers/clk/microchip/clk-core.c b/drivers/clk/microchip/clk-core.c
index 664663d9d7765ee0c61203ea11211da54b709377..49c7b8b487ed6bc0e43d7177cb7c4cee9008f544 100644
--- a/drivers/clk/microchip/clk-core.c
+++ b/drivers/clk/microchip/clk-core.c
@@ -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"
 

-- 
2.51.1
Re: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST
Posted by Dan Carpenter 2 months ago
Hi Brian,

kernel test robot noticed the following build warnings:

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: arm-randconfig-r071-20251204 (https://download.01.org/0day-ci/archive/20251205/202512050233.R9hAWsJN-lkp@intel.com/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 <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202512050233.R9hAWsJN-lkp@intel.com/

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;
                                                        ^^^^^^^^^^^^^^^
So it can't return negative error codes.

ce6e11884659988 Purna Chandra Mandal 2016-05-13  301  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST
Posted by Brian Masney 2 months ago
On Fri, Dec 05, 2025 at 10:21:55AM +0300, Dan Carpenter wrote:
> 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;
>                                                         ^^^^^^^^^^^^^^^
> 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
Re: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST
Posted by kernel test robot 2 months ago
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/202512051151.N3iZUKEG-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251205/202512051151.N3iZUKEG-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512051151.N3iZUKEG-lkp@intel.com/

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  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 3/3] clk: microchip: core: allow driver to be compiled with COMPILE_TEST
Posted by Brian Masney 2 months ago
On Fri, Dec 05, 2025 at 11:51:12AM +0800, kernel test robot wrote:
>    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'

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