Skip to contentSkip to conversation

Add imx8mm bus frequency switching

RFC Superseded Leonard Crestez 4 participants 17 messages Jun 28, 2019 – Jul 4, 2019

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add imx8mm bus frequency switching

This series attempts to add upstream DVFS support for imx8mm, covering dynamic scaling of internal buses and dram. It uses the interconnect framework for proactive scaling (in response to explicit bandwidth requests from devices) and devfreq in order expose the buses and eventually implement reactive scaling (in response to measuredtraffic).

Actual scaling is performed through the clk framework: The NOC and main NICs are driven by composite clks and a new 'imx8m-dram' clk is included for scaling dram using firmware calls.

The interconnect and devfreq parts do not communicate explicitly: they both just call clk_set_min_rate and the clk core picks the minimum value that can satisfy both. They are thus completely independent.

This is easily extensible to more members of the imx8m family, some of which expose more detailed controls over interconnect fabric frequencies.

TODO:
* Clarify DT bindings
* Clarify interconnect OPP picking logic
* Implement devfreq_event for imx8m ddrc
* Expose more dram frequencies

The clk_set_min_rate approach does not mesh very well with the OPP framework. Some of interconnect nodes on imx8m can run at different voltages: OPP can handle this well but not in response to a clk_set_min_rate from an unrelated subsystem. Maybe set voltage on a clk notifier?

Vendor tree does not support voltage switching, independent freqs for different parts of the fabric or any reactive scaling. I think it's important to pick an upstreaming approach which can support as much as possible.

Feedback welcome.

Some objections were apparently raised to doing DRAM switch inside CLK:
perhaps ICC should make min_freq requests to devfreq instead?

Link to v1 (multiple chunks):
* https://patchwork.kernel.org/patch/10976897/
* https://patchwork.kernel.org/patch/10968303/
* https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=91251

Also as a github branch (with few other changes):
https://github.com/cdleonard/linux/tree/next_imx8mm_busfreq

Alexandre Bailon (2):
interconnect: Add generic driver for imx
interconnect: imx: Add platform driver for imx8mm

Leonard Crestez (6):
clk: imx8mm: Add dram freq switch support
clk: imx8m-composite: Switch to determine_rate
arm64: dts: imx8mm: Add dram dvfs irqs to ccm node
devfreq: Add imx-devfreq driver
arm64: dts: imx8mm: Add interconnect node
arm64: dts: imx8mm: Add devfreq-imx nodes

 arch/arm64/boot/dts/freescale/imx8mm.dtsi |  73 +++
 drivers/clk/imx/Makefile                  |   1 +
 drivers/clk/imx/clk-composite-8m.c        |  34 +-
 drivers/clk/imx/clk-imx8m-dram.c          | 357 ++++++++++++
 drivers/clk/imx/clk-imx8mm.c              |  12 +
 drivers/clk/imx/clk.h                     |  13 +
 drivers/devfreq/Kconfig                   |  10 +
 drivers/devfreq/Makefile                  |   1 +
 drivers/devfreq/imx-devfreq.c             | 142 +++++
 drivers/interconnect/Kconfig              |   1 +
 drivers/interconnect/Makefile             |   1 +
 drivers/interconnect/imx/Kconfig          |  17 +
 drivers/interconnect/imx/Makefile         |   2 +
 drivers/interconnect/imx/busfreq-imx8mm.c | 151 ++++++
 drivers/interconnect/imx/busfreq.c        | 628 ++++++++++++++++++++++
 drivers/interconnect/imx/busfreq.h        | 123 +++++
 include/dt-bindings/clock/imx8mm-clock.h  |   4 +-
 include/dt-bindings/interconnect/imx8mm.h |  49 ++
 18 files changed, 1606 insertions(+), 13 deletions(-)
 create mode 100644 drivers/clk/imx/clk-imx8m-dram.c
 create mode 100644 drivers/devfreq/imx-devfreq.c
 create mode 100644 drivers/interconnect/imx/Kconfig
 create mode 100644 drivers/interconnect/imx/Makefile
 create mode 100644 drivers/interconnect/imx/busfreq-imx8mm.c
 create mode 100644 drivers/interconnect/imx/busfreq.c
 create mode 100644 drivers/interconnect/imx/busfreq.h
 create mode 100644 include/dt-bindings/interconnect/imx8mm.h
Signature · 1 line
2.17.1
#1 lore raw

RFC v2 1/8 clk: imx8mm: Add dram freq switch support

Add a compound clock encapsulating dram frequency switch support for imx8m chips. This allows higher-level DVFS code to manipulate dram frequency using standard clock framework APIs.

Linux-side implementation is similar in principle to imx_clk_cpu or a composite clock. Only some preparation is done inside the kernel, the actual freq switch is performed from TF-A code which runs from an SRAM area.

This is an early proof-of-concept which only support low/high mode on imx8mm.

---
Changes since v1:
* Implement determin_rate so that consumers can set_min_rate
* Initial freq table
Link to v1:

Among the possible cleanups:
* Handle errors in low/high busfreq code and back off
* Move irq to secure world
* Try to use fewer clk parameters
* Use a table of frequencies
* More chips and frequencies

---
 drivers/clk/imx/Makefile                 |   1 +
 drivers/clk/imx/clk-imx8m-dram.c         | 357 +++++++++++++++++++++++
 drivers/clk/imx/clk-imx8mm.c             |  12 +
 drivers/clk/imx/clk.h                    |  13 +
 include/dt-bindings/clock/imx8mm-clock.h |   4 +-
 5 files changed, 386 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/imx/clk-imx8m-dram.c
drivers/clk/imx/Makefile +1 -0
index 05641c64b317..0fc7195d6d3a 100644
@@ -10,10 +10,11 @@ obj-$(CONFIG_MXC_CLK) += \
 	clk-fixup-div.o \
 	clk-fixup-mux.o \
 	clk-frac-pll.o \
 	clk-gate-exclusive.o \
 	clk-gate2.o \
+	clk-imx8m-dram.o \
 	clk-pfd.o \
 	clk-pfdv2.o \
 	clk-pllv1.o \
 	clk-pllv2.o \
 	clk-pllv3.o \
drivers/clk/imx/clk-imx8m-dram.c new file +357 -0

357 lines not on this page · raw message

drivers/clk/imx/clk-imx8mm.c +12 -0
index 6b8e75df994d..8e19a6fdc415 100644
@@ -660,10 +660,22 @@ static int __init imx8mm_clocks_init(struct device_node *ccm_node)
 	clks[IMX8MM_CLK_GPT_3M] = imx_clk_fixed_factor("gpt_3m", "osc_24m", 1, 8);
 
 	clks[IMX8MM_CLK_DRAM_ALT_ROOT] = imx_clk_fixed_factor("dram_alt_root", "dram_alt", 1, 4);
 	clks[IMX8MM_CLK_DRAM_CORE] = imx_clk_mux2_flags("dram_core_clk", base + 0x9800, 24, 1, imx8mm_dram_core_sels, ARRAY_SIZE(imx8mm_dram_core_sels), CLK_IS_CRITICAL);
 
+	clks[IMX8MM_CLK_DRAM] = imx8m_dram_clk(
+			ccm_node,
+			"dram", "dram_core_clk",
+			clks[IMX8MM_CLK_DRAM_CORE],
+			clks[IMX8MM_CLK_DRAM_APB],
+			clks[IMX8MM_DRAM_PLL_OUT],
+			clks[IMX8MM_CLK_DRAM_ALT],
+			clks[IMX8MM_CLK_DRAM_ALT_ROOT],
+			clks[IMX8MM_SYS_PLL1_40M],
+			clks[IMX8MM_SYS_PLL1_100M],
+			clks[IMX8MM_SYS_PLL1_800M]);
+
 	clks[IMX8MM_CLK_ARM] = imx_clk_cpu("arm", "arm_a53_div",
 					   clks[IMX8MM_CLK_A53_DIV],
 					   clks[IMX8MM_CLK_A53_SRC],
 					   clks[IMX8MM_ARM_PLL_OUT],
 					   clks[IMX8MM_CLK_24M]);
