linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v4 0/4] Extend lan966x clock driver for clock gating support
@ 2021-11-03  8:50 Horatiu Vultur
  2021-11-03  8:50 ` [RFC PATCH v4 1/4] clk: gate: Add devm_clk_hw_register_gate() Horatiu Vultur
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Horatiu Vultur @ 2021-11-03  8:50 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, kavyasree.kotagiri, nicolas.ferre,
	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.

v3->v4:
 - fix reg property in the schema file

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 |  5 +-
 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, 125 insertions(+), 5 deletions(-)

-- 
2.33.0


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

* [RFC PATCH v4 1/4] clk: gate: Add devm_clk_hw_register_gate()
  2021-11-03  8:50 [RFC PATCH v4 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
@ 2021-11-03  8:50 ` Horatiu Vultur
  2021-11-03  8:51 ` [RFC PATCH v4 2/4] dt-bindings: clock: lan966x: Extend for clock gate support Horatiu Vultur
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Horatiu Vultur @ 2021-11-03  8:50 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, kavyasree.kotagiri, nicolas.ferre,
	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] 7+ messages in thread

* [RFC PATCH v4 2/4] dt-bindings: clock: lan966x: Extend for clock gate support
  2021-11-03  8:50 [RFC PATCH v4 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
  2021-11-03  8:50 ` [RFC PATCH v4 1/4] clk: gate: Add devm_clk_hw_register_gate() Horatiu Vultur
@ 2021-11-03  8:51 ` Horatiu Vultur
  2021-11-12 19:45   ` Rob Herring
  2021-11-03  8:51 ` [RFC PATCH v4 3/4] dt-bindings: clock: lan966x: Extend includes with clock gates Horatiu Vultur
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Horatiu Vultur @ 2021-11-03  8:51 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, kavyasree.kotagiri, nicolas.ferre,
	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     | 5 ++++-
 1 file changed, 4 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..df2bec188706 100644
--- a/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml
+++ b/Documentation/devicetree/bindings/clock/microchip,lan966x-gck.yaml
@@ -19,7 +19,10 @@ properties:
     const: microchip,lan966x-gck
 
   reg:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: Generic clock registers
+      - description: Optional gate clock registers
 
   clocks:
     items:
-- 
2.33.0


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

* [RFC PATCH v4 3/4] dt-bindings: clock: lan966x: Extend includes with clock gates
  2021-11-03  8:50 [RFC PATCH v4 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
  2021-11-03  8:50 ` [RFC PATCH v4 1/4] clk: gate: Add devm_clk_hw_register_gate() Horatiu Vultur
  2021-11-03  8:51 ` [RFC PATCH v4 2/4] dt-bindings: clock: lan966x: Extend for clock gate support Horatiu Vultur
@ 2021-11-03  8:51 ` Horatiu Vultur
  2021-11-03  8:51 ` [RFC PATCH v4 4/4] clk: lan966x: Extend lan966x clock driver for clock gating support Horatiu Vultur
  2021-12-08 10:14 ` [RFC PATCH v4 0/4] " Nicolas Ferre
  4 siblings, 0 replies; 7+ messages in thread
From: Horatiu Vultur @ 2021-11-03  8:51 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, kavyasree.kotagiri, nicolas.ferre,
	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] 7+ messages in thread

* [RFC PATCH v4 4/4] clk: lan966x: Extend lan966x clock driver for clock gating support
  2021-11-03  8:50 [RFC PATCH v4 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
                   ` (2 preceding siblings ...)
  2021-11-03  8:51 ` [RFC PATCH v4 3/4] dt-bindings: clock: lan966x: Extend includes with clock gates Horatiu Vultur
@ 2021-11-03  8:51 ` Horatiu Vultur
  2021-12-08 10:14 ` [RFC PATCH v4 0/4] " Nicolas Ferre
  4 siblings, 0 replies; 7+ messages in thread
From: Horatiu Vultur @ 2021-11-03  8:51 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, kavyasree.kotagiri, nicolas.ferre,
	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] 7+ messages in thread

* Re: [RFC PATCH v4 2/4] dt-bindings: clock: lan966x: Extend for clock gate support
  2021-11-03  8:51 ` [RFC PATCH v4 2/4] dt-bindings: clock: lan966x: Extend for clock gate support Horatiu Vultur
@ 2021-11-12 19:45   ` Rob Herring
  0 siblings, 0 replies; 7+ messages in thread
From: Rob Herring @ 2021-11-12 19:45 UTC (permalink / raw)
  To: Horatiu Vultur
  Cc: robh+dt, devicetree, sboyd, kavyasree.kotagiri, linux-clk,
	linux-kernel, mturquette, nicolas.ferre

On Wed, 03 Nov 2021 09:51:00 +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     | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [RFC PATCH v4 0/4] Extend lan966x clock driver for clock gating support
  2021-11-03  8:50 [RFC PATCH v4 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
                   ` (3 preceding siblings ...)
  2021-11-03  8:51 ` [RFC PATCH v4 4/4] clk: lan966x: Extend lan966x clock driver for clock gating support Horatiu Vultur
@ 2021-12-08 10:14 ` Nicolas Ferre
  4 siblings, 0 replies; 7+ messages in thread
From: Nicolas Ferre @ 2021-12-08 10:14 UTC (permalink / raw)
  To: Horatiu Vultur, mturquette, sboyd, robh+dt, kavyasree.kotagiri,
	linux-clk, devicetree, linux-kernel

On 03/11/2021 at 09:50, Horatiu Vultur wrote:
> 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.
> 
> v3->v4:
>   - fix reg property in the schema file
> 
> 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

For whole series:
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>

I'm queuing these patches on clk-at91 branch and plan to seed a 
pull-request to Stephen soon.

In the meantime it's sitting in the at91-next branch as well which is 
picked up by linux-next.

Best regards,
   Nicolas

>   .../bindings/clock/microchip,lan966x-gck.yaml |  5 +-
>   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, 125 insertions(+), 5 deletions(-)
> 


-- 
Nicolas Ferre

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

end of thread, other threads:[~2021-12-08 10:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-03  8:50 [RFC PATCH v4 0/4] Extend lan966x clock driver for clock gating support Horatiu Vultur
2021-11-03  8:50 ` [RFC PATCH v4 1/4] clk: gate: Add devm_clk_hw_register_gate() Horatiu Vultur
2021-11-03  8:51 ` [RFC PATCH v4 2/4] dt-bindings: clock: lan966x: Extend for clock gate support Horatiu Vultur
2021-11-12 19:45   ` Rob Herring
2021-11-03  8:51 ` [RFC PATCH v4 3/4] dt-bindings: clock: lan966x: Extend includes with clock gates Horatiu Vultur
2021-11-03  8:51 ` [RFC PATCH v4 4/4] clk: lan966x: Extend lan966x clock driver for clock gating support Horatiu Vultur
2021-12-08 10:14 ` [RFC PATCH v4 0/4] " Nicolas Ferre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).