Skip to contentSkip to conversation

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

PATCH Applied Brian Masney 2 participants 16 messages Dec 5, 2025 – Jan 10 Common clk

lore
Share & tools
lore
#0 lore raw

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

Here's a series that fixes an issue with my round_rate conversion on this PIC32 driver, fixes a minor bug, and allows building this driver on other architectures with COMPILE_TEST enabled.

Changes in v3:
- Mock out cpu_nop5() in the case of COMPILE_TEST
- Don't return -EINVAL in *_get_parent()
- Link to v2: https://lore.kernel.org/r/[email protected]

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

---
Brian Masney (4):
clk: microchip: core: remove duplicate determine_rate on pic32_sclk_ops
clk: microchip: core: correct return value on *_get_parent()
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 | 68 +++++++++++++++++++++-------------------
 2 files changed, 36 insertions(+), 34 deletions(-)

---
base-commit: b0db9cfd941e8ec63947e39ae29d9abc8be2559d
change-id: 20251125-clk-microchip-fixes-d0864e21ef0d

Best regards,

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

PATCH v3 1/4 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.52.0
Reviewed-by on v3 1/4
#2 lore raw

Re: [PATCH v3 1/4] clk: microchip: core: remove duplicate determine_rate on pic32_sclk_ops

Quoted 12 lines · Brian Masney

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.

Quoted 4 lines
Fixes e9f039c08cdc ("clk: microchip: core: convert from round_rate() to determine_rate()")
#3 lore raw

PATCH v3 2/4 clk: microchip: core: correct return value on *_get_parent()

In reply to Brian Masney

roclk_get_parent() and sclk_get_parent() has the possibility of returning -EINVAL, however the framework expects this call to always succeed since the return value is unsigned.

If there is no parent map defined, then the current value programmed in the hardware is used. Let's use that same value in the case where -EINVAL is currently returned.

This index is only used by clk_core_get_parent_by_index(), and it validates that it doesn't overflow the number of available parents.

---
 drivers/clk/microchip/clk-core.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/clk/microchip/clk-core.c +12 -13
index a0163441dfe5c1dfc27dae48e64cf3cb3d6b764f..82f62731fc0ed566b0c6b007381c4f10a2a8a7e7 100644
@@ -283,14 +283,13 @@ static u8 roclk_get_parent(struct clk_hw *hw)
 
 	v = (readl(refo->ctrl_reg) >> REFO_SEL_SHIFT) & REFO_SEL_MASK;
 
-	if (!refo->parent_map)
-		return v;
-
-	for (i = 0; i < clk_hw_get_num_parents(hw); i++)
-		if (refo->parent_map[i] == v)
-			return i;
+	if (refo->parent_map) {
+		for (i = 0; i < clk_hw_get_num_parents(hw); i++)
+			if (refo->parent_map[i] == v)
+				return i;
+	}
 
-	return -EINVAL;
+	return v;
 }
 
 static unsigned long roclk_calc_rate(unsigned long parent_rate,
@@ -817,13 +816,13 @@ static u8 sclk_get_parent(struct clk_hw *hw)
 
 	v = (readl(sclk->mux_reg) >> OSC_CUR_SHIFT) & OSC_CUR_MASK;
 
-	if (!sclk->parent_map)
-		return v;
+	if (sclk->parent_map) {
+		for (i = 0; i < clk_hw_get_num_parents(hw); i++)
+			if (sclk->parent_map[i] == v)
+				return i;
+	}
 
-	for (i = 0; i < clk_hw_get_num_parents(hw); i++)
-		if (sclk->parent_map[i] == v)
-			return i;
-	return -EINVAL;
+	return v;
 }
 
 static int sclk_set_parent(struct clk_hw *hw, u8 index)
Signature · 1 line
2.52.0
Reviewed-by on v3 2/4
#4 lore raw

Re: [PATCH v3 2/4] clk: microchip: core: correct return value on *_get_parent()

Quoted 4 lines · Brian Masney

roclk_get_parent() and sclk_get_parent() has the possibility of returning -EINVAL, however the framework expects this call to always succeed since the return value is unsigned.

Quoted 8 lines

If there is no parent map defined, then the current value programmed in the hardware is used. Let's use that same value in the case where -EINVAL is currently returned.