drivers/clk/imx/clk.h +13 -0
index d94d9cb079d3..858547fbad58 100644
@@ -468,6 +468,19 @@ struct clk *imx8m_clk_composite_flags(const char *name,
 
 struct clk_hw *imx_clk_divider_gate(const char *name, const char *parent_name,
 		unsigned long flags, void __iomem *reg, u8 shift, u8 width,
 		u8 clk_divider_flags, const struct clk_div_table *table,
 		spinlock_t *lock);
+
+struct clk* imx8m_dram_clk(
+		struct device_node *np,
+		const char *name, const char* parent_name,
+		struct clk* dram_core,
+		struct clk* dram_apb,
+		struct clk* dram_pll,
+		struct clk* dram_alt,
+		struct clk* dram_alt_root,
+		struct clk* sys1_pll_40m,
+		struct clk* sys1_pll_100m,
+		struct clk* sys1_pll_800m);
+
 #endif
include/dt-bindings/clock/imx8mm-clock.h +3 -1
index 07e6c686f3ef..dde146b923a8 100644
@@ -246,8 +246,10 @@
 #define IMX8MM_CLK_GPIO5_ROOT			227
 
 #define IMX8MM_CLK_SNVS_ROOT			228
 #define IMX8MM_CLK_GIC				229
 
-#define IMX8MM_CLK_END				230
+#define IMX8MM_CLK_DRAM				230
+
+#define IMX8MM_CLK_END				231
 
 #endif
Signature · 1 line
2.17.1
#2 lore raw

RFC v2 2/8 clk: imx8m-composite: Switch to determine_rate

In reply to Leonard Crestez

This allows consumers to use min_rate max_rate.

---
 drivers/clk/imx/clk-composite-8m.c | 34 +++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/clk/imx/clk-composite-8m.c +22 -12
index 388bdb94f841..1be82ec08ecd 100644
@@ -45,10 +45,12 @@ static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw,
 				   divider->flags, PCG_DIV_WIDTH);
 }
 
 static int imx8m_clk_composite_compute_dividers(unsigned long rate,
 						unsigned long parent_rate,
+						unsigned long min_rate,
+						unsigned long max_rate,
 						int *prediv, int *postdiv)
 {
 	int div1, div2;
 	int error = INT_MAX;
 	int ret = -EINVAL;
@@ -56,11 +58,17 @@ static int imx8m_clk_composite_compute_dividers(unsigned long rate,
 	*prediv = 1;
 	*postdiv = 1;
 
 	for (div1 = 1; div1 <= PCG_PREDIV_MAX; div1++) {
 		for (div2 = 1; div2 <= PCG_DIV_MAX; div2++) {
-			int new_error = ((parent_rate / div1) / div2) - rate;
+			unsigned long new_rate;
+			int new_error;
+
+			new_rate = ((parent_rate / div1) / div2);
+			if (new_rate < min_rate || new_rate > max_rate)
+				continue;
+			new_error = new_rate - rate;
 
 			if (abs(new_error) < abs(error)) {
 				*prediv = div1;
 				*postdiv = div2;
 				error = new_error;
@@ -69,38 +77,40 @@ static int imx8m_clk_composite_compute_dividers(unsigned long rate,
 		}
 	}
 	return ret;
 }
 
-static long imx8m_clk_composite_divider_round_rate(struct clk_hw *hw,
-						unsigned long rate,
-						unsigned long *prate)
+static int imx8m_clk_composite_divider_determine_rate(struct clk_hw *hw,
+						       struct clk_rate_request *req)
 {
 	int prediv_value;
 	int div_value;
 
-	imx8m_clk_composite_compute_dividers(rate, *prate,
-						&prediv_value, &div_value);
-	rate = DIV_ROUND_UP(*prate, prediv_value);
+	imx8m_clk_composite_compute_dividers(req->rate, req->best_parent_rate,
+					     req->min_rate, req->max_rate,
+					     &prediv_value, &div_value);
 
-	return DIV_ROUND_UP(rate, div_value);
+	req->rate = DIV_ROUND_UP(req->best_parent_rate, prediv_value);
+	req->rate = DIV_ROUND_UP(req->rate, div_value);
 
+	return 0;
 }
 
 static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
-					unsigned long rate,
-					unsigned long parent_rate)
+						unsigned long rate,
+						unsigned long parent_rate)
 {
 	struct clk_divider *divider = to_clk_divider(hw);
 	unsigned long flags = 0;
 	int prediv_value;
 	int div_value;
 	int ret;
 	u32 val;
 
 	ret = imx8m_clk_composite_compute_dividers(rate, parent_rate,
-						&prediv_value, &div_value);
+						   0, ULONG_MAX,
+						   &prediv_value, &div_value);
 	if (ret)
 		return -EINVAL;
 
 	spin_lock_irqsave(divider->lock, flags);
 
@@ -117,11 +127,11 @@ static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
 	return ret;
 }
 
 static const struct clk_ops imx8m_clk_composite_divider_ops = {
 	.recalc_rate = imx8m_clk_composite_divider_recalc_rate,
-	.round_rate = imx8m_clk_composite_divider_round_rate,
+	.determine_rate = imx8m_clk_composite_divider_determine_rate,
 	.set_rate = imx8m_clk_composite_divider_set_rate,
 };
 
 struct clk *imx8m_clk_composite_flags(const char *name,
 					const char * const *parent_names,
Signature · 1 line
2.17.1
#6 lore raw

RFC v2 3/8 arm64: dts: imx8mm: Add dram dvfs irqs to ccm node

In reply to Leonard Crestez

This could probably be avoided by handling these in secure world.

---
 arch/arm64/boot/dts/freescale/imx8mm.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/freescale/imx8mm.dtsi +8 -0
index 232a7412755a..5da905c257ad 100644
@@ -449,10 +449,18 @@
 				#clock-cells = <1>;
 				clocks = <&osc_32k>, <&osc_24m>, <&clk_ext1>, <&clk_ext2>,
 					 <&clk_ext3>, <&clk_ext4>;
 				clock-names = "osc_32k", "osc_24m", "clk_ext1", "clk_ext2",
 					      "clk_ext3", "clk_ext4";
+				interrupts = <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>,
+					     <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>,
+					     <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
+					     <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>;
+				interrupt-name = "irq_busfreq_0",
+						 "irq_busfreq_1",
+						 "irq_busfreq_2",
+						 "irq_busfreq_3";
 			};
 
 			src: reset-controller@30390000 {
 				compatible = "fsl,imx8mm-src", "syscon";
 				reg = <0x30390000 0x10000>;
Signature · 1 line
2.17.1
#7 lore raw

RFC v2 4/8 interconnect: Add generic driver for imx

In reply to Leonard Crestez

From: Alexandre Bailon <[email protected]>

This adds support for i.MX SoC to interconnect framework.

This is based on busfreq from NXP vendor tree tree. The implementation is sufficiently generic to be applies to any imx SOC and perhaps others.

Using the interconnect framework driver requests for bandwidth are used to determine a global "platform opp" which is then and then scale the frequency. These "platform opps" are similar to the "low/audio/high" busfreq levels from NXP tree.

Busfreq platform drivers just have to register interconnect nodes and OPPs.

Changes by Leonard:
* Make it probe: add xlate and provider->dev
* Clarify commit message
* Use unsigned long for rate

---
 drivers/interconnect/Kconfig       |   1 +
 drivers/interconnect/Makefile      |   1 +
 drivers/interconnect/imx/Kconfig   |  13 +
 drivers/interconnect/imx/Makefile  |   1 +
 drivers/interconnect/imx/busfreq.c | 628 +++++++++++++++++++++++++++++
 drivers/interconnect/imx/busfreq.h | 123 ++++++
 6 files changed, 767 insertions(+)
 create mode 100644 drivers/interconnect/imx/Kconfig
 create mode 100644 drivers/interconnect/imx/Makefile
 create mode 100644 drivers/interconnect/imx/busfreq.c
 create mode 100644 drivers/interconnect/imx/busfreq.h
drivers/interconnect/Kconfig +1 -0
index bfa4ca3ab7a9..e61802230f90 100644
@@ -10,7 +10,8 @@ menuconfig INTERCONNECT
 	  If unsure, say no.
 
 if INTERCONNECT
 
 source "drivers/interconnect/qcom/Kconfig"
+source "drivers/interconnect/imx/Kconfig"
 
 endif
drivers/interconnect/Makefile +1 -0
index 28f2ab0824d5..20a13b7eb37f 100644
@@ -2,5 +2,6 @@
 
 icc-core-objs				:= core.o
 
 obj-$(CONFIG_INTERCONNECT)		+= icc-core.o
 obj-$(CONFIG_INTERCONNECT_QCOM)		+= qcom/
+obj-$(CONFIG_INTERCONNECT_IMX)		+= imx/
drivers/interconnect/imx/Kconfig new file +13 -0
new file mode 100644
index 000000000000..afd7b71bbd82
@@ -0,0 +1,13 @@
+config INTERCONNECT_IMX
+	bool "i.MX interconnect drivers"
+	depends on ARCH_MXC || ARCH_MXC_ARM64 || COMPILE_TEST
+	help
+	  Support for i.MX interconnect hardware.
+
+config BUSFREQ
+	bool "busfreq interconnect driver"
+	depends on INTERCONNECT_IMX
+	help
+	  A generic interconnect driver that could be used for any i.MX.
+	  This provides a way to register master and slave and some opp
+	  to use when one or more master are in use.
drivers/interconnect/imx/Makefile new file +1 -0
new file mode 100644
index 000000000000..fea647183815
@@ -0,0 +1 @@
+obj-$(CONFIG_BUSFREQ) += busfreq.o
drivers/interconnect/imx/busfreq.c new file +628 -0

628 lines not on this page · raw message

drivers/interconnect/imx/busfreq.h new file +123 -0

123 lines not on this page · raw message

Signature · 1 line
2.17.1
#8 lore raw

RFC v2 5/8 interconnect: imx: Add platform driver for imx8mm

In reply to Leonard Crestez

From: Alexandre Bailon <[email protected]>

This adds a platform driver for the i.MX8MM SoC.

---

Changes by Leonard:
* Single DRAM clk
* Change compat string to imx8mm-interconnect

---
 drivers/interconnect/imx/Kconfig          |   4 +
 drivers/interconnect/imx/Makefile         |   1 +
 drivers/interconnect/imx/busfreq-imx8mm.c | 151 ++++++++++++++++++++++
 include/dt-bindings/interconnect/imx8mm.h |  49 +++++++
 4 files changed, 205 insertions(+)
 create mode 100644 drivers/interconnect/imx/busfreq-imx8mm.c
 create mode 100644 include/dt-bindings/interconnect/imx8mm.h
drivers/interconnect/imx/Kconfig +4 -0
index afd7b71bbd82..b569d40e5ca0 100644
@@ -9,5 +9,9 @@ config BUSFREQ
 	depends on INTERCONNECT_IMX
 	help
 	  A generic interconnect driver that could be used for any i.MX.
 	  This provides a way to register master and slave and some opp
 	  to use when one or more master are in use.
+
+config BUSFREQ_IMX8MM
+	bool "i.MX8MM busfreq driver"
+	depends on BUSFREQ
drivers/interconnect/imx/Makefile +1 -0
index fea647183815..a92fea6e042d 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_BUSFREQ) += busfreq.o
+obj-$(CONFIG_BUSFREQ_IMX8MM) += busfreq-imx8mm.o
drivers/interconnect/imx/busfreq-imx8mm.c new file +151 -0

