Skip to contentSkip to conversation

clk: imx: Make the dram_apb and dram_alt as read-only

PATCH In review Abel Vesa 1 participant 4 messages Oct 21, 2020

Subsystems (3)
lore
Share & tools
lore

Abel Vesa

author
#0 lore raw

cover clk: imx: Make the dram_apb and dram_alt as read-only

On i.MX8M platforms the dram_apb and dram_alt are controlled from EL3. So in order to keep track of the actual clock tree in kernel, we need to actually declare the clocks but never actually change their parents or divider settings. We do that by marking the mux and the div as read-only with CLK_DIVIDER_READ_ONLY and CLK_MUX_READ_ONLY flags.

Abel Vesa (2):
clk: imx: composite-8m: Add DRAM clock registration variant
clk: imx8m: Use dram variant registration for dram clocks

 drivers/clk/imx/clk-composite-8m.c | 7 +++++++
 drivers/clk/imx/clk-imx8mm.c       | 4 ++--
 drivers/clk/imx/clk-imx8mn.c       | 4 ++--
 drivers/clk/imx/clk-imx8mp.c       | 4 ++--
 drivers/clk/imx/clk-imx8mq.c       | 4 ++--
 drivers/clk/imx/clk.h              | 6 ++++++
 6 files changed, 21 insertions(+), 8 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/2 clk: imx: composite-8m: Add DRAM clock registration variant

The switch between parents for dram_apb and dram_alt is done in EL3, so lets mark the mux and divider as read only with the CLK_DIVIDER_READ_ONLY and CLK_MUX_READ_ONLY flags.

---
 drivers/clk/imx/clk-composite-8m.c | 7 +++++++
 drivers/clk/imx/clk.h              | 6 ++++++
 2 files changed, 13 insertions(+)
