All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v3 0/4] Extend lan966x clock driver for clock gating support
@ 2021-11-01  8:08 Horatiu Vultur
  2021-11-01  8:08 ` [RFC PATCH v3 1/4] clk: gate: Add devm_clk_hw_register_gate() Horatiu Vultur
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Horatiu Vultur @ 2021-11-01  8:08 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, nicolas.ferre, kavyasree.kotagiri,
	eugen.hristev, linux-clk, devicetree, linux-kernel
  Cc: Horatiu Vultur

This patch series depends on the following series, therefor keep it as RFC.
https://www.spinics.net/lists/linux-clk/msg62795.html

This patch series extend the clock driver to support also clock gating.

v2->v3:
 - add devm_clk_hw_register_gate function

v1->v2:
 - add Acked-by tag for patch 2
 - make the resource for clock gating as an optional resource

Horatiu Vultur (4):
  clk: gate: Add devm_clk_hw_register_gate()
  dt-bindings: clock: lan966x: Extend for clock gate support
  dt-bindings: clock: lan966x: Extend includes with clock gates
  clk: lan966x: Extend lan966x clock driver for clock gating support

 .../bindings/clock/microchip,lan966x-gck.yaml |  3 +-
 drivers/clk/clk-gate.c                        | 35 +++++++++++
 drivers/clk/clk-lan966x.c                     | 59 ++++++++++++++++++-
 include/dt-bindings/clock/microchip,lan966x.h |  8 ++-
 include/linux/clk-provider.h                  | 23 ++++++++
 5 files changed, 123 insertions(+), 5 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC PATCH v3 1/4] clk: gate: Add devm_clk_hw_register_gate()
  2021-11-01  8:08 [RFC PATCH v3 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
@ 2021-11-01  8:08 ` Horatiu Vultur
  2021-11-01  8:08 ` [RFC PATCH v3 2/4] dt-bindings: clock: lan966x: Extend for clock gate support Horatiu Vultur
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Horatiu Vultur @ 2021-11-01  8:08 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, nicolas.ferre, kavyasree.kotagiri,
	eugen.hristev, linux-clk, devicetree, linux-kernel
  Cc: Horatiu Vultur

Add devm_clk_hw_register_gate() - devres-managed version of
clk_hw_register_gate()

Suggested-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 drivers/clk/clk-gate.c       | 35 +++++++++++++++++++++++++++++++++++
 include/linux/clk-provider.h | 23 +++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index 070dc47e95a1..64283807600b 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/clk-provider.h>
+#include <linux/device.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/io.h>
@@ -222,3 +223,37 @@ void clk_hw_unregister_gate(struct clk_hw *hw)
 	kfree(gate);
 }
 EXPORT_SYMBOL_GPL(clk_hw_unregister_gate);
+
+static void devm_clk_hw_release_gate(struct device *dev, void *res)
+{
+	clk_hw_unregister_gate(*(struct clk_hw **)res);
+}
+
+struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
+		struct device_node *np, const char *name,
+		const char *parent_name, const struct clk_hw *parent_hw,
+		const struct clk_parent_data *parent_data,
+		unsigned long flags,
+		void __iomem *reg, u8 bit_idx,
+		u8 clk_gate_flags, spinlock_t *lock)
+{
+	struct clk_hw **ptr, *hw;
+
+	ptr = devres_alloc(devm_clk_hw_release_gate, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	hw = __clk_hw_register_gate(dev, np, name, parent_name, parent_hw,
+				    parent_data, flags, reg, bit_idx,
+				    clk_gate_flags, lock);
+
+	if (!IS_ERR(hw)) {
+		*ptr = hw;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return hw;
+}
+EXPORT_SYMBOL_GPL(__devm_clk_hw_register_gate);
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index f59c875271a0..2faa6f7aa8a8 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -490,6 +490,13 @@ struct clk_hw *__clk_hw_register_gate(struct device *dev,
 		unsigned long flags,
 		void __iomem *reg, u8 bit_idx,
 		u8 clk_gate_flags, spinlock_t *lock);
+struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
+		struct device_node *np, const char *name,
+		const char *parent_name, const struct clk_hw *parent_hw,
+		const struct clk_parent_data *parent_data,
+		unsigned long flags,
+		void __iomem *reg, u8 bit_idx,
+		u8 clk_gate_flags, spinlock_t *lock);
 struct clk *clk_register_gate(struct device *dev, const char *name,
 		const char *parent_name, unsigned long flags,
 		void __iomem *reg, u8 bit_idx,
@@ -544,6 +551,22 @@ struct clk *clk_register_gate(struct device *dev, const char *name,
 	__clk_hw_register_gate((dev), NULL, (name), NULL, NULL, (parent_data), \
 			       (flags), (reg), (bit_idx),		      \
 			       (clk_gate_flags), (lock))
+/**
+ * devm_clk_hw_register_gate - register a gate clock with the clock framework
+ * @dev: device that is registering this clock
+ * @name: name of this clock
+ * @parent_name: name of this clock's parent
+ * @flags: framework-specific flags for this clock
+ * @reg: register address to control gating of this clock
+ * @bit_idx: which bit in the register controls gating of this clock
+ * @clk_gate_flags: gate-specific flags for this clock
+ * @lock: shared register lock for this clock
+ */
+#define devm_clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx,\
+				  clk_gate_flags, lock)			      \
+	__devm_clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
+			       NULL, (flags), (reg), (bit_idx),		      \
+			       (clk_gate_flags), (lock))
 void clk_unregister_gate(struct clk *clk);
 void clk_hw_unregister_gate(struct clk_hw *hw);
 int clk_gate_is_enabled(struct clk_hw *hw);
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH v3 2/4] dt-bindings: clock: lan966x: Extend for clock gate support
  2021-11-01  8:08 [RFC PATCH v3 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
  2021-11-01  8:08 ` [RFC PATCH v3 1/4] clk: gate: Add devm_clk_hw_register_gate() Horatiu Vultur