151 lines not on this page · raw message

include/dt-bindings/interconnect/imx8mm.h new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.17.1
#9 lore raw

RFC v2 6/8 devfreq: Add imx-devfreq driver

In reply to Leonard Crestez

Add initial support for frequency switches on pieces of the imx interconnect fabric.

Uses clk_set_min_rate so that other subsytems can also impose minimum rate requests.

---
 drivers/devfreq/Kconfig       |  10 +++
 drivers/devfreq/Makefile      |   1 +
 drivers/devfreq/imx-devfreq.c | 142 ++++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)
 create mode 100644 drivers/devfreq/imx-devfreq.c
drivers/devfreq/Kconfig +10 -0
index f3b242987fd9..3a7c6265ca2f 100644
@@ -90,10 +90,20 @@ config ARM_EXYNOS_BUS_DEVFREQ
 	  Each memory bus group could contain many memoby bus block. It reads
 	  PPMU counters of memory controllers by using DEVFREQ-event device
 	  and adjusts the operating frequencies and voltages with OPP support.
 	  This does not yet operate with optimal voltages.
 
+config ARM_IMX_DEVFREQ
+	tristate "i.MX DEVFREQ Driver"
+	depends on ARCH_MXC
+	select DEVFREQ_GOV_USERSPACE
+	select PM_OPP
+	help
+	  This adds the DEVFREQ driver for the Tegra family of SoCs.
+	  It reads ACTMON counters of memory controllers and adjusts the
+	  operating frequencies and voltages with OPP support.
+
 config ARM_TEGRA_DEVFREQ
 	tristate "NVIDIA Tegra30/114/124/210 DEVFREQ Driver"
 	depends on ARCH_TEGRA_3x_SOC || ARCH_TEGRA_114_SOC || \
 		ARCH_TEGRA_132_SOC || ARCH_TEGRA_124_SOC || \
 		ARCH_TEGRA_210_SOC || \
drivers/devfreq/Makefile +1 -0
index 338ae8440db6..c2463ed4c934 100644
@@ -7,10 +7,11 @@ obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE)	+= governor_powersave.o
 obj-$(CONFIG_DEVFREQ_GOV_USERSPACE)	+= governor_userspace.o
 obj-$(CONFIG_DEVFREQ_GOV_PASSIVE)	+= governor_passive.o
 
 # DEVFREQ Drivers
 obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ)	+= exynos-bus.o
+obj-$(CONFIG_ARM_IMX_DEVFREQ)		+= imx-devfreq.o
 obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ)	+= rk3399_dmc.o
 obj-$(CONFIG_ARM_TEGRA_DEVFREQ)		+= tegra30-devfreq.o
 obj-$(CONFIG_ARM_TEGRA20_DEVFREQ)	+= tegra20-devfreq.o
 
 # DEVFREQ Event Drivers
drivers/devfreq/imx-devfreq.c new file +142 -0

142 lines not on this page · raw message

Signature · 1 line
2.17.1
#11 lore raw

RFC v2 7/8 arm64: dts: imx8mm: Add interconnect node

In reply to Leonard Crestez
---
 arch/arm64/boot/dts/freescale/imx8mm.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/freescale/imx8mm.dtsi +11 -0
index 5da905c257ad..3b4b112814f7 100644
@@ -6,10 +6,11 @@
 #include <dt-bindings/clock/imx8mm-clock.h>
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/input/input.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/thermal/thermal.h>
+#include <dt-bindings/interconnect/imx8mm.h>
 
 #include "imx8mm-pinfunc.h"
 
 / {
 	compatible = "fsl,imx8mm";
@@ -179,10 +180,20 @@
 		interrupts = <GIC_PPI 7
 			     (GIC_CPU_MASK_SIMPLE(6) | IRQ_TYPE_LEVEL_HIGH)>;
 		interrupt-affinity = <&A53_0>, <&A53_1>, <&A53_2>, <&A53_3>;
 	};
 
