Skip to contentSkip to conversation

Modify MxL's CGU clk driver to make it secure boot compatible

PATCH RESEND Superseded Rahul Tanwar 2 participants 23 messages Sep 22, 2022 – Oct 12, 2022 4 messages not in the archive Common clk

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Modify MxL's CGU clk driver to make it secure boot compatible

* Rebase on latest 6.0 clk linux tree and resend patch series because of no response from anyone so far. Please let me know if anyone has any concerns about these changes. Thanks.

MxL's CGU driver was found to be lacking below required features. Add these required lacking features:

1. Since it is a core driver, it has to conform to secure boot & secure access architecture. In order for the register accesses to be secure access compliant, it needs regmap support as per our security architecture. Hence, replace direct read/writel with regmap based IO. Also remove spinlocks because they are no longer necessary because regmap uses its own lock.

2. There are some gate clocks which are used by the power mgmt IP to gate when a certain power saving mode is activated. These gate clocks can also be gated from CGU clk driver. This creates a conflict. To avoid the conflict, by default disable gating such gate registers from CGU clk driver. But keep a flag to do so for other older IP's which uses same CGU clk IP but does not use same power mgmt IP.

3. Fix two functional bugs found during testing.

This patch series is based on below git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git

Rahul Tanwar (5):
clk: mxl: Switch from direct readl/writel based IO to regmap based IO
clk: mxl: Remove unnecessary spinlocks
clk: mxl: Avoid disabling gate clocks from clk driver
clk: mxl: Add validation for register reads/writes
clk: mxl: Add a missing flag to allow parent clock rate change

 drivers/clk/x86/Kconfig       |   5 +-
 drivers/clk/x86/clk-cgu-pll.c |  23 ++-----
 drivers/clk/x86/clk-cgu.c     | 117 +++++++++++-----------------------
 drivers/clk/x86/clk-cgu.h     |  71 +++++++++++++--------
 drivers/clk/x86/clk-lgm.c     |  16 +++--
 5 files changed, 101 insertions(+), 131 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH RESEND v2 1/5 clk: mxl: Switch from direct readl/writel based IO to regmap based IO

Earlier version of driver used direct io remapped register read writes using readl/writel. But we need secure boot access which is only possible when registers are read & written using regmap. This is because the security bus/hook is written & coupled only with regmap layer.

Switch the driver from direct readl/writel based register accesses to regmap based register accesses.

Additionally, update the license headers to latest status.

---
 drivers/clk/x86/Kconfig       |  5 +++--
 drivers/clk/x86/clk-cgu-pll.c | 10 +++++----
 drivers/clk/x86/clk-cgu.c     |  5 +++--
 drivers/clk/x86/clk-cgu.h     | 38 +++++++++++++++++++----------------
 drivers/clk/x86/clk-lgm.c     | 13 ++++++++----
 5 files changed, 42 insertions(+), 29 deletions(-)
drivers/clk/x86/Kconfig +3 -2
index 69642e15fcc1..ced99e082e3d 100644
@@ -1,8 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config CLK_LGM_CGU
 	depends on OF && HAS_IOMEM && (X86 || COMPILE_TEST)
+	select MFD_SYSCON
 	select OF_EARLY_FLATTREE
 	bool "Clock driver for Lightning Mountain(LGM) platform"
 	help
-	  Clock Generation Unit(CGU) driver for Intel Lightning Mountain(LGM)
-	  network processor SoC.
+	  Clock Generation Unit(CGU) driver for MaxLinear's x86 based
+	  Lightning Mountain(LGM) network processor SoC.
drivers/clk/x86/clk-cgu-pll.c +6 -4
index 3179557b5f78..c83083affe88 100644
@@ -1,8 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
+ * Copyright (C) 2020-2022 MaxLinear, Inc.
  * Copyright (C) 2020 Intel Corporation.
- * Zhu YiXin <[email protected]>
- * Rahul Tanwar <[email protected]>
+ * Zhu Yixin <[email protected]>
+ * Rahul Tanwar <[email protected]>
  */
 
 #include <linux/clk-provider.h>
@@ -76,8 +77,9 @@ static int lgm_pll_enable(struct clk_hw *hw)
 
 	spin_lock_irqsave(&pll->lock, flags);
 	lgm_set_clk_val(pll->membase, pll->reg, 0, 1, 1);
-	ret = readl_poll_timeout_atomic(pll->membase + pll->reg,
-					val, (val & 0x1), 1, 100);
+	ret = regmap_read_poll_timeout_atomic(pll->membase, pll->reg,
+					      val, (val & 0x1), 1, 100);
+
 	spin_unlock_irqrestore(&pll->lock, flags);
 
 	return ret;
drivers/clk/x86/clk-cgu.c +3 -2
index 33de600e0c38..f5f30a18f486 100644
@@ -1,8 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
+ * Copyright (C) 2020-2022 MaxLinear, Inc.
  * Copyright (C) 2020 Intel Corporation.
- * Zhu YiXin <[email protected]>
- * Rahul Tanwar <[email protected]>
+ * Zhu Yixin <[email protected]>
+ * Rahul Tanwar <[email protected]>
  */
 #include <linux/clk-provider.h>
 #include <linux/device.h>
drivers/clk/x86/clk-cgu.h +21 -17
index 4e22bfb22312..dbcb66468797 100644
@@ -1,18 +1,19 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * Copyright(c) 2020 Intel Corporation.
- * Zhu YiXin <[email protected]>
- * Rahul Tanwar <[email protected]>
+ * Copyright (C) 2020-2022 MaxLinear, Inc.
+ * Copyright (C) 2020 Intel Corporation.
+ * Zhu Yixin <[email protected]>
+ * Rahul Tanwar <[email protected]>
  */
 
 #ifndef __CLK_CGU_H
 #define __CLK_CGU_H
 
