Skip to contentSkip to conversation

PolarFire SoC clock devicetree rework

PATCH Superseded Conor Dooley 2 participants 6 messages Oct 18, 2024 – Oct 21, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover PolarFire SoC clock devicetree rework

From: Conor Dooley <[email protected]>

Here's a U-Boot implementation of the changes I'm trying to make in
https://lore.kernel.org/all/20241002-private-unequal-33cfa6101338@spud/
that affect how the clocks are described in devicetree for PolarFire SoC. There's been no complaints about the only part that impacts U-Boot, so I figured it was time to send patches here.

I've implemented things here in a backwards compatible manner, so that these changes can be applied now without the relevant devicetree patches (since the dust has not settled on all aspects of the rework) and the revised devicetree can make its way into U-Boot via a regular OF_UPSTREAM update once merged "upstream".

There's minor duplication with Hal's work in patch 3, but I think that's not particularly important, given it is the addition of a trivial Makefile we both require:
https://lore.kernel.org/all/[email protected]

Cheers,
Conor.

CC Rick Chen <[email protected]>
CC Tom Rini <[email protected]>
CC Conor Dooley <[email protected]>
CC Cyril Jean <[email protected]>
CC Lukasz Majewski <[email protected]>
CC Sean Anderson <[email protected]>
CC Sumit Garg <[email protected]>
CC [email protected] (open list)

Conor Dooley (3):
clk: microchip: mpfs: support new syscon based devicetree
configuration
board: mpfs_icicle: imply new clk driver dependencies
riscv: dts: mpfs: migrate to OF_UPSTREAM

 arch/riscv/dts/Makefile                    |   1 -
 arch/riscv/dts/mpfs-icicle-kit-fabric.dtsi |  71 ---
 arch/riscv/dts/mpfs-icicle-kit-u-boot.dtsi |  14 -
 arch/riscv/dts/mpfs-icicle-kit.dts         | 208 ---------
 arch/riscv/dts/mpfs.dtsi                   | 511 ---------------------
 board/microchip/mpfs_icicle/Kconfig        |   2 +
 configs/microchip_mpfs_icicle_defconfig    |   3 +-
 drivers/clk/microchip/Kconfig              |   2 +
 drivers/clk/microchip/mpfs_clk.c           |  63 ++-
 drivers/clk/microchip/mpfs_clk.h           |   5 +-
 drivers/clk/microchip/mpfs_clk_cfg.c       |  16 +-
 drivers/clk/microchip/mpfs_clk_periph.c    |  37 +-
 dts/upstream/src/riscv/Makefile            |  13 +
 13 files changed, 98 insertions(+), 848 deletions(-)
 delete mode 100644 arch/riscv/dts/mpfs-icicle-kit-fabric.dtsi
 delete mode 100644 arch/riscv/dts/mpfs-icicle-kit-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/mpfs-icicle-kit.dts
 delete mode 100644 arch/riscv/dts/mpfs.dtsi
 create mode 100644 dts/upstream/src/riscv/Makefile
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/3 clk: microchip: mpfs: support new syscon based devicetree configuration

From: Conor Dooley <[email protected]>

Why get a devicetree description wrong once when you can get it wrong twice? The original mistake, which the driver supports was failing to describe the main PLL that the "cfg" and "periph" clocks parented by. The second mistake was describing the "cfg" and "periph" clocks a reg region within the clock controller, rather as two registers within a syscon region that also contains pinctrl, interrupt muxing controls and other functions.

Make up for lost time and describe these regions as they should have been originally, preserving support for the existing two configurations for the sake of existing systems with firmware-provided devicetrees.

---
 drivers/clk/microchip/Kconfig           |  2 +
 drivers/clk/microchip/mpfs_clk.c        | 63 ++++++++++++++++++++-----
 drivers/clk/microchip/mpfs_clk.h        |  5 +-
 drivers/clk/microchip/mpfs_clk_cfg.c    | 16 +++----
 drivers/clk/microchip/mpfs_clk_periph.c | 37 +++++++--------
 5 files changed, 81 insertions(+), 42 deletions(-)