+	icc: interconnect {
+		compatible = "fsl,imx8mm-interconnect";
+		#interconnect-cells = <1>;
+		clocks = <&clk IMX8MM_CLK_DRAM>,
+			 <&clk IMX8MM_CLK_NOC>,
+			 <&clk IMX8MM_CLK_AHB>,
+			 <&clk IMX8MM_CLK_MAIN_AXI>;
+		clock-names = "dram", "noc", "ahb", "axi";
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(6) | IRQ_TYPE_LEVEL_LOW)>, /* Physical Secure */
 			     <GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(6) | IRQ_TYPE_LEVEL_LOW)>, /* Physical Non-Secure */
 			     <GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(6) | IRQ_TYPE_LEVEL_LOW)>, /* Virtual */
Signature · 1 line
2.17.1
#12 lore raw

RFC v2 8/8 arm64: dts: imx8mm: Add devfreq-imx nodes

In reply to Leonard Crestez

The imx8mm has multiple buses which can be scaled with some degree of independence. Expose them as devfreq devices for userspace scaling.

It shouldn't be possible to get the system in a non-working state this way. It is primarily aimed at testing and fine performance tuning.

---
 arch/arm64/boot/dts/freescale/imx8mm.dtsi | 54 +++++++++++++++++++++++
 1 file changed, 54 insertions(+)
arch/arm64/boot/dts/freescale/imx8mm.dtsi +54 -0
index 3b4b112814f7..aa9ed418652d 100644
@@ -121,10 +121,32 @@
 			opp-supported-hw = <0x8>, <0x7>;
 			clock-latency-ns = <150000>;
 		};
 	};
 
+	ddrc_opp_table: ddrc-opp-table {
+		compatible = "operating-points-v2";
+
+		opp-25M {
+			opp-hz = /bits/ 64 <25000000>;
+		};
+		opp-750M {
+			opp-hz = /bits/ 64 <750000000>;
+		};
+	};
+
+	noc_opp_table: noc-opp-table {
+		compatible = "operating-points-v2";
+
+		opp-150M {
+			opp-hz = /bits/ 64 <150000000>;
+		};
+		opp-750M {
+			opp-hz = /bits/ 64 <750000000>;
+		};
+	};
+
 	memory@40000000 {
 		device_type = "memory";
 		reg = <0x0 0x40000000 0 0x80000000>;
 	};
 
@@ -748,10 +770,35 @@
 				status = "disabled";
 			};
 
 		};
 
+		pl301_main: nic@32000000 {
+			compatible = "fsl,imx8mm-nic";
+			reg = <0x32000000 0x100000>;
+			clocks = <&clk IMX8MM_CLK_MAIN_AXI>;
+		};
+
+		pl301_wakeup: nic@32100000 {
+			compatible = "fsl,imx8mm-nic";
+			reg = <0x32100000 0x100000>;
+			clocks = <&clk IMX8MM_CLK_AHB>;
+		};
+
+		pl301_enet: nic@32400000 {
+			compatible = "fsl,imx8mm-nic";
+			reg = <0x32400000 0x100000>;
+			clocks = <&clk IMX8MM_CLK_ENET_AXI>;
+		};
+
+		noc: noc@32700000 {
+			compatible = "fsl,imx8mm-noc";
+			reg = <0x32700000 0x100000>;
+			clocks = <&clk IMX8MM_CLK_NOC>;
+			operating-points-v2 = <&noc_opp_table>;
+		};
+
 		aips4: bus@32c00000 {
 			compatible = "fsl,aips-bus", "simple-bus";
 			#address-cells = <1>;
 			#size-cells = <1>;
 			ranges = <0x32c00000 0x32c00000 0x400000>;
@@ -835,7 +882,14 @@
 			      <0x38880000 0xc0000>; /* GICR (RD_base + SGI_base) */
 			#interrupt-cells = <3>;
 			interrupt-controller;
 			interrupts = <GIC_PPI 9 IRQ_TYPE_LEVEL_HIGH>;
 		};
+
+		ddrc: dram-controller@3d400000 {
+			compatible = "fsl,imx8mm-ddrc";
+			reg = <0x3d400000 0x400000>;
+			clocks = <&clk IMX8MM_CLK_DRAM>;
+			operating-points-v2 = <&ddrc_opp_table>;
+		};
 	};
 };
Signature · 1 line
2.17.1
#3 lore raw

Re: [RFCv2 2/8] clk: imx8m-composite: Switch to determine_rate

In reply to Leonard Crestez
Quoted 12 lines · Leonard Crestez

This allows consumers to use min_rate max_rate.

---
 drivers/clk/imx/clk-composite-8m.c | 34 +++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/clk/imx/clk-composite-8m.c +0 -0
index 388bdb94f841..1be82ec08ecd 100644

drivers/clk/imx/clk-composite-8m.c static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw, · line 51

Quoted 7 lines
drivers/clk/imx/clk-composite-8m.c +2 -0
@@ -45,10 +45,12 @@ static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw,
 				   divider->flags, PCG_DIV_WIDTH);
 }
 
 static int imx8m_clk_composite_compute_dividers(unsigned long rate,
 						unsigned long parent_rate,
+						unsigned long min_rate,
+						unsigned long max_rate,

You should pass on the req instead of min_rate and max_rate here.

Quoted 91 lines
drivers/clk/imx/clk-composite-8m.c +20 -12
 						int *prediv, int *postdiv)
 {
 	int div1, div2;
 	int error = INT_MAX;
 	int ret = -EINVAL;
@@ -56,11 +58,17 @@ static int imx8m_clk_composite_compute_dividers(unsigned long rate,
 	*prediv = 1;
 	*postdiv = 1;
 
 	for (div1 = 1; div1 <= PCG_PREDIV_MAX; div1++) {
 		for (div2 = 1; div2 <= PCG_DIV_MAX; div2++) {
-			int new_error = ((parent_rate / div1) / div2) - rate;
+			unsigned long new_rate;
+			int new_error;
+
+			new_rate = ((parent_rate / div1) / div2);
+			if (new_rate < min_rate || new_rate > max_rate)
+				continue;
+			new_error = new_rate - rate;
 
 			if (abs(new_error) < abs(error)) {
 				*prediv = div1;
 				*postdiv = div2;
 				error = new_error;
@@ -69,38 +77,40 @@ static int imx8m_clk_composite_compute_dividers(unsigned long rate,
 		}
 	}
 	return ret;
 }
 
-static long imx8m_clk_composite_divider_round_rate(struct clk_hw *hw,
-						unsigned long rate,
-						unsigned long *prate)
+static int imx8m_clk_composite_divider_determine_rate(struct clk_hw *hw,
+						       struct clk_rate_request *req)
 {
 	int prediv_value;
 	int div_value;
 
-	imx8m_clk_composite_compute_dividers(rate, *prate,
-						&prediv_value, &div_value);
-	rate = DIV_ROUND_UP(*prate, prediv_value);
+	imx8m_clk_composite_compute_dividers(req->rate, req->best_parent_rate,
+					     req->min_rate, req->max_rate,
+					     &prediv_value, &div_value);
 
-	return DIV_ROUND_UP(rate, div_value);
+	req->rate = DIV_ROUND_UP(req->best_parent_rate, prediv_value);
+	req->rate = DIV_ROUND_UP(req->rate, div_value);
 
+	return 0;
 }
 
 static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
-					unsigned long rate,
-					unsigned long parent_rate)
+						unsigned long rate,
+						unsigned long parent_rate)
 {
 	struct clk_divider *divider = to_clk_divider(hw);
 	unsigned long flags = 0;
 	int prediv_value;
 	int div_value;
 	int ret;
 	u32 val;
 
 	ret = imx8m_clk_composite_compute_dividers(rate, parent_rate,
-						&prediv_value, &div_value);
+						   0, ULONG_MAX,
+						   &prediv_value, &div_value);
 	if (ret)
 		return -EINVAL;
 
 	spin_lock_irqsave(divider->lock, flags);
 
@@ -117,11 +127,11 @@ static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
 	return ret;
 }
 
 static const struct clk_ops imx8m_clk_composite_divider_ops = {
 	.recalc_rate = imx8m_clk_composite_divider_recalc_rate,
-	.round_rate = imx8m_clk_composite_divider_round_rate,
+	.determine_rate = imx8m_clk_composite_divider_determine_rate,
 	.set_rate = imx8m_clk_composite_divider_set_rate,
 };
 
 struct clk *imx8m_clk_composite_flags(const char *name,
 					const char * const *parent_names,
Signature · 1 line
2.17.1
#4 lore raw

Re: [RFCv2 2/8] clk: imx8m-composite: Switch to determine_rate

Quoted 8 lines · Abel Vesa
Quoted 6 lines · Leonard Crestez

This allows consumers to use min_rate max_rate.

drivers/clk/imx/clk-composite-8m.c +0 -0
@@ -45,10 +45,12 @@ static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw,
  				   divider->flags, PCG_DIV_WIDTH);
  }
 