-#include <linux/io.h>
+#include <linux/regmap.h>
 
 struct lgm_clk_mux {
 	struct clk_hw hw;
-	void __iomem *membase;
+	struct regmap *membase;
 	unsigned int reg;
 	u8 shift;
 	u8 width;
@@ -22,7 +23,7 @@ struct lgm_clk_mux {
 
 struct lgm_clk_divider {
 	struct clk_hw hw;
-	void __iomem *membase;
+	struct regmap *membase;
 	unsigned int reg;
 	u8 shift;
 	u8 width;
@@ -35,7 +36,7 @@ struct lgm_clk_divider {
 
 struct lgm_clk_ddiv {
 	struct clk_hw hw;
-	void __iomem *membase;
+	struct regmap *membase;
 	unsigned int reg;
 	u8 shift0;
 	u8 width0;
@@ -53,7 +54,7 @@ struct lgm_clk_ddiv {
 
 struct lgm_clk_gate {
 	struct clk_hw hw;
-	void __iomem *membase;
+	struct regmap *membase;
 	unsigned int reg;
 	u8 shift;
 	unsigned long flags;
@@ -77,7 +78,7 @@ enum lgm_clk_type {
  * @clk_data: array of hw clocks and clk number.
  */
 struct lgm_clk_provider {
-	void __iomem *membase;
+	struct regmap *membase;
 	struct device_node *np;
 	struct device *dev;
 	struct clk_hw_onecell_data clk_data;
@@ -92,7 +93,7 @@ enum pll_type {
 
 struct lgm_clk_pll {
 	struct clk_hw hw;
-	void __iomem *membase;
+	struct regmap *membase;
 	unsigned int reg;
 	unsigned long flags;
 	enum pll_type type;
@@ -300,29 +301,32 @@ struct lgm_clk_branch {
 		.div = _d,					\
 	}
 
-static inline void lgm_set_clk_val(void __iomem *membase, u32 reg,
+static inline void lgm_set_clk_val(struct regmap *membase, u32 reg,
 				   u8 shift, u8 width, u32 set_val)
 {
 	u32 mask = (GENMASK(width - 1, 0) << shift);
-	u32 regval;
 
-	regval = readl(membase + reg);
-	regval = (regval & ~mask) | ((set_val << shift) & mask);
-	writel(regval, membase + reg);
+	regmap_update_bits(membase, reg, mask, set_val << shift);
 }
 
-static inline u32 lgm_get_clk_val(void __iomem *membase, u32 reg,
+static inline u32 lgm_get_clk_val(struct regmap *membase, u32 reg,
 				  u8 shift, u8 width)
 {
 	u32 mask = (GENMASK(width - 1, 0) << shift);
 	u32 val;
 
-	val = readl(membase + reg);
+	if (regmap_read(membase, reg, &val)) {
+		WARN_ONCE(1, "Failed to read clk reg: 0x%x\n", reg);
+		return 0;
+	}
+
 	val = (val & mask) >> shift;
 
 	return val;
 }
 
+
+
 int lgm_clk_register_branches(struct lgm_clk_provider *ctx,
 			      const struct lgm_clk_branch *list,
 			      unsigned int nr_clk);
drivers/clk/x86/clk-lgm.c +9 -4
index 020f4e83a5cc..4fa2bcaf71c8 100644
@@ -1,10 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
+ * Copyright (C) 2020-2022 MaxLinear, Inc.
  * Copyright (C) 2020 Intel Corporation.
- * Zhu YiXin <[email protected]>
- * Rahul Tanwar <[email protected]>
+ * Zhu Yixin <[email protected]>
+ * Rahul Tanwar <[email protected]>
  */
 #include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <dt-bindings/clock/intel,lgm-clk.h>
@@ -433,9 +435,12 @@ static int lgm_cgu_probe(struct platform_device *pdev)
 
 	ctx->clk_data.num = CLK_NR_CLKS;
 
-	ctx->membase = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(ctx->membase))
+	ctx->membase = syscon_node_to_regmap(np);
+	if (IS_ERR_OR_NULL(ctx->membase)) {
+		dev_err(dev, "Failed to get clk CGU iomem\n");
 		return PTR_ERR(ctx->membase);
+	}
+
 
 	ctx->np = np;
 	ctx->dev = dev;
Signature · 1 line
2.17.1
#4 lore raw

PATCH RESEND v2 2/5 clk: mxl: Remove unnecessary spinlocks

In reply to Rahul Tanwar

This driver is now switched from direct readl/writel based register access to regmap based register acceess. Regmap already has its own lock to serialize the register accesses across multiple cores.

Hence, there is no need for additional spinlocks in the driver. Remove all spinlocks which are no longer required.

---
 drivers/clk/x86/clk-cgu-pll.c | 13 ------
 drivers/clk/x86/clk-cgu.c     | 80 ++++-------------------------------
 drivers/clk/x86/clk-cgu.h     |  6 ---
 drivers/clk/x86/clk-lgm.c     |  1 -
 4 files changed, 9 insertions(+), 91 deletions(-)
drivers/clk/x86/clk-cgu-pll.c +0 -13
index c83083affe88..409dbf55f4ca 100644
@@ -41,13 +41,10 @@ static unsigned long lgm_pll_recalc_rate(struct clk_hw *hw, unsigned long prate)
 {
 	struct lgm_clk_pll *pll = to_lgm_clk_pll(hw);
 	unsigned int div, mult, frac;
-	unsigned long flags;
 
-	spin_lock_irqsave(&pll->lock, flags);
 	mult = lgm_get_clk_val(pll->membase, PLL_REF_DIV(pll->reg), 0, 12);
 	div = lgm_get_clk_val(pll->membase, PLL_REF_DIV(pll->reg), 18, 6);
 	frac = lgm_get_clk_val(pll->membase, pll->reg, 2, 24);
-	spin_unlock_irqrestore(&pll->lock, flags);
 
 	if (pll->type == TYPE_LJPLL)
 		div *= 4;
@@ -58,12 +55,9 @@ static unsigned long lgm_pll_recalc_rate(struct clk_hw *hw, unsigned long prate)
 static int lgm_pll_is_enabled(struct clk_hw *hw)
 {
 	struct lgm_clk_pll *pll = to_lgm_clk_pll(hw);
-	unsigned long flags;
 	unsigned int ret;
 
-	spin_lock_irqsave(&pll->lock, flags);
 	ret = lgm_get_clk_val(pll->membase, pll->reg, 0, 1);
-	spin_unlock_irqrestore(&pll->lock, flags);
 
 	return ret;
 }
@@ -71,16 +65,13 @@ static int lgm_pll_is_enabled(struct clk_hw *hw)
 static int lgm_pll_enable(struct clk_hw *hw)
 {
 	struct lgm_clk_pll *pll = to_lgm_clk_pll(hw);
-	unsigned long flags;
 	u32 val;
 	int ret;
 
-	spin_lock_irqsave(&pll->lock, flags);
 	lgm_set_clk_val(pll->membase, pll->reg, 0, 1, 1);
 	ret = regmap_read_poll_timeout_atomic(pll->membase, pll->reg,
 					      val, (val & 0x1), 1, 100);
 
-	spin_unlock_irqrestore(&pll->lock, flags);
 
 	return ret;
 }
@@ -88,11 +79,8 @@ static int lgm_pll_enable(struct clk_hw *hw)
 static void lgm_pll_disable(struct clk_hw *hw)
 {
 	struct lgm_clk_pll *pll = to_lgm_clk_pll(hw);
-	unsigned long flags;
 
-	spin_lock_irqsave(&pll->lock, flags);
 	lgm_set_clk_val(pll->membase, pll->reg, 0, 1, 0);
-	spin_unlock_irqrestore(&pll->lock, flags);
 }
 
 static const struct clk_ops lgm_pll_ops = {
@@ -123,7 +111,6 @@ lgm_clk_register_pll(struct lgm_clk_provider *ctx,
 		return ERR_PTR(-ENOMEM);
 
 	pll->membase = ctx->membase;
-	pll->lock = ctx->lock;
 	pll->reg = list->reg;
 	pll->flags = list->flags;
 	pll->type = list->type;
drivers/clk/x86/clk-cgu.c +9 -71

321 lines not on this page · raw message

drivers/clk/x86/clk-cgu.h +0 -6
index dbcb66468797..0aa0f35d63a0 100644
@@ -18,7 +18,6 @@ struct lgm_clk_mux {
 	u8 shift;
 	u8 width;
 	unsigned long flags;
-	spinlock_t lock;
 };
 
 struct lgm_clk_divider {
@@ -31,7 +30,6 @@ struct lgm_clk_divider {
 	u8 width_gate;
 	unsigned long flags;
 	const struct clk_div_table *table;
-	spinlock_t lock;
 };
 
 struct lgm_clk_ddiv {
@@ -49,7 +47,6 @@ struct lgm_clk_ddiv {
 	unsigned int mult;
 	unsigned int div;
 	unsigned long flags;
-	spinlock_t lock;
 };
 
 struct lgm_clk_gate {
@@ -58,7 +55,6 @@ struct lgm_clk_gate {
 	unsigned int reg;
 	u8 shift;
 	unsigned long flags;
-	spinlock_t lock;
 };
 
 enum lgm_clk_type {
@@ -82,7 +78,6 @@ struct lgm_clk_provider {
 	struct device_node *np;
 	struct device *dev;
 	struct clk_hw_onecell_data clk_data;
-	spinlock_t lock;
 };
 
 enum pll_type {
@@ -97,7 +92,6 @@ struct lgm_clk_pll {
 	unsigned int reg;
 	unsigned long flags;
 	enum pll_type type;
-	spinlock_t lock;
 };
 
 /**
drivers/clk/x86/clk-lgm.c +0 -1
index 4fa2bcaf71c8..e312af42e97a 100644
@@ -444,7 +444,6 @@ static int lgm_cgu_probe(struct platform_device *pdev)
 
 	ctx->np = np;
 	ctx->dev = dev;
-	spin_lock_init(&ctx->lock);
 
 	ret = lgm_clk_register_plls(ctx, lgm_pll_clks,
 				    ARRAY_SIZE(lgm_pll_clks));
Signature · 1 line
2.17.1
#7 lore raw

PATCH RESEND v2 3/5 clk: mxl: Avoid disabling gate clocks from clk driver

In reply to Rahul Tanwar

In MxL's LGM SoC, gate clocks are supposed to be enabled or disabled from EPU (power management IP) in certain power saving modes. If gate clocks are allowed to be enabled/disabled from CGU clk driver, then there arises a conflict where in case clk driver disables a gate clk, and then EPU tries to disable the same gate clk, then it will hang polling for the clk gated successful status.

To avoid such a conflict, disable gate clocks enabling/disabling from CGU clk driver. But add a GATE_CLK_HW flag to control this in order to be backward compatible with other SoCs which share the same CGU IP but not the same EPU IP.

---
 drivers/clk/x86/clk-cgu.c | 32 ++++++++++++++++++++++++--------
 drivers/clk/x86/clk-cgu.h |  1 +
 2 files changed, 25 insertions(+), 8 deletions(-)
drivers/clk/x86/clk-cgu.c +24 -8
index 1f7e93de67bc..d24173cfe0b0 100644
@@ -258,8 +258,12 @@ static int lgm_clk_gate_enable(struct clk_hw *hw)
 	struct lgm_clk_gate *gate = to_lgm_clk_gate(hw);
 	unsigned int reg;
 
-	reg = GATE_HW_REG_EN(gate->reg);
-	lgm_set_clk_val(gate->membase, reg, gate->shift, 1, 1);
+	if (gate->flags & GATE_CLK_HW) {
+		reg = GATE_HW_REG_EN(gate->reg);
+		lgm_set_clk_val(gate->membase, reg, gate->shift, 1, 1);
+	} else {
+		gate->reg = 1;
+	}
 
 	return 0;
 }
@@ -269,8 +273,12 @@ static void lgm_clk_gate_disable(struct clk_hw *hw)
 	struct lgm_clk_gate *gate = to_lgm_clk_gate(hw);
 	unsigned int reg;
 
-	reg = GATE_HW_REG_DIS(gate->reg);
-	lgm_set_clk_val(gate->membase, reg, gate->shift, 1, 1);
+	if (gate->flags & GATE_CLK_HW) {
+		reg = GATE_HW_REG_DIS(gate->reg);
+		lgm_set_clk_val(gate->membase, reg, gate->shift, 1, 1);
+	} else {
+		gate->reg = 0;
+	}
 }
 
 static int lgm_clk_gate_is_enabled(struct clk_hw *hw)
@@ -278,8 +286,12 @@ static int lgm_clk_gate_is_enabled(struct clk_hw *hw)
 	struct lgm_clk_gate *gate = to_lgm_clk_gate(hw);
 	unsigned int reg, ret;
 
-	reg = GATE_HW_REG_STAT(gate->reg);
-	ret = lgm_get_clk_val(gate->membase, reg, gate->shift, 1);
+	if (gate->flags & GATE_CLK_HW) {
+		reg = GATE_HW_REG_STAT(gate->reg);
+		ret = lgm_get_clk_val(gate->membase, reg, gate->shift, 1);
+	} else {
+		ret = gate->reg;
+	}
 
 	return ret;
 }
@@ -315,7 +327,8 @@ lgm_clk_register_gate(struct lgm_clk_provider *ctx,
 	init.num_parents = pname ? 1 : 0;
 
 	gate->membase = ctx->membase;
-	gate->reg = reg;
+	if (cflags & GATE_CLK_HW)
+		gate->reg = reg;
 	gate->shift = shift;
 	gate->flags = cflags;
 	gate->hw.init = &init;
@@ -326,7 +339,10 @@ lgm_clk_register_gate(struct lgm_clk_provider *ctx,
 		return ERR_PTR(ret);
 
 	if (cflags & CLOCK_FLAG_VAL_INIT) {
-		lgm_set_clk_val(gate->membase, reg, shift, 1, list->gate_val);
+		if (cflags & GATE_CLK_HW)
+			lgm_set_clk_val(gate->membase, reg, shift, 1, list->gate_val);
+		else
+			gate->reg = 1;
 	}
 
 	return hw;
drivers/clk/x86/clk-cgu.h +1 -0
index 0aa0f35d63a0..73ce84345f81 100644
@@ -197,6 +197,7 @@ struct lgm_clk_branch {
 /* clock flags definition */
 #define CLOCK_FLAG_VAL_INIT	BIT(16)
 #define MUX_CLK_SW		BIT(17)
+#define GATE_CLK_HW		BIT(18)
 
 #define LGM_MUX(_id, _name, _pdata, _f, _reg,		\
 		_shift, _width, _cf, _v)		\
Signature · 1 line
2.17.1
#18 lore raw

PATCH RESEND v2 4/5 clk: mxl: Add validation for register reads/writes

In reply to Rahul Tanwar

Some clocks support parent clock dividers but they do not support clock gating (clk enable/disable). Such types of clocks might call API's for get/set_reg_val routines with width as 0 during clk_prepare_enable() call. Handle such cases by first validating width during clk_prepare_enable() while still supporting clk_set_rate() correctly.

---
 drivers/clk/x86/clk-cgu.h | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)
drivers/clk/x86/clk-cgu.h +26 -4
index 73ce84345f81..46daf9ebd6c9 100644
@@ -299,29 +299,51 @@ struct lgm_clk_branch {
 static inline void lgm_set_clk_val(struct regmap *membase, u32 reg,
 				   u8 shift, u8 width, u32 set_val)
 {
-	u32 mask = (GENMASK(width - 1, 0) << shift);
+	u32 mask;
 
+	/*
+	 * Some clocks support parent clock dividers but they do not
+	 * support clock gating (clk enable/disable). Such types of
+	 * clocks might call this function with width as 0 during
+	 * clk_prepare_enable() call. Handle such cases by not doing
+	 * anything during clk_prepare_enable() but handle clk_set_rate()
+	 * correctly
+	 */
+	if (!width)
+		return;
+
+	mask = (GENMASK(width - 1, 0) << shift);
 	regmap_update_bits(membase, reg, mask, set_val << shift);
 }
 
 static inline u32 lgm_get_clk_val(struct regmap *membase, u32 reg,
 				  u8 shift, u8 width)
 {
-	u32 mask = (GENMASK(width - 1, 0) << shift);
+	u32 mask;
 	u32 val;
 
+	/*
+	 * Some clocks support parent clock dividers but they do not
+	 * support clock gating (clk enable/disable). Such types of
+	 * clocks might call this function with width as 0 during
+	 * clk_prepare_enable() call. Handle such cases by not doing
+	 * anything during clk_prepare_enable() but handle clk_set_rate()
+	 * correctly
+	 */
+	if (!width)
+		return 0;
+
 	if (regmap_read(membase, reg, &val)) {
 		WARN_ONCE(1, "Failed to read clk reg: 0x%x\n", reg);
 		return 0;
 	}
 
+	mask = (GENMASK(width - 1, 0) << shift);
 	val = (val & mask) >> shift;
 
 	return val;
 }
 
-
-
 int lgm_clk_register_branches(struct lgm_clk_provider *ctx,
 			      const struct lgm_clk_branch *list,
 			      unsigned int nr_clk);
Signature · 1 line
2.17.1
#24 lore raw

PATCH RESEND v2 5/5 clk: mxl: Add a missing flag to allow parent clock rate change

In reply to Rahul Tanwar

One of the clock entry "dcl" clk's rate can only be changed by changing its parent's clock rate. But it was missing to have CLK_SET_RATE_PARENT flag as enabled.

Add/enable CLK_SET_RATE_PARENT flag for dcl clk in order to allow its clk rate to be changed via its parent's clk.

---
 drivers/clk/x86/clk-lgm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/x86/clk-lgm.c +1 -1
index e312af42e97a..34e16ea90596 100644
@@ -255,7 +255,7 @@ static const struct lgm_clk_branch lgm_branch_clks[] = {
 	LGM_FIXED(LGM_CLK_SLIC, "slic", NULL, 0, CGU_IF_CLK1,
 		  8, 2, CLOCK_FLAG_VAL_INIT, 8192000, 2),
 	LGM_FIXED(LGM_CLK_DOCSIS, "v_docsis", NULL, 0, 0, 0, 0, 0, 16000000, 0),
-	LGM_DIV(LGM_CLK_DCL, "dcl", "v_ifclk", 0, CGU_PCMCR,
+	LGM_DIV(LGM_CLK_DCL, "dcl", "v_ifclk", CLK_SET_RATE_PARENT, CGU_PCMCR,
 		25, 3, 0, 0, 0, 0, dcl_div),
 	LGM_MUX(LGM_CLK_PCM, "pcm", pcm_p, 0, CGU_C55_PCMCR,
 		0, 1, CLK_MUX_ROUND_CLOSEST, 0),
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH RESEND v2 1/5] clk: mxl: Switch from direct readl/writel based IO to regmap based IO

In reply to Rahul Tanwar

Quoting Rahul Tanwar (2022-09-21 23:24:24)

drivers/clk/x86/clk-cgu-pll.c line 5

Quoted 12 lines
drivers/clk/x86/clk-cgu-pll.c +2 -2
index 3179557b5f78..c83083affe88 100644
@@ -1,8 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
+ * Copyright (C) 2020-2022 MaxLinear, Inc.
  * Copyright (C) 2020 Intel Corporation.
- * Zhu YiXin <[email protected]>
- * Rahul Tanwar <[email protected]>
+ * Zhu Yixin <[email protected]>

Does Zhu Yixin approve? They're not Cced on this patch.

Quoted 4 lines
drivers/clk/x86/clk-cgu-pll.c +1 -0
+ * Rahul Tanwar <[email protected]>
  */
 
 #include <linux/clk-provider.h>
maintainer
#5 lore raw

Re: [PATCH RESEND v2 2/5] clk: mxl: Remove unnecessary spinlocks

In reply to Rahul Tanwar

Quoting Rahul Tanwar (2022-09-21 23:24:25)

Quoted 6 lines

This driver is now switched from direct readl/writel based register access to regmap based register acceess. Regmap already has its own lock to serialize the register accesses across multiple cores.

Hence, there is no need for additional spinlocks in the driver. Remove all spinlocks which are no longer required.

Can you confirm that the driver doesn't do a read, modify, write (rmw) sequence where during the modification another CPU can rmw and corrupt the previous "read"?

maintainer
#8 lore raw

Re: [PATCH RESEND v2 3/5] clk: mxl: Avoid disabling gate clocks from clk driver

In reply to Rahul Tanwar

Quoting Rahul Tanwar (2022-09-21 23:24:26)

Quoted 6 lines

In MxL's LGM SoC, gate clocks are supposed to be enabled or disabled from EPU (power management IP) in certain power saving modes. If gate clocks are allowed to be enabled/disabled from CGU clk driver, then there arises a conflict where in case clk driver disables a gate clk, and then EPU tries to disable the same gate clk, then it will hang polling for the clk gated successful status.

Is there any point in registering these clks when they're not supposed to be controlled from Linux?

maintainer
#25 lore raw

Re: [PATCH RESEND v2 5/5] clk: mxl: Add a missing flag to allow parent clock rate change

In reply to Rahul Tanwar

Quoting Rahul Tanwar (2022-09-21 23:24:28)

Quoted 9 lines

One of the clock entry "dcl" clk's rate can only be changed by changing its parent's clock rate. But it was missing to have CLK_SET_RATE_PARENT flag as enabled.

Add/enable CLK_SET_RATE_PARENT flag for dcl clk in order to allow its clk rate to be changed via its parent's clk.

---

Any Fixes tag?

maintainer
#19 lore raw

Re: [PATCH RESEND v2 4/5] clk: mxl: Add validation for register reads/writes

In reply to Rahul Tanwar

Quoting Rahul Tanwar (2022-09-21 23:24:27)

Quoted 23 lines

Some clocks support parent clock dividers but they do not support clock gating (clk enable/disable). Such types of clocks might call API's for get/set_reg_val routines with width as 0 during clk_prepare_enable() call. Handle such cases by first validating width during clk_prepare_enable() while still supporting clk_set_rate() correctly.

---
 drivers/clk/x86/clk-cgu.h | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)
drivers/clk/x86/clk-cgu.h +1 -1
index 73ce84345f81..46daf9ebd6c9 100644
@@ -299,29 +299,51 @@ struct lgm_clk_branch {
 static inline void lgm_set_clk_val(struct regmap *membase, u32 reg,
                                   u8 shift, u8 width, u32 set_val)
 {
-       u32 mask = (GENMASK(width - 1, 0) << shift);
+       u32 mask;
 

drivers/clk/x86/clk-cgu.h struct lgm_clk_branch { · line 313

Quoted 10 lines
drivers/clk/x86/clk-cgu.h +10 -0
+       /*
+        * Some clocks support parent clock dividers but they do not
+        * support clock gating (clk enable/disable). Such types of
+        * clocks might call this function with width as 0 during
+        * clk_prepare_enable() call. Handle such cases by not doing
+        * anything during clk_prepare_enable() but handle clk_set_rate()
+        * correctly
+        */
+       if (!width)
+               return;

Why are the clk_ops assigned in a way that makes the code get here? Why can't we have different clk_ops, or not register the clks at all, when the hardware can't be written?

Quoted 3 lines
drivers/clk/x86/clk-cgu.h +2 -0
+
+       mask = (GENMASK(width - 1, 0) << shift);
        regmap_update_bits(membase, reg, mask, set_val << shift);
#3 lore raw

Re: [PATCH RESEND v2 1/5] clk: mxl: Switch from direct readl/writel based IO to regmap based IO

In reply to Stephen Boyd

Hi Stephen,

Thanks for review and response.

Quoted 4 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-21 23:24:24)

Quoted 14 lines

drivers/clk/x86/clk-cgu-pll.c line 5

Quoted 12 lines
drivers/clk/x86/clk-cgu-pll.c +2 -2
index 3179557b5f78..c83083affe88 100644
@@ -1,8 +1,9 @@
  // SPDX-License-Identifier: GPL-2.0
  /*
+ * Copyright (C) 2020-2022 MaxLinear, Inc.
   * Copyright (C) 2020 Intel Corporation.
- * Zhu YiXin <[email protected]>
- * Rahul Tanwar <[email protected]>
+ * Zhu Yixin <[email protected]>

Does Zhu Yixin approve? They're not Cced on this patch.

Zhu Yixin is part of [email protected] mail list which is CCed here. In v3, i will separately CC Yixin and request him to review again and provide a Reviewed-by tag if no concerns.

Thanks,
Rahul

Quoted 7 lines
Quoted 5 lines
drivers/clk/x86/clk-cgu-pll.c +1 -0
+ * Rahul Tanwar <[email protected]>
   */
 
  #include <linux/clk-provider.h>
#6 lore raw

Re: [PATCH RESEND v2 2/5] clk: mxl: Remove unnecessary spinlocks

In reply to Stephen Boyd
Quoted 8 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-21 23:24:25)

Quoted 4 lines

This driver is now switched from direct readl/writel based register access to regmap based register acceess. Regmap already has its own lock to serialize the register accesses across multiple cores.

Quoted 6 lines
Quoted 2 lines

Hence, there is no need for additional spinlocks in the driver. Remove all spinlocks which are no longer required.

Can you confirm that the driver doesn't do a read, modify, write (rmw) sequence where during the modification another CPU can rmw and corrupt the previous "read"?

For rmw, driver uses regmap_update_bits() API. All regmap API's use their own spinlocks before doing any read or write or rmw.

Patch 1/5 switches from direct readl/writel to regmap based API's for register read/write/rmw in which case additional driver spinlock becomes redundant. So this patch 2/5 removes redundant driver spin locks.

Thanks,
Rahul

Quoted 2 lines
#9 lore raw

Re: [PATCH RESEND v2 3/5] clk: mxl: Avoid disabling gate clocks from clk driver

In reply to Stephen Boyd
Quoted 11 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-21 23:24:26)

Quoted 6 lines

In MxL's LGM SoC, gate clocks are supposed to be enabled or disabled from EPU (power management IP) in certain power saving modes. If gate clocks are allowed to be enabled/disabled from CGU clk driver, then there arises a conflict where in case clk driver disables a gate clk, and then EPU tries to disable the same gate clk, then it will hang polling for the clk gated successful status.

Quoted 2 lines

Is there any point in registering these clks when they're not supposed to be controlled from Linux?

As mentioned in the full commit log, only reason to register these clks is to be backward compatible with older versions of similar SoC's which reuse the same clk CGU IP but do not use same power management IP. Such older SoCs also use the same clk driver and for them these clks are required to be controlled by clk ops from Linux.

Thanks,
Rahul

Quoted 2 lines
#26 lore raw

Re: [PATCH RESEND v2 5/5] clk: mxl: Add a missing flag to allow parent clock rate change

In reply to Stephen Boyd
Quoted 8 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-21 23:24:28)

Quoted 4 lines

One of the clock entry "dcl" clk's rate can only be changed by changing its parent's clock rate. But it was missing to have CLK_SET_RATE_PARENT flag as enabled.

Quoted 8 lines
Quoted 5 lines

Add/enable CLK_SET_RATE_PARENT flag for dcl clk in order to allow its clk rate to be changed via its parent's clk.

---

Any Fixes tag?

Missed it, will add in v3.

Thanks,
Rahul

Quoted 1 line
#20 lore raw

Re: [PATCH RESEND v2 4/5] clk: mxl: Add validation for register reads/writes

In reply to Stephen Boyd
Quoted 27 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-21 23:24:27)

Quoted 23 lines

Some clocks support parent clock dividers but they do not support clock gating (clk enable/disable). Such types of clocks might call API's for get/set_reg_val routines with width as 0 during clk_prepare_enable() call. Handle such cases by first validating width during clk_prepare_enable() while still supporting clk_set_rate() correctly.

---
  drivers/clk/x86/clk-cgu.h | 30 ++++++++++++++++++++++++++----
  1 file changed, 26 insertions(+), 4 deletions(-)
drivers/clk/x86/clk-cgu.h +1 -1
index 73ce84345f81..46daf9ebd6c9 100644
@@ -299,29 +299,51 @@ struct lgm_clk_branch {
  static inline void lgm_set_clk_val(struct regmap *membase, u32 reg,
                                    u8 shift, u8 width, u32 set_val)
  {
-       u32 mask = (GENMASK(width - 1, 0) << shift);
+       u32 mask;
 
Quoted 14 lines

drivers/clk/x86/clk-cgu.h struct lgm_clk_branch { · line 313

Quoted 10 lines
drivers/clk/x86/clk-cgu.h +10 -0
+       /*
+        * Some clocks support parent clock dividers but they do not
+        * support clock gating (clk enable/disable). Such types of
+        * clocks might call this function with width as 0 during
+        * clk_prepare_enable() call. Handle such cases by not doing
+        * anything during clk_prepare_enable() but handle clk_set_rate()
+        * correctly
+        */
+       if (!width)
+               return;

Why are the clk_ops assigned in a way that makes the code get here? Why can't we have different clk_ops, or not register the clks at all, when the hardware can't be written?

The hardware can actually be written for such clks but only for clk_set_rate() op for setting the clk rate. Just that hardware does not provide any way to enable/disable such clks.

Alternative way to handle such clks could be that the clk consumer does not invoke clk_prepare_enable() before invoking clk_set_rate(). But we want to avoid making changes in the clk consumer code to keep it standard. And handle it here by just validating the width parameter.

Thanks,
Rahul

Quoted 6 lines
Quoted 4 lines
drivers/clk/x86/clk-cgu.h +2 -0
+
+       mask = (GENMASK(width - 1, 0) << shift);
         regmap_update_bits(membase, reg, mask, set_val << shift);
#11 lore raw

Re: [PATCH RESEND v2 3/5] clk: mxl: Avoid disabling gate clocks from clk driver

In reply to a message not in the archive

Hi Stephen,

Quoted 27 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-28 22:45:59)

Quoted 16 lines · Stephen Boyd
Quoted 11 lines

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-21 23:24:26)

Quoted 6 lines

In MxL's LGM SoC, gate clocks are supposed to be enabled or disabled from EPU (power management IP) in certain power saving modes. If gate clocks are allowed to be enabled/disabled from CGU clk driver, then there arises a conflict where in case clk driver disables a gate clk, and then EPU tries to disable the same gate clk, then it will hang polling for the clk gated successful status.

Quoted 2 lines

Is there any point in registering these clks when they're not supposed to be controlled from Linux?

Quoted 6 lines

As mentioned in the full commit log, only reason to register these clks is to be backward compatible with older versions of similar SoC's which reuse the same clk CGU IP but do not use same power management IP. Such older SoCs also use the same clk driver and for them these clks are required to be controlled by clk ops from Linux.

Quoted 4 lines

Why is the clk driver probing on the new SoCs? Is it providing something? Can we detect that the power management IP exists and not register these clks?

We discussed in the team about not registering gate clks at all as you mentioned. But if we do that, all peripheral drivers that use these clks would need modifications so their probe does not fail due to failure returns of clk related standard calls for e.g devm_clk_get(), clk_prepare_enable(). These are standard calls in probe for all the drivers and a lot of them use gate clks. So this would need a lot of changes with possibility of breaking working functionalities.

Also, i incorrectly mentioned about the reason being backward compatibility with older SoCs. Main reason is to support different power profiles use cases as per end product requirements some of which might control it from clk framework i.e. this driver. We keep a internal driver flag just for this purpose to provide this flexibility depending on the use case which is what we have used here.

I am sending v3 with more clear & correct description about it to justify the need for these changes.

Thanks,
Rahul

Quoted 1 line
#22 lore raw

Re: [PATCH RESEND v2 4/5] clk: mxl: Add validation for register reads/writes

In reply to a message not in the archive

Hi Stephen,

Quoted 27 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-28 23:10:10)

Quoted 23 lines · Stephen Boyd
Quoted 13 lines

drivers/clk/x86/clk-cgu.h struct lgm_clk_branch { · line 313

Quoted 12 lines
drivers/clk/x86/clk-cgu.h +11 -0
+       u32 mask;
 
+       /*
+        * Some clocks support parent clock dividers but they do not
+        * support clock gating (clk enable/disable). Such types of
+        * clocks might call this function with width as 0 during
+        * clk_prepare_enable() call. Handle such cases by not doing
+        * anything during clk_prepare_enable() but handle clk_set_rate()
+        * correctly
+        */
+       if (!width)
+               return;
Quoted 3 lines

Why are the clk_ops assigned in a way that makes the code get here? Why can't we have different clk_ops, or not register the clks at all, when the hardware can't be written?

The hardware can actually be written for such clks but only for clk_set_rate() op for setting the clk rate. Just that hardware does not provide any way to enable/disable such clks.

Quoted 8 lines
Quoted 4 lines

Alternative way to handle such clks could be that the clk consumer does not invoke clk_prepare_enable() before invoking clk_set_rate(). But we want to avoid making changes in the clk consumer code to keep it standard. And handle it here by just validating the width parameter.

Why not have different clk_ops then that doesn't do anything for enable/disable and only does it for set_rate?

There is only one clk entry which falls in this category. Adding a different clk_ops for just one clk would need many more lines of code addition which appears to be a overkill.

I have removed this change in v3 and used the driver internal flag to handle this particular clk. That requires minimal change and looks logical addition.

Thanks,
Rahul

Quoted 1 line
#17 lore raw

Re: [PATCH RESEND v2 3/5] clk: mxl: Avoid disabling gate clocks from clk driver

In reply to a message not in the archive

[Resend due to mail delivery failure in earlier reply - one email id got corrupted somehow in earlier reply]

Hi Stephen,

Quoted 27 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-28 22:45:59)

Quoted 16 lines · Stephen Boyd
Quoted 11 lines

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-21 23:24:26)

Quoted 6 lines

In MxL's LGM SoC, gate clocks are supposed to be enabled or disabled from EPU (power management IP) in certain power saving modes. If gate clocks are allowed to be enabled/disabled from CGU clk driver, then there arises a conflict where in case clk driver disables a gate clk, and then EPU tries to disable the same gate clk, then it will hang polling for the clk gated successful status.

Quoted 2 lines

Is there any point in registering these clks when they're not supposed to be controlled from Linux?

Quoted 6 lines

As mentioned in the full commit log, only reason to register these clks is to be backward compatible with older versions of similar SoC's which reuse the same clk CGU IP but do not use same power management IP. Such older SoCs also use the same clk driver and for them these clks are required to be controlled by clk ops from Linux.

Quoted 4 lines

Why is the clk driver probing on the new SoCs? Is it providing something? Can we detect that the power management IP exists and not register these clks?

We discussed in the team about not registering gate clks at all as you mentioned. But if we do that, all peripheral drivers that use these clks would need modifications so their probe does not fail due to failure returns of clk related standard calls for e.g devm_clk_get(), clk_prepare_enable(). These are standard calls in probe for all the drivers and a lot of them use gate clks. So this would need a lot of changes with possibility of breaking working functionalities.

Also, i incorrectly mentioned about the reason being backward compatibility with older SoCs. Main reason is to support different power profiles use cases as per end product requirements some of which might control it from clk framework i.e. this driver. We keep a internal driver flag just for this purpose to provide this flexibility depending on the use case which is what we have used here.

I am sending v3 with more clear & correct description about it to justify the need for these changes.

Thanks,
Rahul

Quoted 1 line
#23 lore raw

Re: [PATCH RESEND v2 4/5] clk: mxl: Add validation for register reads/writes

In reply to a message not in the archive

[Resend due to mail delivery failure in earlier reply - one email id got corrupted somehow in earlier reply]

Hi Stephen,

Quoted 27 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-09-28 23:10:10)

Quoted 23 lines · Stephen Boyd
Quoted 13 lines

drivers/clk/x86/clk-cgu.h struct lgm_clk_branch { · line 313

Quoted 12 lines
drivers/clk/x86/clk-cgu.h +11 -0
+       u32 mask;
 
+       /*
+        * Some clocks support parent clock dividers but they do not
+        * support clock gating (clk enable/disable). Such types of
+        * clocks might call this function with width as 0 during
+        * clk_prepare_enable() call. Handle such cases by not doing
+        * anything during clk_prepare_enable() but handle clk_set_rate()
+        * correctly
+        */
+       if (!width)
+               return;
Quoted 3 lines

Why are the clk_ops assigned in a way that makes the code get here? Why can't we have different clk_ops, or not register the clks at all, when the hardware can't be written?

The hardware can actually be written for such clks but only for clk_set_rate() op for setting the clk rate. Just that hardware does not provide any way to enable/disable such clks.

Quoted 8 lines
Quoted 4 lines

Alternative way to handle such clks could be that the clk consumer does not invoke clk_prepare_enable() before invoking clk_set_rate(). But we want to avoid making changes in the clk consumer code to keep it standard. And handle it here by just validating the width parameter.

Why not have different clk_ops then that doesn't do anything for enable/disable and only does it for set_rate?

There is only one clk entry which falls in this category. Adding a different clk_ops for just one clk would need many more lines of code addition which appears to be a overkill.

I have removed this change in v3 and used the driver internal flag to handle this particular clk. That requires minimal change and looks logical addition.

Thanks,
Rahul

Quoted 1 line
#13 lore raw

Re: [PATCH RESEND v2 3/5] clk: mxl: Avoid disabling gate clocks from clk driver

In reply to a message not in the archive

Hi Stephen,

Quoted 19 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-10-05 02:36:00)

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Why is the clk driver probing on the new SoCs? Is it providing something? Can we detect that the power management IP exists and not register these clks?

Quoted 7 lines

We discussed in the team about not registering gate clks at all as you mentioned. But if we do that, all peripheral drivers that use these clks would need modifications so their probe does not fail due to failure returns of clk related standard calls for e.g devm_clk_get(), clk_prepare_enable(). These are standard calls in probe for all the drivers and a lot of them use gate clks. So this would need a lot of changes with possibility of breaking working functionalities.

Quoted 6 lines

Why? We can have clk_get() return NULL when these clks can't be used. This is how we implement "dummy" clks on systems where the clk provider can provide the clk but there's nothing to do for the clk operations. The clk API treats NULL as a valid clk but bails out early when calling any consumer APIs.

I agree that what you are suggesting is the ideal way to handle such clks. If i understand you correctly, you are suggesting below (please correct me if i am mistaken):

1. Disable/remove such clocks from corresponding driver's devicetree nodes. This will make devm_clk_get() or clk_get() return failure.

2. Modify all drivers which use such clks

from:

    clk = devm_clk_get(...);
    if (IS_ERR(clk))
        return -ERROR;
    clk_prepare_enable(clk);
    clk_get/set_rate();
    ...

to:

    clk = devm_clk_get(...);
    if (!(IS_ERR(clk)) {
        clk_prepare_enable(clk);
        clk_get/set_rate();
        ...
    } else {
       // print error info - do nothing, no clk_ops calls
    }

But the problem that we have is that 80% of the clks that we use fall under this category (around 65 clks). And if we follow this approach, then we will have to make above changes in all of the drivers which use these clks & retest them again. That seems like a overhaul. We already keep a internal driver flag in each clk entry data structure and we already use it in the driver for other types of clks for e.g MUX_CLKs. So using the internal flag to handle this becomes a preferable & existing driver design aligned approach for us.

Thanks,
Rahul

Quoted 15 lines
Quoted 11 lines

Also, i incorrectly mentioned about the reason being backward compatibility with older SoCs. Main reason is to support different power profiles use cases as per end product requirements some of which might control it from clk framework i.e. this driver. We keep a internal driver flag just for this purpose to provide this flexibility depending on the use case which is what we have used here.

I am sending v3 with more clear & correct description about it to justify the need for these changes.

Ok

#16 lore raw

Re: [PATCH RESEND v2 3/5] clk: mxl: Avoid disabling gate clocks from clk driver

In reply to a message not in the archive

Hi Stephen,

Quoted 19 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-10-05 02:36:00)

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Why is the clk driver probing on the new SoCs? Is it providing something? Can we detect that the power management IP exists and not register these clks?

Quoted 7 lines

We discussed in the team about not registering gate clks at all as you mentioned. But if we do that, all peripheral drivers that use these clks would need modifications so their probe does not fail due to failure returns of clk related standard calls for e.g devm_clk_get(), clk_prepare_enable(). These are standard calls in probe for all the drivers and a lot of them use gate clks. So this would need a lot of changes with possibility of breaking working functionalities.

Quoted 6 lines

Why? We can have clk_get() return NULL when these clks can't be used. This is how we implement "dummy" clks on systems where the clk provider can provide the clk but there's nothing to do for the clk operations. The clk API treats NULL as a valid clk but bails out early when calling any consumer APIs.

I agree that what you are suggesting is the ideal way to handle such clks. If i understand you correctly, you are suggesting below (please correct me if i am mistaken):

1. Disable/remove such clocks from corresponding driver's devicetree nodes. This will make devm_clk_get() or clk_get() return failure.

2. Modify all drivers which use such clks

from:

     clk = devm_clk_get(...);
     if (IS_ERR(clk))
         return -ERROR;
     clk_prepare_enable(clk);
     clk_get/set_rate();
     ...

to:

     clk = devm_clk_get(...);
     if (!(IS_ERR(clk)) {
         clk_prepare_enable(clk);
         clk_get/set_rate();
         ...
     } else {
        // print error info - do nothing, no clk_ops calls
     }

But the problem that we have is that 80% of the clks that we use fall under this category (around 65 clks). And if we follow this approach, then we will have to make above changes in all of the drivers which use these clks & retest them again. That seems like a overhaul. We already keep a internal driver flag in each clk entry data structure and we already use it in the driver for other types of clks for e.g MUX_CLKs. So using the internal flag to handle this becomes a preferable & existing driver design aligned approach for us.

Thanks,
Rahul

Quoted 15 lines
Quoted 11 lines

Also, i incorrectly mentioned about the reason being backward compatibility with older SoCs. Main reason is to support different power profiles use cases as per end product requirements some of which might control it from clk framework i.e. this driver. We keep a internal driver flag just for this purpose to provide this flexibility depending on the use case which is what we have used here.

I am sending v3 with more clear & correct description about it to justify the need for these changes.

Ok

#15 lore raw

Re: [PATCH RESEND v2 3/5] clk: mxl: Avoid disabling gate clocks from clk driver

In reply to a message not in the archive

Hi Stephen,

Quoted 54 lines · Stephen Boyd

This email was sent from outside of MaxLinear.

Quoting Rahul Tanwar (2022-10-11 00:28:56)

Quoted 7 lines

I agree that what you are suggesting is the ideal way to handle such clks. If i understand you correctly, you are suggesting below (please correct me if i am mistaken):

1. Disable/remove such clocks from corresponding driver's devicetree nodes. This will make devm_clk_get() or clk_get() return failure.

No. Don't remove anything from devicetree, simply make the clk provider return NULL when the clk_src_get() function pointer is asked for the clk index that represents the clks that have no abilities to do anything.

Quoted 13 lines

2. Modify all drivers which use such clks

from:

     clk = devm_clk_get(...);
     if (IS_ERR(clk))
         return -ERROR;
     clk_prepare_enable(clk);
     clk_get/set_rate();
     ...

to:

Quoted 8 lines
     clk = devm_clk_get(...);
     if (!(IS_ERR(clk)) {
         clk_prepare_enable(clk);
         clk_get/set_rate();
         ...
     } else {
        // print error info - do nothing, no clk_ops calls
     }

No. Nothing in the drivers changes. The 'clk' pointer will be NULL, that will not make the 'if (IS_ERR(clk))' condition be true, so return -ERROR won't happen. Similarly, clk_prepare_enable() will return 0 when called with a NULL pointer. Please try it out.

Quoted 10 lines

But the problem that we have is that 80% of the clks that we use fall under this category (around 65 clks). And if we follow this approach, then we will have to make above changes in all of the drivers which use these clks & retest them again. That seems like a overhaul. We already keep a internal driver flag in each clk entry data structure and we already use it in the driver for other types of clks for e.g MUX_CLKs. So using the internal flag to handle this becomes a preferable & existing driver design aligned approach for us.

Quoted 2 lines

There isn't an overhaul.

After going through the code again together with your comments, now i understand exactly what you are suggesting. I will make the changes accordingly in v4. Thanks for your valuable inputs.

Rahul

Quoted 1 line