drivers/clk/microchip/Kconfig +2 -0
index b70241559db..62072e100b1 100644
@@ -1,5 +1,7 @@
 config CLK_MPFS
 	bool "Clock support for Microchip PolarFire SoC"
 	depends on CLK && CLK_CCF
+	depends on SYSCON
+	depends on REGMAP
 	help
 	  This enables support clock driver for Microchip PolarFire SoC platform.
drivers/clk/microchip/mpfs_clk.c +50 -13

93 lines not on this page · raw message

drivers/clk/microchip/mpfs_clk.h +3 -2
index 72288cc971b..b8ad3ea7616 100644
@@ -7,6 +7,7 @@
 #define __MICROCHIP_MPFS_CLK_H
 
 #include <linux/clk-provider.h>
+#include <regmap.h>
 /**
  * mpfs_clk_register_cfgs() - register configuration clocks
  *
@@ -14,7 +15,7 @@
  * @parent: a pointer to parent clock.
  * Return: zero on success, or a negative error code.
  */
-int mpfs_clk_register_cfgs(void __iomem *base, struct clk *parent);
+int mpfs_clk_register_cfgs(struct clk *parent, struct regmap *regmap);
 /**
  * mpfs_clk_register_msspll() - register the mss pll
  *
@@ -30,7 +31,7 @@ int mpfs_clk_register_msspll(void __iomem *base, struct clk *parent);
  * @dev: udevice representing the clock controller.
  * Return: zero on success, or a negative error code.
  */
-int mpfs_clk_register_periphs(void __iomem *base, struct udevice *dev);
+int mpfs_clk_register_periphs(struct udevice *dev, struct regmap *regmap);
 /**
  * divider_get_val() - get the clock divider value
  *
drivers/clk/microchip/mpfs_clk_cfg.c +8 -8
index 5e8fb995289..7da1fc77120 100644
@@ -9,6 +9,7 @@
 #include <dm/device.h>
 #include <dm/devres.h>
 #include <dm/uclass.h>
+#include <regmap.h>
 #include <dt-bindings/clock/microchip-mpfs-clock.h>
 #include <linux/err.h>
 
@@ -57,7 +58,7 @@ struct mpfs_cfg_clock {
  */
 struct mpfs_cfg_hw_clock {
 	struct mpfs_cfg_clock cfg;
-	void __iomem *sys_base;
+	struct regmap *regmap;
 	u32 prate;
 	struct clk hw;
 };