Quoted 6 lines

drivers/clk/imx/clk-composite-8m.c static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw, · line 51

Quoted 4 lines
drivers/clk/imx/clk-composite-8m.c +2 -0
  static int imx8m_clk_composite_compute_dividers(unsigned long rate,
  						unsigned long parent_rate,
+						unsigned long min_rate,
+						unsigned long max_rate,

You should pass on the req instead of min_rate and max_rate here.

Then I'd have to switch imx8m_clk_composite_divider_set_rate to allocate a dummy struct clk_rate_request on the stack. It's clearer if I just pass the minimum parameters required.

--
Regards,
Leonard

#5 lore raw

Re: [RFCv2 2/8] clk: imx8m-composite: Switch to determine_rate

Quoted 16 lines · Leonard Crestez
Quoted 8 lines · Abel Vesa
Quoted 6 lines · Leonard Crestez

This allows consumers to use min_rate max_rate.

drivers/clk/imx/clk-composite-8m.c +0 -0
@@ -45,10 +45,12 @@ static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw,
  				   divider->flags, PCG_DIV_WIDTH);
  }
 
Quoted 6 lines

drivers/clk/imx/clk-composite-8m.c static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw, · line 51

Quoted 4 lines
drivers/clk/imx/clk-composite-8m.c +2 -0
  static int imx8m_clk_composite_compute_dividers(unsigned long rate,
  						unsigned long parent_rate,
+						unsigned long min_rate,
+						unsigned long max_rate,

You should pass on the req instead of min_rate and max_rate here.

Quoted 4 lines

Then I'd have to switch imx8m_clk_composite_divider_set_rate to allocate a dummy struct clk_rate_request on the stack. It's clearer if I just pass the minimum parameters required.

That is correct. Nevermind my earlier comment then.

Quoted 4 lines

--
Regards,
Leonard

maintainer
#10 lore raw

Re: [RFCv2 6/8] devfreq: Add imx-devfreq driver

In reply to Leonard Crestez

Hi Leonard,

Quoted 19 lines · Leonard Crestez

Add initial support for frequency switches on pieces of the imx interconnect fabric.

Uses clk_set_min_rate so that other subsytems can also impose minimum rate requests.

---
 drivers/devfreq/Kconfig       |  10 +++
 drivers/devfreq/Makefile      |   1 +
 drivers/devfreq/imx-devfreq.c | 142 ++++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)
 create mode 100644 drivers/devfreq/imx-devfreq.c
drivers/devfreq/Kconfig +0 -0
index f3b242987fd9..3a7c6265ca2f 100644

drivers/devfreq/Kconfig config ARM_EXYNOS_BUS_DEVFREQ · line 97

Quoted 8 lines
drivers/devfreq/Kconfig +3 -0
@@ -90,10 +90,20 @@ config ARM_EXYNOS_BUS_DEVFREQ
 	  Each memory bus group could contain many memoby bus block. It reads
 	  PPMU counters of memory controllers by using DEVFREQ-event device
 	  and adjusts the operating frequencies and voltages with OPP support.
 	  This does not yet operate with optimal voltages.
 
+config ARM_IMX_DEVFREQ
+	tristate "i.MX DEVFREQ Driver"
+	depends on ARCH_MXC

You don't need to add 'COMPILE_TEST' as following?

	depends on ARCH_MXC || COMPILE_TEST

drivers/devfreq/Kconfig config ARM_EXYNOS_BUS_DEVFREQ · line 103

Quoted 6 lines
drivers/devfreq/Kconfig +6 -0
+	select DEVFREQ_GOV_USERSPACE
+	select PM_OPP
+	help
+	  This adds the DEVFREQ driver for the Tegra family of SoCs.
+	  It reads ACTMON counters of memory controllers and adjusts the
+	  operating frequencies and voltages with OPP support.

Maybe, you referred to the description of ARM_TEGRA_DEVFREQ. You have to modify it according to the role of IMX_DEVFREQ.

Quoted 57 lines
drivers/devfreq/Kconfig +1 -0
+
 config ARM_TEGRA_DEVFREQ
 	tristate "NVIDIA Tegra30/114/124/210 DEVFREQ Driver"
 	depends on ARCH_TEGRA_3x_SOC || ARCH_TEGRA_114_SOC || \
 		ARCH_TEGRA_132_SOC || ARCH_TEGRA_124_SOC || \
 		ARCH_TEGRA_210_SOC || \
drivers/devfreq/Makefile +1 -0
index 338ae8440db6..c2463ed4c934 100644
@@ -7,10 +7,11 @@ obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE)	+= governor_powersave.o
 obj-$(CONFIG_DEVFREQ_GOV_USERSPACE)	+= governor_userspace.o
 obj-$(CONFIG_DEVFREQ_GOV_PASSIVE)	+= governor_passive.o
 
 # DEVFREQ Drivers
 obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ)	+= exynos-bus.o
+obj-$(CONFIG_ARM_IMX_DEVFREQ)		+= imx-devfreq.o
 obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ)	+= rk3399_dmc.o
 obj-$(CONFIG_ARM_TEGRA_DEVFREQ)		+= tegra30-devfreq.o
 obj-$(CONFIG_ARM_TEGRA20_DEVFREQ)	+= tegra20-devfreq.o
 
 # DEVFREQ Event Drivers