drivers/clk/imx/clk-composite-8m.c +7 -0
index 2c309e3..c3231eb 100644
@@ -211,6 +211,13 @@ struct clk_hw *imx8m_clk_hw_composite_flags(const char *name,
 		div->width = PCG_PREDIV_WIDTH;
 		divider_ops = &imx8m_clk_composite_divider_ops;
 		mux_ops = &imx8m_clk_composite_mux_ops;
+	} else if (composite_flags & IMX_COMPOSITE_DRAM) {
+		div->shift = PCG_PREDIV_SHIFT;
+		div->width = PCG_PREDIV_WIDTH;
+		div->flags = CLK_DIVIDER_READ_ONLY;
+		mux->flags = CLK_MUX_READ_ONLY;
+		divider_ops = &clk_divider_ops;
+		mux_ops = &clk_mux_ops;
 	} else {
 		div->shift = PCG_PREDIV_SHIFT;
 		div->width = PCG_PREDIV_WIDTH;
drivers/clk/imx/clk.h +6 -0
index 3b796b3..70c57d2 100644
@@ -535,6 +535,7 @@ struct clk_hw *imx_clk_hw_cpu(const char *name, const char *parent_name,
 
 #define IMX_COMPOSITE_CORE	BIT(0)
 #define IMX_COMPOSITE_BUS	BIT(1)
+#define IMX_COMPOSITE_DRAM	BIT(2)
 
 struct clk_hw *imx8m_clk_hw_composite_flags(const char *name,
 					    const char * const *parent_names,
@@ -565,6 +566,11 @@ struct clk_hw *imx8m_clk_hw_composite_flags(const char *name,
 		ARRAY_SIZE(parent_names), reg, 0, \
 		flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
 
+#define __imx8m_clk_hw_composite_dram(name, parent_names, reg, flags) \
+	imx8m_clk_hw_composite_flags(name, parent_names, \
+		ARRAY_SIZE(parent_names), reg, IMX_COMPOSITE_DRAM, \
+		flags | CLK_GET_RATE_NOCACHE | CLK_OPS_PARENT_ENABLE)
+
 #define __imx8m_clk_composite(name, parent_names, reg, flags) \
 	to_clk(__imx8m_clk_hw_composite(name, parent_names, reg, flags))
 
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH 2/2 clk: imx8m: Use dram variant registration for dram clocks

In reply to Abel Vesa

Both dram_apb and dram_alt are controlled by EL3. Using the dram variant registration of the composite-8m clock, the mux and the divider will be read only. Do this for all i.MX8M platforms.

---
 drivers/clk/imx/clk-imx8mm.c | 4 ++--
 drivers/clk/imx/clk-imx8mn.c | 4 ++--
 drivers/clk/imx/clk-imx8mp.c | 4 ++--
 drivers/clk/imx/clk-imx8mq.c | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)
drivers/clk/imx/clk-imx8mm.c +2 -2
index 0de0be0..955cac4 100644
@@ -468,8 +468,8 @@ static int imx8mm_clocks_probe(struct platform_device *pdev)
 	 * DRAM clocks are manipulated from TF-A outside clock framework.
 	 * Mark with GET_RATE_NOCACHE to always read div value from hardware
 	 */
-	hws[IMX8MM_CLK_DRAM_ALT] = __imx8m_clk_hw_composite("dram_alt", imx8mm_dram_alt_sels, base + 0xa000, CLK_GET_RATE_NOCACHE);
-	hws[IMX8MM_CLK_DRAM_APB] = __imx8m_clk_hw_composite("dram_apb", imx8mm_dram_apb_sels, base + 0xa080, CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE);
+	hws[IMX8MM_CLK_DRAM_ALT] = __imx8m_clk_hw_composite_dram("dram_alt", imx8mm_dram_alt_sels, base + 0xa000, 0);
+	hws[IMX8MM_CLK_DRAM_APB] = __imx8m_clk_hw_composite_dram("dram_apb", imx8mm_dram_apb_sels, base + 0xa080, CLK_IS_CRITICAL);
 
 	/* IP */
 	hws[IMX8MM_CLK_VPU_G1] = imx8m_clk_hw_composite("vpu_g1", imx8mm_vpu_g1_sels, base + 0xa100);
drivers/clk/imx/clk-imx8mn.c +2 -2
index e984de5..7aea389 100644
@@ -451,8 +451,8 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
 	 * DRAM clocks are manipulated from TF-A outside clock framework.
 	 * Mark with GET_RATE_NOCACHE to always read div value from hardware
 	 */
-	hws[IMX8MN_CLK_DRAM_ALT] = __imx8m_clk_hw_composite("dram_alt", imx8mn_dram_alt_sels, base + 0xa000, CLK_GET_RATE_NOCACHE);
-	hws[IMX8MN_CLK_DRAM_APB] = __imx8m_clk_hw_composite("dram_apb", imx8mn_dram_apb_sels, base + 0xa080, CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE);
+	hws[IMX8MN_CLK_DRAM_ALT] = __imx8m_clk_hw_composite_dram("dram_alt", imx8mn_dram_alt_sels, base + 0xa000, 0);
+	hws[IMX8MN_CLK_DRAM_APB] = __imx8m_clk_hw_composite_dram("dram_apb", imx8mn_dram_apb_sels, base + 0xa080, CLK_IS_CRITICAL);
 
 	hws[IMX8MN_CLK_DISP_PIXEL] = imx8m_clk_hw_composite("disp_pixel", imx8mn_disp_pixel_sels, base + 0xa500);
 	hws[IMX8MN_CLK_SAI2] = imx8m_clk_hw_composite("sai2", imx8mn_sai2_sels, base + 0xa600);
drivers/clk/imx/clk-imx8mp.c +2 -2
index 12ce477..205f9d6 100644
@@ -579,8 +579,8 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
 	hws[IMX8MP_CLK_IPG_ROOT] = imx_clk_hw_divider2("ipg_root", "ahb_root", ccm_base + 0x9080, 0, 1);
 	hws[IMX8MP_CLK_IPG_AUDIO_ROOT] = imx_clk_hw_divider2("ipg_audio_root", "audio_ahb", ccm_base + 0x9180, 0, 1);
 
-	hws[IMX8MP_CLK_DRAM_ALT] = imx8m_clk_hw_composite("dram_alt", imx8mp_dram_alt_sels, ccm_base + 0xa000);
-	hws[IMX8MP_CLK_DRAM_APB] = imx8m_clk_hw_composite_critical("dram_apb", imx8mp_dram_apb_sels, ccm_base + 0xa080);
+	hws[IMX8MP_CLK_DRAM_ALT] = __imx8m_clk_hw_composite_dram("dram_alt", imx8mp_dram_alt_sels, ccm_base + 0xa000, 0);
+	hws[IMX8MP_CLK_DRAM_APB] = __imx8m_clk_hw_composite_dram("dram_apb", imx8mp_dram_apb_sels, ccm_base + 0xa080, CLK_IS_CRITICAL);
 	hws[IMX8MP_CLK_VPU_G1] = imx8m_clk_hw_composite("vpu_g1", imx8mp_vpu_g1_sels, ccm_base + 0xa100);
 	hws[IMX8MP_CLK_VPU_G2] = imx8m_clk_hw_composite("vpu_g2", imx8mp_vpu_g2_sels, ccm_base + 0xa180);
 	hws[IMX8MP_CLK_CAN1] = imx8m_clk_hw_composite("can1", imx8mp_can1_sels, ccm_base + 0xa200);
drivers/clk/imx/clk-imx8mq.c +2 -2
index a06cc21..774906e9 100644
@@ -458,8 +458,8 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
 	 * Mark with GET_RATE_NOCACHE to always read div value from hardware
 	 */
 	hws[IMX8MQ_CLK_DRAM_CORE] = imx_clk_hw_mux2_flags("dram_core_clk", base + 0x9800, 24, 1, imx8mq_dram_core_sels, ARRAY_SIZE(imx8mq_dram_core_sels), CLK_IS_CRITICAL);
-	hws[IMX8MQ_CLK_DRAM_ALT] = __imx8m_clk_hw_composite("dram_alt", imx8mq_dram_alt_sels, base + 0xa000, CLK_GET_RATE_NOCACHE);
-	hws[IMX8MQ_CLK_DRAM_APB] = __imx8m_clk_hw_composite("dram_apb", imx8mq_dram_apb_sels, base + 0xa080, CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE);
+	hws[IMX8MQ_CLK_DRAM_ALT] = __imx8m_clk_hw_composite_dram("dram_alt", imx8mq_dram_alt_sels, base + 0xa000, 0);
+	hws[IMX8MQ_CLK_DRAM_APB] = __imx8m_clk_hw_composite_dram("dram_apb", imx8mq_dram_apb_sels, base + 0xa080, CLK_IS_CRITICAL);
 
 	/* IP */
 	hws[IMX8MQ_CLK_VPU_G1] = imx8m_clk_hw_composite("vpu_g1", imx8mq_vpu_g1_sels, base + 0xa100);
Signature · 1 line
2.7.4
author
#3 lore raw
In reply to Abel Vesa
Quoted 6 lines · Abel Vesa

On i.MX8M platforms the dram_apb and dram_alt are controlled from EL3. So in order to keep track of the actual clock tree in kernel, we need to actually declare the clocks but never actually change their parents or divider settings. We do that by marking the mux and the div as read-only with CLK_DIVIDER_READ_ONLY and CLK_MUX_READ_ONLY flags.

Ignore this patchset entirely. A lot of things are missing for this approach.

Quoted 15 lines

Abel Vesa (2):
clk: imx: composite-8m: Add DRAM clock registration variant
clk: imx8m: Use dram variant registration for dram clocks

 drivers/clk/imx/clk-composite-8m.c | 7 +++++++
 drivers/clk/imx/clk-imx8mm.c       | 4 ++--
 drivers/clk/imx/clk-imx8mn.c       | 4 ++--
 drivers/clk/imx/clk-imx8mp.c       | 4 ++--
 drivers/clk/imx/clk-imx8mq.c       | 4 ++--
 drivers/clk/imx/clk.h              | 6 ++++++
 6 files changed, 21 insertions(+), 8 deletions(-)
Signature · 1 line
2.7.4