@@ -68,11 +69,11 @@ static ulong mpfs_cfg_clk_recalc_rate(struct clk *hw)
 {
 	struct mpfs_cfg_hw_clock *cfg_hw = to_mpfs_cfg_clk(hw);
 	struct mpfs_cfg_clock *cfg = &cfg_hw->cfg;
-	void __iomem *base_addr = cfg_hw->sys_base;
 	unsigned long rate;
 	u32 val;
 
-	val = readl(base_addr + REG_CLOCK_CONFIG_CR) >> cfg->shift;
+	regmap_read(cfg_hw->regmap, REG_CLOCK_CONFIG_CR, &val);
+	val >>= cfg->shift;
 	val &= clk_div_mask(cfg->width);
 	rate = cfg_hw->prate / (1u << val);
 	hw->rate = rate;
@@ -84,7 +85,6 @@ static ulong mpfs_cfg_clk_set_rate(struct clk *hw, ulong rate)
 {
 	struct mpfs_cfg_hw_clock *cfg_hw = to_mpfs_cfg_clk(hw);
 	struct mpfs_cfg_clock *cfg = &cfg_hw->cfg;
-	void __iomem *base_addr = cfg_hw->sys_base;
 	u32  val;
 	int divider_setting;
 
@@ -93,10 +93,10 @@ static ulong mpfs_cfg_clk_set_rate(struct clk *hw, ulong rate)
 	if (divider_setting < 0)
 		return divider_setting;
 
-	val = readl(base_addr + REG_CLOCK_CONFIG_CR);
+	regmap_read(cfg_hw->regmap, REG_CLOCK_CONFIG_CR, &val);
 	val &= ~(clk_div_mask(cfg->width) << cfg_hw->cfg.shift);
 	val |= divider_setting << cfg->shift;
-	writel(val, base_addr + REG_CLOCK_CONFIG_CR);
+	regmap_write(cfg_hw->regmap, REG_CLOCK_CONFIG_CR, val);
 
 	return clk_get_rate(hw);
 }
@@ -116,7 +116,7 @@ static struct mpfs_cfg_hw_clock mpfs_cfg_clks[] = {
 	CLK_CFG(CLK_AHB, "clk_ahb", 4, 2, mpfs_div_ahb_table, 0),
 };
 
-int mpfs_clk_register_cfgs(void __iomem *base, struct clk *parent)
+int mpfs_clk_register_cfgs(struct clk *parent, struct regmap *regmap)
 {
 	int ret;
 	int i, id, num_clks;
@@ -126,7 +126,7 @@ int mpfs_clk_register_cfgs(void __iomem *base, struct clk *parent)
 	num_clks = ARRAY_SIZE(mpfs_cfg_clks);
 	for (i = 0; i < num_clks; i++) {
 		hw = &mpfs_cfg_clks[i].hw;
-		mpfs_cfg_clks[i].sys_base = base;
+		mpfs_cfg_clks[i].regmap = regmap;
 		mpfs_cfg_clks[i].prate = clk_get_rate(parent);
 		name = mpfs_cfg_clks[i].cfg.name;
 		ret = clk_register(hw, MPFS_CFG_CLOCK, name, parent->dev->name);
drivers/clk/microchip/mpfs_clk_periph.c +18 -19
index 41c6df4fb97..b734f49d81a 100644
@@ -9,6 +9,7 @@
 #include <dm/device.h>
 #include <dm/devres.h>
 #include <dm/uclass.h>
+#include <regmap.h>
 #include <dt-bindings/clock/microchip-mpfs-clock.h>
 #include <linux/err.h>
 
@@ -50,7 +51,7 @@ struct mpfs_periph_clock {
  */
 struct mpfs_periph_hw_clock {
 	struct mpfs_periph_clock periph;
-	void __iomem *sys_base;
+	struct regmap *regmap;
 	u32 prate;
 	struct clk hw;
 };
@@ -61,17 +62,16 @@ static int mpfs_periph_clk_enable(struct clk *hw)
 {
 	struct mpfs_periph_hw_clock *periph_hw = to_mpfs_periph_clk(hw);
 	struct mpfs_periph_clock *periph = &periph_hw->periph;
-	void __iomem *base_addr = periph_hw->sys_base;
-	u32 reg, val;
+	u32 reg;
 
 	if (periph->flags != CLK_IS_CRITICAL) {
-		reg = readl(base_addr + REG_SUBBLK_RESET_CR);
-		val = reg & ~(1u << periph->shift);
-		writel(val, base_addr + REG_SUBBLK_RESET_CR);
+		regmap_read(periph_hw->regmap, REG_SUBBLK_RESET_CR, &reg);
+		reg &= ~(1u << periph->shift);
+		regmap_write(periph_hw->regmap, REG_SUBBLK_RESET_CR, reg);
 
-		reg = readl(base_addr + REG_SUBBLK_CLOCK_CR);
-		val = reg | (1u << periph->shift);
-		writel(val, base_addr + REG_SUBBLK_CLOCK_CR);
+		regmap_read(periph_hw->regmap, REG_SUBBLK_CLOCK_CR, &reg);
+		reg |= (1u << periph->shift);
+		regmap_write(periph_hw->regmap, REG_SUBBLK_CLOCK_CR, reg);
 	}
 
 	return 0;
@@ -81,17 +81,16 @@ static int mpfs_periph_clk_disable(struct clk *hw)
 {
 	struct mpfs_periph_hw_clock *periph_hw = to_mpfs_periph_clk(hw);
 	struct mpfs_periph_clock *periph = &periph_hw->periph;
-	void __iomem *base_addr = periph_hw->sys_base;
-	u32 reg, val;
+	u32 reg;
 
 	if (periph->flags != CLK_IS_CRITICAL) {
-		reg = readl(base_addr + REG_SUBBLK_RESET_CR);
-		val = reg | (1u << periph->shift);
-		writel(val, base_addr + REG_SUBBLK_RESET_CR);
+		regmap_read(periph_hw->regmap, REG_SUBBLK_RESET_CR, &reg);
+		reg |= (1u << periph->shift);
+		regmap_write(periph_hw->regmap, REG_SUBBLK_RESET_CR, reg);
 
-		reg = readl(base_addr + REG_SUBBLK_CLOCK_CR);
-		val = reg & ~(1u << periph->shift);
-		writel(val, base_addr + REG_SUBBLK_CLOCK_CR);
+		regmap_read(periph_hw->regmap, REG_SUBBLK_CLOCK_CR, &reg);
+		reg &= ~(1u << periph->shift);
+		regmap_write(periph_hw->regmap, REG_SUBBLK_CLOCK_CR, reg);
 	}
 
 	return 0;
@@ -159,7 +158,7 @@ static struct mpfs_periph_hw_clock mpfs_periph_clks[] = {
 	CLK_PERIPH(CLK_CFM, "clk_periph_cfm", CLK_AHB, 29, 0),
 };
 
-int mpfs_clk_register_periphs(void __iomem *base, struct udevice *dev)
+int mpfs_clk_register_periphs(struct udevice *dev, struct regmap *regmap)
 {
 	int ret;
 	int i, id, num_clks;
@@ -172,7 +171,7 @@ int mpfs_clk_register_periphs(void __iomem *base, struct udevice *dev)
 
 		clk_request(dev, &parent);
 		hw = &mpfs_periph_clks[i].hw;
-		mpfs_periph_clks[i].sys_base = base;
+		mpfs_periph_clks[i].regmap = regmap;
 		mpfs_periph_clks[i].prate = clk_get_rate(&parent);
 		name = mpfs_periph_clks[i].periph.name;
 		ret = clk_register(hw, MPFS_PERIPH_CLOCK, name, parent.dev->name);
Signature · 1 line
2.45.2
#2 lore raw

PATCH 2/3 board: mpfs_icicle: imply new clk driver dependencies

In reply to Conor Dooley

From: Conor Dooley <[email protected]>

The clock driver for PolarFire SoC now requires syscon and regmap features, so imply them to preserve implication of the clock driver.

---
 board/microchip/mpfs_icicle/Kconfig | 2 ++
 1 file changed, 2 insertions(+)
board/microchip/mpfs_icicle/Kconfig +2 -0
index 4309f7528bb..6e8c479e955 100644
@@ -24,6 +24,8 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply SMP
 	imply CLK_CCF
 	imply CLK_MPFS
+	imply REGMAP
+	imply SYSCON
 	imply SYS_NS16550
 	imply CMD_DHCP
 	imply CMD_EXT2
Signature · 1 line
2.45.2
#3 lore raw

PATCH 3/3 riscv: dts: mpfs: migrate to OF_UPSTREAM

In reply to Conor Dooley

From: Conor Dooley <[email protected]>

The U-Boot copy of the mpfs devicetree has, in general, been neglected somewhat in comparison to the one in Linux. Moving to OF_UPSTREAM to keep both in sync should serve to eliminate that discrepancy.

Additionally, moving to OF_UPSTREAM will let U-Boot automatically pick up the devicetree rework that is in progress at [1].

---
For obvious reasons, there's partial duplication here with Hal's work, since we both need the new Makefile:
https://lore.kernel.org/all/[email protected]/

---
 arch/riscv/dts/Makefile                    |   1 -
 arch/riscv/dts/mpfs-icicle-kit-fabric.dtsi |  71 ---
 arch/riscv/dts/mpfs-icicle-kit-u-boot.dtsi |  14 -
 arch/riscv/dts/mpfs-icicle-kit.dts         | 208 ---------
 arch/riscv/dts/mpfs.dtsi                   | 511 ---------------------
 configs/microchip_mpfs_icicle_defconfig    |   3 +-
 dts/upstream/src/riscv/Makefile            |  13 +
 7 files changed, 15 insertions(+), 806 deletions(-)
 delete mode 100644 arch/riscv/dts/mpfs-icicle-kit-fabric.dtsi
 delete mode 100644 arch/riscv/dts/mpfs-icicle-kit-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/mpfs-icicle-kit.dts
 delete mode 100644 arch/riscv/dts/mpfs.dtsi
 create mode 100644 dts/upstream/src/riscv/Makefile
arch/riscv/dts/Makefile +0 -1
index c4c44057bad..1e391b5c491 100644
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 dtb-$(CONFIG_TARGET_ANDES_AE350) += ae350_32.dtb ae350_64.dtb
-dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += mpfs-icicle-kit.dtb
 dtb-$(CONFIG_TARGET_MILKV_DUO) += cv1800b-milkv-duo.dtb
 dtb-$(CONFIG_TARGET_QEMU_VIRT) += qemu-virt32.dtb qemu-virt64.dtb
 dtb-$(CONFIG_TARGET_OPENPITON_RISCV64) += openpiton-riscv64.dtb
arch/riscv/dts/mpfs-icicle-kit-fabric.dtsi deleted +0 -71

71 lines not on this page · raw message

arch/riscv/dts/mpfs-icicle-kit-u-boot.dtsi deleted +0 -14
deleted file mode 100644
index f60283fb6b3..00000000000
@@ -1,14 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0 OR MIT)
-/*
- * Copyright (C) 2020 Microchip Technology Inc.
- * Padmarao Begari <[email protected]>
- */
-
-/ {
-	aliases {
-		cpu1 = &cpu1;
-		cpu2 = &cpu2;
-		cpu3 = &cpu3;
-		cpu4 = &cpu4;
-	};
-};
arch/riscv/dts/mpfs-icicle-kit.dts deleted +0 -208

208 lines not on this page · raw message

arch/riscv/dts/mpfs.dtsi deleted +0 -511

511 lines not on this page · raw message

configs/microchip_mpfs_icicle_defconfig +2 -1
index 05adfcd9afe..fb8d5083a0a 100644
@@ -4,7 +4,8 @@ CONFIG_SYS_MALLOC_F_LEN=0x2000
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x80200000
 CONFIG_ENV_SIZE=0x2000
-CONFIG_DEFAULT_DEVICE_TREE="mpfs-icicle-kit"
+CONFIG_DEFAULT_DEVICE_TREE="microchip/mpfs-icicle-kit"
+CONFIG_OF_UPSTREAM=y
 CONFIG_SYS_MEM_TOP_HIDE=0x400000
 CONFIG_SYS_LOAD_ADDR=0x80200000
 CONFIG_TARGET_MICROCHIP_ICICLE=y
dts/upstream/src/riscv/Makefile new file +13 -0
new file mode 100644
index 00000000000..dd2ed0bdfbd
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+include $(srctree)/scripts/Makefile.dts
+
+targets += $(dtb-y)
+
+DTC_FLAGS += -R 4 -p 0x1000
+
+PHONY += dtbs
+dtbs: $(addprefix $(obj)/, $(dtb-y))
+	@:
+
+clean-files := */*.dtb */*.dtbo
Signature · 1 line
2.45.2
#4 lore raw

Re: [PATCH v1 3/3] riscv: dts: mpfs: migrate to OF_UPSTREAM

Hi Conor,

Thanks for working on this.

Quoted 31 lines · Conor Dooley

From: Conor Dooley <[email protected]>

The U-Boot copy of the mpfs devicetree has, in general, been neglected somewhat in comparison to the one in Linux. Moving to OF_UPSTREAM to keep both in sync should serve to eliminate that discrepancy.

Additionally, moving to OF_UPSTREAM will let U-Boot automatically pick up the devicetree rework that is in progress at [1].

---
For obvious reasons, there's partial duplication here with Hal's work, since we both need the new Makefile:
https://lore.kernel.org/all/[email protected]/

---
 arch/riscv/dts/Makefile                    |   1 -
 arch/riscv/dts/mpfs-icicle-kit-fabric.dtsi |  71 ---
 arch/riscv/dts/mpfs-icicle-kit-u-boot.dtsi |  14 -
 arch/riscv/dts/mpfs-icicle-kit.dts         | 208 ---------
 arch/riscv/dts/mpfs.dtsi                   | 511 ---------------------
 configs/microchip_mpfs_icicle_defconfig    |   3 +-
 dts/upstream/src/riscv/Makefile            |  13 +
 7 files changed, 15 insertions(+), 806 deletions(-)
 delete mode 100644 arch/riscv/dts/mpfs-icicle-kit-fabric.dtsi
 delete mode 100644 arch/riscv/dts/mpfs-icicle-kit-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/mpfs-icicle-kit.dts
 delete mode 100644 arch/riscv/dts/mpfs.dtsi
 create mode 100644 dts/upstream/src/riscv/Makefile

<snip>

Quoted 9 lines
dts/upstream/src/riscv/Makefile new file +3 -0
new file mode 100644
index 00000000000..dd2ed0bdfbd
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+include $(srctree)/scripts/Makefile.dts

dts/upstream/src/riscv/Makefile line 13

Quoted 10 lines
dts/upstream/src/riscv/Makefile new file +10 -0
+
+targets += $(dtb-y)
+
+DTC_FLAGS += -R 4 -p 0x1000
+
+PHONY += dtbs
+dtbs: $(addprefix $(obj)/, $(dtb-y))
+       @:
+
+clean-files := */*.dtb */*.dtbo

Many of the common Makefile bits were moved by patch [1] to ‎scripts/Makefile.dts. So you should rebase to the latest master branch. Apart from that, changes look good to me.

[1] https://github.com/u-boot/u-boot/commit/d2061828a4c1b60b44cd2307b6a782ac2efbffbe

-Sumit

Quoted 3 lines

--
2.45.2

#5 lore raw

Re: [PATCH v1 3/3] riscv: dts: mpfs: migrate to OF_UPSTREAM

Quoted 26 lines · Sumit Garg
Quoted 9 lines · Conor Dooley
dts/upstream/src/riscv/Makefile new file +3 -0
new file mode 100644
index 00000000000..dd2ed0bdfbd
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+include $(srctree)/scripts/Makefile.dts

dts/upstream/src/riscv/Makefile line 13

Quoted 10 lines
dts/upstream/src/riscv/Makefile new file +10 -0
+
+targets += $(dtb-y)
+
+DTC_FLAGS += -R 4 -p 0x1000
+
+PHONY += dtbs
+dtbs: $(addprefix $(obj)/, $(dtb-y))
+       @:
+
+clean-files := */*.dtb */*.dtbo

Many of the common Makefile bits were moved by patch [1] to ‎scripts/Makefile.dts. So you should rebase to the latest master branch. Apart from that, changes look good to me.

Quoted 1 line

[1] https://github.com/u-boot/u-boot/commit/d2061828a4c1b60b44cd2307b6a782ac2efbffbe

Heh, I had actually rebased to the latest next a few days before sending these, but I guess that didn't include that match. next or master make little difference here I think as a base, so I'll do that, thanks.