drivers/devfreq/imx-devfreq.c new file +29 -0
new file mode 100644
index 000000000000..aa8868d32f22
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 NXP
+ */
+
+#include <linux/clk.h>
+#include <linux/devfreq.h>
+#include <linux/devfreq-event.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/pm_opp.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+struct imx_devfreq {
+	struct devfreq_dev_profile profile;
+	struct devfreq *devfreq;
+	struct clk *clk;
+};
+
+static int imx_devfreq_target(struct device *dev, unsigned long *freq, u32 flags)
+{
+	struct imx_devfreq *priv = dev_get_drvdata(dev);
+	struct dev_pm_opp *new_opp;
+	unsigned long new_freq;
+	int ret;
+
+	new_opp = devfreq_recommended_opp(dev, freq, flags);

drivers/devfreq/imx-devfreq.c line 39

Quoted 10 lines
drivers/devfreq/imx-devfreq.c new file +10 -0
+	if (IS_ERR(new_opp)) {
+		ret = PTR_ERR(new_opp);
+		dev_err(dev, "failed to get recommended opp: %d\n", ret);
+		return ret;
+	}
+	new_freq = dev_pm_opp_get_freq(new_opp);
+	dev_pm_opp_put(new_opp);
+
+	ret = clk_set_min_rate(priv->clk, new_freq);
+        if (ret)

Fix the indentation.

Quoted 94 lines
drivers/devfreq/imx-devfreq.c new file +93 -0
+		return ret;
+
+	ret = clk_set_rate(priv->clk, 0);
+	if (ret) {
+		clk_set_min_rate(priv->clk, priv->devfreq->previous_freq);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int imx_devfreq_get_cur_freq(struct device *dev, unsigned long *freq)
+{
+	struct imx_devfreq *priv = dev_get_drvdata(dev);
+
+	*freq = clk_get_rate(priv->clk);
+
+	return 0;
+}
+
+static int imx_devfreq_get_dev_status(struct device *dev,
+		struct devfreq_dev_status *stat)
+{
+	struct imx_devfreq *priv = dev_get_drvdata(dev);
+
+	stat->busy_time = 0;
+	stat->total_time = 0;
+	stat->current_frequency = clk_get_rate(priv->clk);
+
+	return 0;
+}
+
+static void imx_devfreq_exit(struct device *dev)
+{
+	return dev_pm_opp_of_remove_table(dev);
+}
+
+static int imx_devfreq_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct imx_devfreq *priv;
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(priv->devfreq)) {
+		ret = PTR_ERR(priv->devfreq);
+		dev_err(dev, "failed to fetch clk: %d\n", ret);
+		return ret;
+	}
+	platform_set_drvdata(pdev, priv);
+
+	ret = dev_pm_opp_of_add_table(dev);
+	if (ret < 0) {
+		dev_err(dev, "failed to get OPP table\n");
+		return ret;
+	}
+
+	priv->profile.polling_ms = 1000;
+	priv->profile.target = imx_devfreq_target;
+	priv->profile.get_dev_status = imx_devfreq_get_dev_status;
+	priv->profile.exit = imx_devfreq_exit;
+	priv->profile.get_cur_freq = imx_devfreq_get_cur_freq;
+	priv->profile.initial_freq = clk_get_rate(priv->clk);
+
+	priv->devfreq = devm_devfreq_add_device(dev, &priv->profile,
+						DEVFREQ_GOV_USERSPACE,
+						NULL);
+	if (IS_ERR(priv->devfreq)) {
+		ret = PTR_ERR(priv->devfreq);
+		dev_err(dev, "failed to add devfreq device: %d\n", ret);
+		goto err_remove_table;
+	}
+
+	return 0;
+
+err_remove_table:
+	dev_pm_opp_of_remove_table(dev);
+	return ret;
+}
+
+static const struct of_device_id imx_devfreq_of_match[] = {
+	{ .compatible = "fsl,imx8mm-ddrc", },
+	{ .compatible = "fsl,imx8mm-noc", },
+	{ .compatible = "fsl,imx8mm-nic", },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, imx_devfreq_of_match);
+
+static struct platform_driver imx_devfreq_platdrv = {

drivers/devfreq/imx-devfreq.c line 142

Quoted 10 lines
drivers/devfreq/imx-devfreq.c new file +10 -0
+	.probe		= imx_devfreq_probe,
+	.driver = {
+		.name	= "devfreq-imx",
+		.of_match_table = of_match_ptr(imx_devfreq_of_match),
+	},
+};
+module_platform_driver(imx_devfreq_platdrv);
+
+MODULE_DESCRIPTION("Generic i.MX bus frequency driver");
+MODULE_LICENSE("GPL v2");

Why don't you add the author information?

And when you are sending the patch, you better
to use get_maintainer.pl script to contain
the related all maintainers/reviewers.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#13 lore raw
In reply to Leonard Crestez

Hi Leonard,

Quoted 6 lines · Leonard Crestez

This series attempts to add upstream DVFS support for imx8mm, covering dynamic scaling of internal buses and dram. It uses the interconnect framework for proactive scaling (in response to explicit bandwidth requests from devices) and devfreq in order expose the buses and eventually implement reactive scaling (in response to measuredtraffic).

I'm assuming you took a glance at my patch series [1] adding BW OPP tables and adding devfreq support for scaling interconnect paths.

Based on looking at your patch series, I think [1] would allow you to use ICC framework for both proactive and reactive scaling. Proactive scaling would use the ICC framework directly. Reactive scaling would go through devfreq (so that you can use various governors/adjust policy) before it goes to ICC framework.

Quoted 3 lines

Actual scaling is performed through the clk framework: The NOC and main NICs are driven by composite clks and a new 'imx8m-dram' clk is included for scaling dram using firmware calls.

Seems reasonable. All hardware block in the end run using a clock.

Quoted 3 lines

The interconnect and devfreq parts do not communicate explicitly: they both just call clk_set_min_rate and the clk core picks the minimum value that can satisfy both. They are thus completely independent.

Two different parts not talking to each other and just setting min rate can cause problems for some concurrency use cases. ICC framework is explicitly designed to handle cases like this and aggregate the needs correctly. You might want to look into that more closely.

Quoted 9 lines

This is easily extensible to more members of the imx8m family, some of which expose more detailed controls over interconnect fabric frequencies.

TODO:
* Clarify DT bindings
* Clarify interconnect OPP picking logic
* Implement devfreq_event for imx8m ddrc
* Expose more dram frequencies

Quoted 4 lines

The clk_set_min_rate approach does not mesh very well with the OPP framework. Some of interconnect nodes on imx8m can run at different voltages: OPP can handle this well but not in response to a clk_set_min_rate from an unrelated subsystem. Maybe set voltage on a clk notifier?

I think if you design it something like below, it might make your life a whole lot easier.
Hopefully the formatting looks okay on your end. The arrow going up is just connecting devfreq to ICC.

                        Proactive -> ICC -> clk/OPP API to set freq/volt
                                      ^
                                      |

HW measure -> governor -> devfreq ----+

That way, all voltage/frequency requirements are managed cleanly by clk/OPP frameworks. The ICC deals with aggregating all the requirements and devfreq lets you handle reactive scaling and policy.

And in the beginning, while you get a governor going, you can use "performance" governor for the "reactive scaling" users. That way, your reactive paths will continue to have good performance while the rest of the "proactive" clients change to use ICC APIs.

Quoted 5 lines

Vendor tree does not support voltage switching, independent freqs for different parts of the fabric or any reactive scaling. I think it's important to pick an upstreaming approach which can support as much as possible.

Feedback welcome.

If all of this makes sense, please take a look at [2] and provide your thoughts. I've dropped a few patches from [1] to avoid confusion (too much going on at once). I think BW OPP tables and having OPP tables for interconnect paths will be something you'll need (if not now, eventually) and something you can build on top of nicely.

Thanks,
Saravana

[1] - https://lore.kernel.org/lkml/[email protected]/
[2] - https://lore.kernel.org/lkml/[email protected]/

Quoted 54 lines

Some objections were apparently raised to doing DRAM switch inside CLK:
perhaps ICC should make min_freq requests to devfreq instead?

Link to v1 (multiple chunks):
* https://patchwork.kernel.org/patch/10976897/
* https://patchwork.kernel.org/patch/10968303/
* https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=91251

Also as a github branch (with few other changes):
https://github.com/cdleonard/linux/tree/next_imx8mm_busfreq

Alexandre Bailon (2):
interconnect: Add generic driver for imx
interconnect: imx: Add platform driver for imx8mm