@ 2021-11-01  8:08 ` Horatiu Vultur
  2021-11-02 17:47   ` Rob Herring
  2021-11-01  8:08 ` [RFC PATCH v3 3/4] dt-bindings: clock: lan966x: Extend includes with clock gates Horatiu Vultur
  2021-11-01  8:08 ` [RFC PATCH v3 4/4] clk: lan966x: Extend lan966x clock driver for clock gating support Horatiu Vultur
  3 siblings, 1 reply; 6+ messages in thread
From: Horatiu Vultur @ 2021-11-01  8:08 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, nicolas.ferre, kavyasree.kotagiri,
	eugen.hristev, linux-clk, devicetree, linux-kernel
  Cc: Horatiu Vultur

Allow to add an optional resource to be able to access the clock gate
registers.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 .../devicetree/bindings/clock/microchip,lan966x-gck.yaml       | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml b/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml
index fca83bd68e26..a53c889629da 100644
--- a/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml
+++ b/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml
@@ -19,7 +19,8 @@ properties:
     const: microchip,lan966x-gck
 
   reg:
-    maxItems: 1
+    minItems: 1
+    maxItems: 2
 
   clocks:
     items:
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH v3 3/4] dt-bindings: clock: lan966x: Extend includes with clock gates
  2021-11-01  8:08 [RFC PATCH v3 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
  2021-11-01  8:08 ` [RFC PATCH v3 1/4] clk: gate: Add devm_clk_hw_register_gate() Horatiu Vultur
  2021-11-01  8:08 ` [RFC PATCH v3 2/4] dt-bindings: clock: lan966x: Extend for clock gate support Horatiu Vultur
@ 2021-11-01  8:08 ` Horatiu Vultur
  2021-11-01  8:08 ` [RFC PATCH v3 4/4] clk: lan966x: Extend lan966x clock driver for clock gating support Horatiu Vultur
  3 siblings, 0 replies; 6+ messages in thread
From: Horatiu Vultur @ 2021-11-01  8:08 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, nicolas.ferre, kavyasree.kotagiri,
	eugen.hristev, linux-clk, devicetree, linux-kernel
  Cc: Horatiu Vultur, Rob Herring

On lan966x it is allow to control the clock to some peripherals like
USB. So extend the include file with these clocks.

Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 include/dt-bindings/clock/microchip,lan966x.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/dt-bindings/clock/microchip,lan966x.h b/include/dt-bindings/clock/microchip,lan966x.h
index fe36ed6d8b5f..6f9d43d76d5a 100644
--- a/include/dt-bindings/clock/microchip,lan966x.h
+++ b/include/dt-bindings/clock/microchip,lan966x.h
@@ -23,6 +23,12 @@
 #define GCK_ID_TIMER		12
 #define GCK_ID_USB_REFCLK	13
 
-#define N_CLOCKS		14
+/* Gate clocks */
+#define GCK_GATE_UHPHS		14
+#define GCK_GATE_UDPHS		15
+#define GCK_GATE_MCRAMC		16
+#define GCK_GATE_HMATRIX	17
+
+#define N_CLOCKS		18
 
 #endif
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH v3 4/4] clk: lan966x: Extend lan966x clock driver for clock gating support
  2021-11-01  8:08 [RFC PATCH v3 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
                   ` (2 preceding siblings ...)
  2021-11-01  8:08 ` [RFC PATCH v3 3/4] dt-bindings: clock: lan966x: Extend includes with clock gates Horatiu Vultur
@ 2021-11-01  8:08 ` Horatiu Vultur
  3 siblings, 0 replies; 6+ messages in thread
From: Horatiu Vultur @ 2021-11-01  8:08 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, nicolas.ferre, kavyasree.kotagiri,
	eugen.hristev, linux-clk, devicetree, linux-kernel
  Cc: Horatiu Vultur

Extend the clock driver to add support also for clock gating. The
following peripherals can be gated: UHPHS, UDPHS, MCRAMC, HMATRIX.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 drivers/clk/clk-lan966x.c | 59 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 56 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-lan966x.c b/drivers/clk/clk-lan966x.c
index 19bec94e1551..328ded6b2eae 100644
--- a/drivers/clk/clk-lan966x.c
+++ b/drivers/clk/clk-lan966x.c
@@ -48,6 +48,20 @@ static struct clk_init_data init = {
 	.num_parents = ARRAY_SIZE(lan966x_gck_pdata),
 };
 
+struct clk_gate_soc_desc {
+	const char *name;
+	int bit_idx;
+};
+
+static const struct clk_gate_soc_desc clk_gate_desc[] = {
+	{ "uhphs", 11 },
+	{ "udphs", 10 },
+	{ "mcramc", 9 },
+	{ "hmatrix", 8 },
+	{ }
+};
+
+static DEFINE_SPINLOCK(clk_gate_lock);
 static void __iomem *base;
 
 static int lan966x_gck_enable(struct clk_hw *hw)
@@ -188,11 +202,37 @@ static struct clk_hw *lan966x_gck_clk_register(struct device *dev, int i)
 	return &priv->hw;
 };
 
+static int lan966x_gate_clk_register(struct device *dev,
+				     struct clk_hw_onecell_data *hw_data,
+				     void __iomem *gate_base)
+{
+	int i;
+
+	for (i = GCK_GATE_UHPHS; i < N_CLOCKS; ++i) {
+		int idx = i - GCK_GATE_UHPHS;
+
+		hw_data->hws[i] =
+			devm_clk_hw_register_gate(dev, clk_gate_desc[idx].name,
+						  "lan966x", 0, base,
+						  clk_gate_desc[idx].bit_idx,
+						  0, &clk_gate_lock);
+
+		if (IS_ERR(hw_data->hws[i]))
+			return dev_err_probe(dev, PTR_ERR(hw_data->hws[i]),
+					     "failed to register %s clock\n",
+					     clk_gate_desc[idx].name);
+	}
+
+	return 0;
+}
+
 static int lan966x_clk_probe(struct platform_device *pdev)
 {
 	struct clk_hw_onecell_data *hw_data;
 	struct device *dev = &pdev->dev;
-	int i;
+	void __iomem *gate_base;
+	struct resource *res;
+	int i, ret;
 
 	hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, N_CLOCKS),
 			       GFP_KERNEL);
@@ -205,9 +245,9 @@ static int lan966x_clk_probe(struct platform_device *pdev)
 
 	init.ops = &lan966x_gck_ops;
 
-	hw_data->num = N_CLOCKS;
+	hw_data->num = GCK_GATE_UHPHS;
 
-	for (i = 0; i < N_CLOCKS; i++) {
+	for (i = 0; i < GCK_GATE_UHPHS; i++) {
 		init.name = clk_names[i];
 		hw_data->hws[i] = lan966x_gck_clk_register(dev, i);
 		if (IS_ERR(hw_data->hws[i])) {
@@ -217,6 +257,19 @@ static int lan966x_clk_probe(struct platform_device *pdev)
 		}
 	}
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	if (res) {
+		gate_base = devm_ioremap_resource(&pdev->dev, res);
+		if (IS_ERR(gate_base))
+			return PTR_ERR(gate_base);
+
+		hw_data->num = N_CLOCKS;
+
+		ret = lan966x_gate_clk_register(dev, hw_data, gate_base);
+		if (ret)
+			return ret;
+	}
+
 	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, hw_data);
 }
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH v3 2/4] dt-bindings: clock: lan966x: Extend for clock gate support
  2021-11-01  8:08 ` [RFC PATCH v3 2/4] dt-bindings: clock: lan966x: Extend for clock gate support Horatiu Vultur
@ 2021-11-02 17:47   ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2021-11-02 17:47 UTC (permalink / raw)
  To: Horatiu Vultur
  Cc: mturquette, sboyd, nicolas.ferre, kavyasree.kotagiri,
	eugen.hristev, linux-clk, devicetree, linux-kernel

On Mon, Nov 01, 2021 at 09:08:43AM +0100, Horatiu Vultur wrote:
> Allow to add an optional resource to be able to access the clock gate
> registers.
> 
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> ---
>  .../devicetree/bindings/clock/microchip,lan966x-gck.yaml       | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml b/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml
> index fca83bd68e26..a53c889629da 100644
> --- a/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml
> +++ b/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml
> @@ -19,7 +19,8 @@ properties:
>      const: microchip,lan966x-gck
>  
>    reg:
> -    maxItems: 1
> +    minItems: 1
> +    maxItems: 2

When there is more than 1 entry, you need to describe each entry:

minItems: 1
items:
  - description: ...
  - description: ...

>  
>    clocks:
>      items:
> -- 
> 2.33.0
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-02 17:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01  8:08 [RFC PATCH v3 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
2021-11-01  8:08 ` [RFC PATCH v3 1/4] clk: gate: Add devm_clk_hw_register_gate() Horatiu Vultur
2021-11-01  8:08 ` [RFC PATCH v3 2/4] dt-bindings: clock: lan966x: Extend for clock gate support Horatiu Vultur
2021-11-02 17:47   ` Rob Herring
2021-11-01  8:08 ` [RFC PATCH v3 3/4] dt-bindings: clock: lan966x: Extend includes with clock gates Horatiu Vultur
2021-11-01  8:08 ` [RFC PATCH v3 4/4] clk: lan966x: Extend lan966x clock driver for clock gating support Horatiu Vultur

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.