This index is only used by clk_core_get_parent_by_index(), and it validates that it doesn't overflow the number of available parents.

I'm getting this from checkpatch:

Applying: clk: microchip: core: correct return value on *_get_parent() [Checking commit] 910546c58dc2 clk: microchip: core: correct return value on *_get_parent()
[Checkpatch] WARNING: Reported-by: should be immediately followed by
Closes: with a URL to the report
#17:

Quoted 3 lines

Other than the above:

#5 lore raw

Re: [PATCH v3 2/4] clk: microchip: core: correct return value on *_get_parent()

Quoted 18 lines · Claudiu Beznea
Quoted 4 lines · Brian Masney

roclk_get_parent() and sclk_get_parent() has the possibility of returning -EINVAL, however the framework expects this call to always succeed since the return value is unsigned.

Quoted 8 lines

If there is no parent map defined, then the current value programmed in the hardware is used. Let's use that same value in the case where -EINVAL is currently returned.

This index is only used by clk_core_get_parent_by_index(), and it validates that it doesn't overflow the number of available parents.

I'm getting this from checkpatch:

Quoted 8 lines

Applying: clk: microchip: core: correct return value on *_get_parent() [Checking commit] 910546c58dc2 clk: microchip: core: correct return value on *_get_parent()
[Checkpatch] WARNING: Reported-by: should be immediately followed by
Closes: with a URL to the report
#17:

That's a false positive from checkpatch. It doesn't like the two Reported-by lines, with a single Closes. The warning goes away if I do this:

Quoted 6 lines
Quoted 3 lines

Other than the above:

Thanks!

Brian

#6 lore raw

PATCH v3 3/4 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 82f62731fc0ed566b0c6b007381c4f10a2a8a7e7..f467d7bc28c87a50fb18dc527574f973c4b7e615 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.52.0
#7 lore raw

PATCH v3 4/4 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.

Note that with the existing asm calls is not how I'd want to do this today if this was a new driver, however I don't have access to this hardware. To avoid any breakage, let's keep the existing behavior.

---
 drivers/clk/microchip/Kconfig    |  2 +-
 drivers/clk/microchip/clk-core.c | 32 +++++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 10 deletions(-)
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 +23 -9
index f467d7bc28c87a50fb18dc527574f973c4b7e615..fad4b45d908310ffb59e4ed57c55ae4266253444 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"
 
@@ -74,15 +82,21 @@
 /* SoC specific clock needed during SPLL clock rate switch */
 static struct clk_hw *pic32_sclk_hw;
 
-/* add instruction pipeline delay while CPU clock is in-transition. */
-#define cpu_nop5()			\
-do {					\
-	__asm__ __volatile__("nop");	\
-	__asm__ __volatile__("nop");	\
-	__asm__ __volatile__("nop");	\
-	__asm__ __volatile__("nop");	\
-	__asm__ __volatile__("nop");	\
-} while (0)
+#if !defined(CONFIG_MACH_PIC32) && defined(CONFIG_COMPILE_TEST)
+#define cpu_nop5()
+#else
+{
+	/* add instruction pipeline delay while CPU clock is in-transition. */
+	#define cpu_nop5()			\
+	do {					\
+		__asm__ __volatile__("nop");	\
+		__asm__ __volatile__("nop");	\
+		__asm__ __volatile__("nop");	\
+		__asm__ __volatile__("nop");	\
+		__asm__ __volatile__("nop");	\
+	} while (0)
+}
+#endif
 
 /* Perpheral bus clocks */
 struct pic32_periph_clk {
Signature · 1 line
2.52.0
#8 lore raw

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

Hi, Brian,

Quoted 32 lines · 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.

Note that with the existing asm calls is not how I'd want to do this today if this was a new driver, however I don't have access to this hardware. To avoid any breakage, let's keep the existing behavior.

---
 drivers/clk/microchip/Kconfig    |  2 +-
 drivers/clk/microchip/clk-core.c | 32 +++++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 10 deletions(-)
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 +0 -0
index f467d7bc28c87a50fb18dc527574f973c4b7e615..fad4b45d908310ffb59e4ed57c55ae4266253444 100644

drivers/clk/microchip/clk-core.c line 13

Quoted 5 lines
drivers/clk/microchip/clk-core.c +2 -0
@@ -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)

Can't we have something like:

#if defined(CONFIG_MATCH_PIC32)
#include <asm/match-pic32/pic32.h>
#else
#define PIC32_CLR(_reg) ((_reg) + 0x04)
#define PIC32_SET(_reg) ((_reg) + 0x08)
#define PIC32_INV(_reg) ((_reg) + 0x0C)
#define pic32_syskey_unlock()
#endif

drivers/clk/microchip/clk-core.c line 17

Quoted 4 lines
drivers/clk/microchip/clk-core.c +4 -0
+#define PIC32_CLR(_reg)		((_reg) + 0x04)
+#define PIC32_SET(_reg)		((_reg) + 0x08)
+#define PIC32_INV(_reg)		((_reg) + 0x0C)
+#define pic32_syskey_unlock()

On the other side, there are other drivers using these defines, maybe a unified approach would fit better? Maybe moving these to include/linux/platform_data ?

Quoted 10 lines
drivers/clk/microchip/clk-core.c +2 -0
+#else
 #include <asm/mach-pic32/pic32.h>
+#endif
 
 #include "clk-core.h"
 
@@ -74,15 +82,21 @@
 /* SoC specific clock needed during SPLL clock rate switch */
 static struct clk_hw *pic32_sclk_hw;
 

drivers/clk/microchip/clk-core.c line 85

Quoted 10 lines
drivers/clk/microchip/clk-core.c +1 -9
-/* add instruction pipeline delay while CPU clock is in-transition. */
-#define cpu_nop5()			\
-do {					\
-	__asm__ __volatile__("nop");	\
-	__asm__ __volatile__("nop");	\
-	__asm__ __volatile__("nop");	\
-	__asm__ __volatile__("nop");	\
-	__asm__ __volatile__("nop");	\
-} while (0)
+#if !defined(CONFIG_MACH_PIC32) && defined(CONFIG_COMPILE_TEST)

Same here, can't we have:

#ifdef CONFIG_MATCH_PIC32

#define cpu_nop5()			\
	do {					\
		__asm__ __volatile__("nop");	\
		__asm__ __volatile__("nop");	\
		__asm__ __volatile__("nop");	\
		__asm__ __volatile__("nop");	\
		__asm__ __volatile__("nop");	\
	} while (0)

#else
#define cpu_nop5()
#endif

?

drivers/clk/microchip/clk-core.c line 88