Leonard Crestez (6):
clk: imx8mm: Add dram freq switch support
clk: imx8m-composite: Switch to determine_rate
arm64: dts: imx8mm: Add dram dvfs irqs to ccm node
devfreq: Add imx-devfreq driver
arm64: dts: imx8mm: Add interconnect node
arm64: dts: imx8mm: Add devfreq-imx nodes

 arch/arm64/boot/dts/freescale/imx8mm.dtsi |  73 +++
 drivers/clk/imx/Makefile                  |   1 +
 drivers/clk/imx/clk-composite-8m.c        |  34 +-
 drivers/clk/imx/clk-imx8m-dram.c          | 357 ++++++++++++
 drivers/clk/imx/clk-imx8mm.c              |  12 +
 drivers/clk/imx/clk.h                     |  13 +
 drivers/devfreq/Kconfig                   |  10 +
 drivers/devfreq/Makefile                  |   1 +
 drivers/devfreq/imx-devfreq.c             | 142 +++++
 drivers/interconnect/Kconfig              |   1 +
 drivers/interconnect/Makefile             |   1 +
 drivers/interconnect/imx/Kconfig          |  17 +
 drivers/interconnect/imx/Makefile         |   2 +
 drivers/interconnect/imx/busfreq-imx8mm.c | 151 ++++++
 drivers/interconnect/imx/busfreq.c        | 628 ++++++++++++++++++++++
 drivers/interconnect/imx/busfreq.h        | 123 +++++
 include/dt-bindings/clock/imx8mm-clock.h  |   4 +-
 include/dt-bindings/interconnect/imx8mm.h |  49 ++
 18 files changed, 1606 insertions(+), 13 deletions(-)
 create mode 100644 drivers/clk/imx/clk-imx8m-dram.c
 create mode 100644 drivers/devfreq/imx-devfreq.c
 create mode 100644 drivers/interconnect/imx/Kconfig
 create mode 100644 drivers/interconnect/imx/Makefile
 create mode 100644 drivers/interconnect/imx/busfreq-imx8mm.c
 create mode 100644 drivers/interconnect/imx/busfreq.c
 create mode 100644 drivers/interconnect/imx/busfreq.h
 create mode 100644 include/dt-bindings/interconnect/imx8mm.h

--
2.17.1

#14 lore raw
Quoted 8 lines · Saravana Kannan
Quoted 3 lines

The interconnect and devfreq parts do not communicate explicitly: they both just call clk_set_min_rate and the clk core picks the minimum value that can satisfy both. They are thus completely independent.

Two different parts not talking to each other and just setting min rate can cause problems for some concurrency use cases. ICC framework is explicitly designed to handle cases like this and aggregate the needs correctly. You might want to look into that more closely.

The clk framework aggregates the min_rate requests from multiple consumers under a big "prepare_lock" so I expect it will deal with concurrent requests correctly. As for performance: frequency switching shouldn't be a fast path.

Quoted 10 lines
Quoted 4 lines

The clk_set_min_rate approach does not mesh very well with the OPP framework. Some of interconnect nodes on imx8m can run at different voltages: OPP can handle this well but not in response to a clk_set_min_rate from an unrelated subsystem. Maybe set voltage on a clk notifier?

I think if you design it something like below, it might make your life a whole lot easier.
Hopefully the formatting looks okay on your end. The arrow going up is just connecting devfreq to ICC.

Quoted 8 lines
                         Proactive -> ICC -> clk/OPP API to set freq/volt
                                       ^
                                       |

HW measure -> governor -> devfreq ----+

That way, all voltage/frequency requirements are managed cleanly by clk/OPP frameworks. The ICC deals with aggregating all the requirements and devfreq lets you handle reactive scaling and policy.

If icc and devfreq are to directly communicate it makes more sense to do it backwards: ICC should set a min_freq on nodes which have a devfreq instance attached and devfreq should implement actual freq switching.

HW measurement is done on individual nodes while ICC deals with requests along a path. In particular on imx we have a performance monitor attached to the ddr controller and I doubt it can distinguish between masters so how could this be mapped usefully to an interconnect request?

As far as I understand with devfreq the ddrc node could use "ondemand" while the other nodes would default to the "passive" governor and run at predefined default ratios relative to DDRC.

Quoted 5 lines

If all of this makes sense, please take a look at [2] and provide your thoughts. I've dropped a few patches from [1] to avoid confusion (too much going on at once). I think BW OPP tables and having OPP tables for interconnect paths will be something you'll need (if not now, eventually) and something you can build on top of nicely.

I found it very confusing that you're assigning BW OPP tables to devices. My initial understanding was that BW OPP would map "bandwidth" to "frequency" so BW OPPs should be assigned to links along the interconnect graph. But maybe what you want is to have OPPs for the BW values requested by devices?

Looking at the sdm845 icc provider source and it seems that those "peak/avg" values are actually parameters which go into a firmware command!? It makes sense that you want interconnect to be "below" devfreq since icc_provider.set maps very closely to what firmware exposes.

Quoted 1 line

Interconnects and interconnect paths quantify their performance

levels > in terms of bandwidth and not in terms of frequency.

On i.MX we just have a bunch of interconnect IPs for which frequencies can be adjusted (in hz) so the above statement doesn't really hold. It is up to an icc provider to convert aggregate bandwidth values to frequencies along the path.

--
Regards,
Leonard

#15 lore raw
Quoted 12 lines · Leonard Crestez
Quoted 8 lines · Saravana Kannan
Quoted 3 lines

The interconnect and devfreq parts do not communicate explicitly: they both just call clk_set_min_rate and the clk core picks the minimum value that can satisfy both. They are thus completely independent.

Two different parts not talking to each other and just setting min rate can cause problems for some concurrency use cases. ICC framework is explicitly designed to handle cases like this and aggregate the needs correctly. You might want to look into that more closely.

Quoted 4 lines

The clk framework aggregates the min_rate requests from multiple consumers under a big "prepare_lock" so I expect it will deal with concurrent requests correctly. As for performance: frequency switching shouldn't be a fast path.

Sorry I wasn't clear. I was not talking about locking issues or race conditions when I said concurrency use cases. What I meant was if GPU wants 5 GB/s and at the same time (concurrent) camera wants 5 GB/s you'll need to configure the interconnect for 10 GB/s. If both of them just try to set the min freq equivalent for 5 GB/s the performance would be bad or functionality might break.

Quoted 19 lines
Quoted 10 lines
Quoted 4 lines

The clk_set_min_rate approach does not mesh very well with the OPP framework. Some of interconnect nodes on imx8m can run at different voltages: OPP can handle this well but not in response to a clk_set_min_rate from an unrelated subsystem. Maybe set voltage on a clk notifier?

I think if you design it something like below, it might make your life a whole lot easier.
Hopefully the formatting looks okay on your end. The arrow going up is just connecting devfreq to ICC.

Quoted 8 lines
                         Proactive -> ICC -> clk/OPP API to set freq/volt
                                       ^
                                       |

HW measure -> governor -> devfreq ----+

That way, all voltage/frequency requirements are managed cleanly by clk/OPP frameworks. The ICC deals with aggregating all the requirements and devfreq lets you handle reactive scaling and policy.

Quoted 8 lines

If icc and devfreq are to directly communicate it makes more sense to do it backwards: ICC should set a min_freq on nodes which have a devfreq instance attached and devfreq should implement actual freq switching.

HW measurement is done on individual nodes while ICC deals with requests along a path. In particular on imx we have a performance monitor attached to the ddr controller and I doubt it can distinguish between masters so how could this be mapped usefully to an interconnect request?

Ah, that was the missing piece for me -- you are trying to use a central performance monitor. I see what you are trying to do.

So you are looking at system wide traffic at DDR and then using that to scale the interconnect/DDRC. I don't know how complicated or not the IMX interconnect topology is, so please pardon my questions. If you are using a performance monitor at the DDR controller, why do you need the "proactive" requests from other clients? Wouldn't the performance monitor account for all the traffic to DDR?

Quoted 3 lines

As far as I understand with devfreq the ddrc node could use "ondemand" while the other nodes would default to the "passive" governor and run at predefined default ratios relative to DDRC.

Yes, that approach would also work but I'm not sure why you need the ICC framework in that case.

Quoted 11 lines
Quoted 5 lines

If all of this makes sense, please take a look at [2] and provide your thoughts. I've dropped a few patches from [1] to avoid confusion (too much going on at once). I think BW OPP tables and having OPP tables for interconnect paths will be something you'll need (if not now, eventually) and something you can build on top of nicely.

I found it very confusing that you're assigning BW OPP tables to devices. My initial understanding was that BW OPP would map "bandwidth" to "frequency" so BW OPPs should be assigned to links along the interconnect graph. But maybe what you want is to have OPPs for the BW values requested by devices?