Quoted 3 lines
drivers/clk/microchip/clk-core.c +3 -0
+#define cpu_nop5()
+#else
+{

This leads to the following error when compiling:

../drivers/clk/microchip/clk-core.c:88:1: error: expected identifier or ‘(’ before ‘{’ token

   88 | {
      | ^

Thank you,
Claudiu

Quoted 15 lines
drivers/clk/microchip/clk-core.c +11 -0
+	/* add instruction pipeline delay while CPU clock is in-transition. */
+	#define cpu_nop5()			\
+	do {					\
+		__asm__ __volatile__("nop");	\
+		__asm__ __volatile__("nop");	\
+		__asm__ __volatile__("nop");	\
+		__asm__ __volatile__("nop");	\
+		__asm__ __volatile__("nop");	\
+	} while (0)
+}
+#endif
 
 /* Perpheral bus clocks */
 struct pic32_periph_clk {
#9 lore raw

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

Hi Claudiu,

Sorry about the delay writing back. I was at Linux Plumbers in Tokyo.

Quoted 41 lines · Claudiu Beznea
Quoted 32 lines · 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.

Note that with the existing asm calls is not how I'd want to do this today if this was a new driver, however I don't have access to this hardware. To avoid any breakage, let's keep the existing behavior.

---
 drivers/clk/microchip/Kconfig    |  2 +-
 drivers/clk/microchip/clk-core.c | 32 +++++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 10 deletions(-)
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 +0 -0
index f467d7bc28c87a50fb18dc527574f973c4b7e615..fad4b45d908310ffb59e4ed57c55ae4266253444 100644

drivers/clk/microchip/clk-core.c line 13

Quoted 5 lines
drivers/clk/microchip/clk-core.c +2 -0
@@ -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)

Can't we have something like:

Quoted 8 lines

#if defined(CONFIG_MATCH_PIC32)
#include <asm/match-pic32/pic32.h>
#else
#define PIC32_CLR(_reg) ((_reg) + 0x04)
#define PIC32_SET(_reg) ((_reg) + 0x08)
#define PIC32_INV(_reg) ((_reg) + 0x0C)
#define pic32_syskey_unlock()
#endif

Yes, I agree that would be simpler.

Quoted 8 lines

drivers/clk/microchip/clk-core.c line 17

Quoted 4 lines
drivers/clk/microchip/clk-core.c +4 -0
+#define PIC32_CLR(_reg)		((_reg) + 0x04)
+#define PIC32_SET(_reg)		((_reg) + 0x08)
+#define PIC32_INV(_reg)		((_reg) + 0x0C)
+#define pic32_syskey_unlock()

On the other side, there are other drivers using these defines, maybe a unified approach would fit better? Maybe moving these to include/linux/platform_data ?

I agree that would be the better approach. Specifically:

- Move arch/mips/include/asm/mach-pic32/pic32.h to include/linux/platform_data
- Drop the unused include linux/io.h in pic32.h
- Check for CONFIG_MATCH_PIC32 for the pic32_syskey_unlock define. Make it a noop for all other architectures.

That would allow us to have the following in the drivers, with no #if's:

#include <linux/platform_data/pic32.h>

I initially wanted to go this route, and I feel that's the best technical decision, however my only hesitation is that this is going to touch at least 8 different subsystems. I could probably get the MIPS folks to take all of this, however it's going to be a pain to collect all of the ACKs from the different subsystems.

x1:~/src/linux/linus (master %)$ git grep pic32.h arch/mips/pic32/common/reset.c:#include <asm/mach-pic32/pic32.h> arch/mips/pic32/common/reset.c:static void pic32_halt(void) arch/mips/pic32/common/reset.c: pic32_halt(); arch/mips/pic32/common/reset.c: pic32_halt(); arch/mips/pic32/pic32mzda/config.c:#include <asm/mach-pic32/pic32.h> arch/mips/pic32/pic32mzda/early_clk.c:#include <asm/mach-pic32/pic32.h> arch/mips/pic32/pic32mzda/early_console.c:#include <asm/mach-pic32/pic32.h> arch/mips/pic32/pic32mzda/init.c:#include <linux/platform_data/sdhci-pic32.h> drivers/clk/microchip/clk-core.c:#include <asm/mach-pic32/pic32.h> drivers/irqchip/irq-pic32-evic.c:#include <asm/mach-pic32/pic32.h> drivers/mmc/host/sdhci-pic32.c:#include <linux/platform_data/sdhci-pic32.h> drivers/pinctrl/pinctrl-pic32.c:#include <asm/mach-pic32/pic32.h> drivers/pinctrl/pinctrl-pic32.c:#include "pinctrl-pic32.h" drivers/rtc/rtc-pic32.c:#include <asm/mach-pic32/pic32.h> drivers/tty/serial/pic32_uart.c:#include <asm/mach-pic32/pic32.h> drivers/watchdog/pic32-dmt.c:#include <asm/mach-pic32/pic32.h> drivers/watchdog/pic32-wdt.c:#include <asm/mach-pic32/pic32.h>

Thoughts?

Quoted 13 lines

drivers/clk/microchip/clk-core.c line 18

Quoted 1 line
drivers/clk/microchip/clk-core.c +1 -0
+#if !defined(CONFIG_MACH_PIC32) && defined(CONFIG_COMPILE_TEST)

Same here, can't we have:

#ifdef CONFIG_MATCH_PIC32

#define cpu_nop5()			\
	do {					\
		__asm__ __volatile__("nop");	\
		__asm__ __volatile__("nop");	\
		__asm__ __volatile__("nop");	\
		__asm__ __volatile__("nop");	\
		__asm__ __volatile__("nop");	\
	} while (0)
Quoted 3 lines

#else
#define cpu_nop5()
#endif

Yes that sounds good.

Brian

#10 lore raw

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

Hi, Brian,

Sorry for the delay, I was off for a while.

Quoted 103 lines · Brian Masney

Hi Claudiu,

Sorry about the delay writing back. I was at Linux Plumbers in Tokyo.

Quoted 41 lines · Claudiu Beznea
Quoted 32 lines · 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.

Note that with the existing asm calls is not how I'd want to do this today if this was a new driver, however I don't have access to this hardware. To avoid any breakage, let's keep the existing behavior.

---
  drivers/clk/microchip/Kconfig    |  2 +-
  drivers/clk/microchip/clk-core.c | 32 +++++++++++++++++++++++---------
  2 files changed, 24 insertions(+), 10 deletions(-)
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 +0 -0
index f467d7bc28c87a50fb18dc527574f973c4b7e615..fad4b45d908310ffb59e4ed57c55ae4266253444 100644

drivers/clk/microchip/clk-core.c line 13

Quoted 5 lines
drivers/clk/microchip/clk-core.c +2 -0
@@ -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)

Can't we have something like:

Quoted 8 lines

#if defined(CONFIG_MATCH_PIC32)
#include <asm/match-pic32/pic32.h>
#else
#define PIC32_CLR(_reg) ((_reg) + 0x04)
#define PIC32_SET(_reg) ((_reg) + 0x08)
#define PIC32_INV(_reg) ((_reg) + 0x0C)
#define pic32_syskey_unlock()
#endif

Yes, I agree that would be simpler.

Quoted 8 lines

drivers/clk/microchip/clk-core.c line 17

Quoted 4 lines
drivers/clk/microchip/clk-core.c +4 -0
+#define PIC32_CLR(_reg)		((_reg) + 0x04)
+#define PIC32_SET(_reg)		((_reg) + 0x08)
+#define PIC32_INV(_reg)		((_reg) + 0x0C)
+#define pic32_syskey_unlock()

On the other side, there are other drivers using these defines, maybe a unified approach would fit better? Maybe moving these to include/linux/platform_data ?

I agree that would be the better approach. Specifically:

- Move arch/mips/include/asm/mach-pic32/pic32.h to include/linux/platform_data
- Drop the unused include linux/io.h in pic32.h
- Check for CONFIG_MATCH_PIC32 for the pic32_syskey_unlock define. Make it a noop for all other architectures.

That would allow us to have the following in the drivers, with no #if's:

#include <linux/platform_data/pic32.h>

I initially wanted to go this route, and I feel that's the best technical decision, however my only hesitation is that this is going to touch at least 8 different subsystems. I could probably get the MIPS folks to take all of this, however it's going to be a pain to collect all of the ACKs from the different subsystems.

x1:~/src/linux/linus (master %)$ git grep pic32.h arch/mips/pic32/common/reset.c:#include <asm/mach-pic32/pic32.h> arch/mips/pic32/common/reset.c:static void pic32_halt(void) arch/mips/pic32/common/reset.c: pic32_halt(); arch/mips/pic32/common/reset.c: pic32_halt(); arch/mips/pic32/pic32mzda/config.c:#include <asm/mach-pic32/pic32.h> arch/mips/pic32/pic32mzda/early_clk.c:#include <asm/mach-pic32/pic32.h> arch/mips/pic32/pic32mzda/early_console.c:#include <asm/mach-pic32/pic32.h> arch/mips/pic32/pic32mzda/init.c:#include <linux/platform_data/sdhci-pic32.h> drivers/clk/microchip/clk-core.c:#include <asm/mach-pic32/pic32.h> drivers/irqchip/irq-pic32-evic.c:#include <asm/mach-pic32/pic32.h> drivers/mmc/host/sdhci-pic32.c:#include <linux/platform_data/sdhci-pic32.h> drivers/pinctrl/pinctrl-pic32.c:#include <asm/mach-pic32/pic32.h> drivers/pinctrl/pinctrl-pic32.c:#include "pinctrl-pic32.h" drivers/rtc/rtc-pic32.c:#include <asm/mach-pic32/pic32.h> drivers/tty/serial/pic32_uart.c:#include <asm/mach-pic32/pic32.h> drivers/watchdog/pic32-dmt.c:#include <asm/mach-pic32/pic32.h> drivers/watchdog/pic32-wdt.c:#include <asm/mach-pic32/pic32.h>

Quoted 1 line

Thoughts?

Sounds good to me.

Thank you,
Claudiu

#11 lore raw
In reply to Brian Masney

Hi Stephen and Claudiu,

Quoted 13 lines · Brian Masney

Here's a series that fixes an issue with my round_rate conversion on this PIC32 driver, fixes a minor bug, and allows building this driver on other architectures with COMPILE_TEST enabled.

Changes in v3:
- Mock out cpu_nop5() in the case of COMPILE_TEST
- Don't return -EINVAL in *_get_parent()
- Link to v2: https://lore.kernel.org/r/[email protected]

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

Quoted 7 lines

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

Stephen: Can you just pick up the first 3 patches in this series? Let's drop patch 4 for now. I'm going to send to the MIPS maintainers a patch to move arch/mips/include/asm/mach-pic32/pic32.h to include/linux/platform_data, and update all of the drivers to use that new header.

Once that's merged, I'll repost patch 4 from this series to enable COMPILE_TEST for this driver.

Brian

#12 lore raw

Hi, all,

Quoted 24 lines · Brian Masney

Hi Stephen and Claudiu,

Quoted 13 lines · Brian Masney

Here's a series that fixes an issue with my round_rate conversion on this PIC32 driver, fixes a minor bug, and allows building this driver on other architectures with COMPILE_TEST enabled.

Changes in v3:
- Mock out cpu_nop5() in the case of COMPILE_TEST
- Don't return -EINVAL in *_get_parent()
- Link to v2: https://lore.kernel.org/r/[email protected]

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

Quoted 7 lines

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

Quoted 5 lines

Stephen: Can you just pick up the first 3 patches in this series? Let's drop patch 4 for now. I'm going to send to the MIPS maintainers a patch to move arch/mips/include/asm/mach-pic32/pic32.h to include/linux/platform_data, and update all of the drivers to use that new header.

I'm going to take those though clk-microchip tree if that's good for everybody.

Thank you,
Claudiu

#13 lore raw
Quoted 25 lines · claudiu beznea
Quoted 24 lines · Brian Masney

Hi Stephen and Claudiu,

Quoted 20 lines · Brian Masney

Here's a series that fixes an issue with my round_rate conversion on this PIC32 driver, fixes a minor bug, and allows building this driver on other architectures with COMPILE_TEST enabled.

Changes in v3:
- Mock out cpu_nop5() in the case of COMPILE_TEST
- Don't return -EINVAL in *_get_parent()
- Link to v2: https://lore.kernel.org/r/[email protected]

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

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

Quoted 7 lines
Quoted 5 lines

Stephen: Can you just pick up the first 3 patches in this series? Let's drop patch 4 for now. I'm going to send to the MIPS maintainers a patch to move arch/mips/include/asm/mach-pic32/pic32.h to include/linux/platform_data, and update all of the drivers to use that new header.

I'm going to take those though clk-microchip tree if that's good for everybody.

Sounds good. Thanks!

I'll CC you on the MIPS changes to move the header file.

Brian

#14 lore raw
Quoted 30 lines · Brian Masney
Quoted 29 lines · claudiu beznea
Quoted 27 lines · Brian Masney
Quoted 13 lines · Brian Masney

Here's a series that fixes an issue with my round_rate conversion on this PIC32 driver, fixes a minor bug, and allows building this driver on other architectures with COMPILE_TEST enabled.

Changes in v3:
- Mock out cpu_nop5() in the case of COMPILE_TEST
- Don't return -EINVAL in *_get_parent()
- Link to v2: https://lore.kernel.org/r/[email protected]

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

Quoted 7 lines

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

Stephen: Can you just pick up the first 3 patches in this series? Let's drop patch 4 for now. I'm going to send to the MIPS maintainers a patch to move arch/mips/include/asm/mach-pic32/pic32.h to include/linux/platform_data, and update all of the drivers to use that new header.

Quoted 5 lines
Quoted 1 line

I'm going to take those though clk-microchip tree if that's good for everybody.

Sounds good. Thanks!

I'll CC you on the MIPS changes to move the header file.

I posted a series to linux-mips to move the header file. It includes a variation of patch 4 from this series that enables COMPILE_TEST for this driver.

https://lore.kernel.org/linux-mips/[email protected]/T/#t

Brian

#15 lore raw
In reply to Brian Masney
Quoted 4 lines · Brian Masney

Brian Masney (4):
clk: microchip: core: remove duplicate determine_rate on pic32_sclk_ops
clk: microchip: core: correct return value on *_get_parent()
clk: microchip: core: remove unused include asm/traps.h

Applied to clk-microchip, thanks!