I want to have OPPs for bandwidths requested for paths. Each interconnect node can also use BW OPPs if that makes sense for them, but I think they'd be better served by using frequency OPPs.

Quoted 4 lines

Looking at the sdm845 icc provider source and it seems that those "peak/avg" values are actually parameters which go into a firmware command!? It makes sense that you want interconnect to be "below" devfreq since icc_provider.set maps very closely to what firmware exposes.

Even without the firmware (it's mainly there to aggregate requests for some system wide resources) or if interconnects are scaled directly using clock APIs (older chips), sdm845 would still want ICC to be below devfreq. It's because 845 doesn't try to do ICC scaling by measuring at the DDR. Each master makes separate requests and then the ICC aggregates and sets the frequency. They have their reasons (good ones) for doing that.

Quoted 5 lines
Quoted 1 line

Interconnects and interconnect paths quantify their performance

levels > in terms of bandwidth and not in terms of frequency.

On i.MX we just have a bunch of interconnect IPs for which frequencies can be adjusted (in hz)

This is true for every chip. In the end, they all set the Hz of hardware IPs.

Quoted 3 lines

so the above statement doesn't really hold. It
is up to an icc provider to convert aggregate bandwidth values to frequencies along the path.

That's the job of every ICC provider. In the case of i.MX you use clock APIs and in the case of sdm845 they use some complicated firmware interface. But in both cases, when the system is tuned for performance/power everyone in the end cares about frequency and voltage. If the frequency goes too high, they might reduce the bandwidth to make sure the frequency remains reasonable for whatever use case they are profiling.

I think the main difference is where the performance monitoring or performance decision is done. If you don't have a central performance monitor or don't want to use one, then the policy decision (which is where devfreq fits in) will have to happen at the bandwidth decision level.

-Saravana

#16 lore raw
Quoted 18 lines · Saravana Kannan
Quoted 11 lines · Leonard Crestez
Quoted 8 lines · Saravana Kannan
Quoted 3 lines

The interconnect and devfreq parts do not communicate explicitly: they both just call clk_set_min_rate and the clk core picks the minimum value that can satisfy both. They are thus completely independent.

Two different parts not talking to each other and just setting min rate can cause problems for some concurrency use cases. ICC framework is explicitly designed to handle cases like this and aggregate the needs correctly. You might want to look into that more closely.

Quoted 4 lines

The clk framework aggregates the min_rate requests from multiple consumers under a big "prepare_lock" so I expect it will deal with concurrent requests correctly. As for performance: frequency switching shouldn't be a fast path.

Quoted 6 lines

Sorry I wasn't clear. I was not talking about locking issues or race conditions when I said concurrency use cases. What I meant was if GPU wants 5 GB/s and at the same time (concurrent) camera wants 5 GB/s you'll need to configure the interconnect for 10 GB/s. If both of them just try to set the min freq equivalent for 5 GB/s the performance would be bad or functionality might break.

I'm not calling clk_set_min_rate independently for each icc path, that would be obviously broken. The interconnect framework is still used to aggregate bandwith requests and in your scenario clk_set_min_rate for the main NOC would be called in a way that meets the combined 10 GB/s requests.

It is devfreq which calls clk_set_min_rate independently of interconnect, this results in CLK performing the final aggregation between the "proactive" and "reactive" scaling.

Quoted 31 lines
Quoted 19 lines
Quoted 10 lines
Quoted 4 lines

The clk_set_min_rate approach does not mesh very well with the OPP framework. Some of interconnect nodes on imx8m can run at different voltages: OPP can handle this well but not in response to a clk_set_min_rate from an unrelated subsystem. Maybe set voltage on a clk notifier?

I think if you design it something like below, it might make your life a whole lot easier.
Hopefully the formatting looks okay on your end. The arrow going up is just connecting devfreq to ICC.

Quoted 8 lines
                          Proactive -> ICC -> clk/OPP API to set freq/volt
                                        ^
                                        |

HW measure -> governor -> devfreq ----+

That way, all voltage/frequency requirements are managed cleanly by clk/OPP frameworks. The ICC deals with aggregating all the requirements and devfreq lets you handle reactive scaling and policy.

Quoted 8 lines

If icc and devfreq are to directly communicate it makes more sense to do it backwards: ICC should set a min_freq on nodes which have a devfreq instance attached and devfreq should implement actual freq switching.

HW measurement is done on individual nodes while ICC deals with requests along a path. In particular on imx we have a performance monitor attached to the ddr controller and I doubt it can distinguish between masters so how could this be mapped usefully to an interconnect request?

Ah, that was the missing piece for me -- you are trying to use a central performance monitor. I see what you are trying to do.

Quoted 6 lines

So you are looking at system wide traffic at DDR and then using that to scale the interconnect/DDRC. I don't know how complicated or not the IMX interconnect topology is, so please pardon my questions. If you are using a performance monitor at the DDR controller, why do you need the "proactive" requests from other clients? Wouldn't the performance monitor account for all the traffic to DDR?

Reactive scaling is too slow to ramp-up in media playback scenarios and first few frames would fail.

Quoted 6 lines
Quoted 3 lines

As far as I understand with devfreq the ddrc node could use "ondemand" while the other nodes would default to the "passive" governor and run at predefined default ratios relative to DDRC.

Yes, that approach would also work but I'm not sure why you need the ICC framework in that case.

For proactive scaling: to ensure bandwidth *before* traffic starts. In imx vendor tree that's all that's implemented; for reactive scaling we just set busfreq to high as soon as cpu leaves min opp.

IMX interconnect topology is not very complex so mechanisms other than interconnect could be used. But ICC is the most powerful and expressive subsystem for proactive requests.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

If all of this makes sense, please take a look at [2] and provide your thoughts. I've dropped a few patches from [1] to avoid confusion (too much going on at once). I think BW OPP tables and having OPP tables for interconnect paths will be something you'll need (if not now, eventually) and something you can build on top of nicely.

Quoted 7 lines
Quoted 5 lines

I found it very confusing that you're assigning BW OPP tables to devices. My initial understanding was that BW OPP would map "bandwidth" to "frequency" so BW OPPs should be assigned to links along the interconnect graph. But maybe what you want is to have OPPs for the BW values requested by devices?

I want to have OPPs for bandwidths requested for paths.

Right, this was not very obvious.

Quoted 2 lines

Each interconnect node can also use BW OPPs if that makes sense for them, but I think they'd be better served by using frequency OPPs.

Each interconnect node is asked by the framework to ensure a certain BW is available in "bytes". The nodes could use OPPs with BW values to map the icc request to a frequency in "hz".

Quoted 5 lines
Quoted 4 lines

Looking at the sdm845 icc provider source and it seems that those "peak/avg" values are actually parameters which go into a firmware command!? It makes sense that you want interconnect to be "below" devfreq since icc_provider.set maps very closely to what firmware exposes.

Quoted 7 lines

Even without the firmware (it's mainly there to aggregate requests for some system wide resources) or if interconnects are scaled directly using clock APIs (older chips), sdm845 would still want ICC to be below devfreq. It's because 845 doesn't try to do ICC scaling by measuring at the DDR. Each master makes separate requests and then the ICC aggregates and sets the frequency. They have their reasons (good ones) for doing that.

Maybe I'm confused about how devfreq is used in your scenario: you have devices which have their own OPPs (like a GPU) and expose this via devfreq. Then for each GPU OPP you want to pick a the BW value to request from interconnect, right?

My idea was to use devfreq *after* icc so that you can do stuff like force a certain NOC to "max" via echo "performance" > $sysfs/governor. It also allows encapsulating complex freq switching (clk maintainers don't seem to like my dram clk).

On a second examination there is no actual incompatibility here, devfreq could be used both below and above ICC.

--
Regards,
Leonard