All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
To: linux-clk@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Subject: [PATCH] CLK: ARC: Set initial pll output frequency specified in device tree
Date: Fri, 29 Sep 2017 16:13:57 +0300	[thread overview]
Message-ID: <20170929131357.26796-1-Eugeniy.Paltsev@synopsys.com> (raw)

Add option to set initial output frequency of plls via
"clock-frequency" property in pll's device tree node.
This frequency will be set while pll driver probed.

The usage example is setting CPU clock frequency on boot
See discussion:
https://www.mail-archive.com/linux-snps-arc@lists.infradead.org/msg02689.html

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
---
 .../bindings/clock/snps,hsdk-pll-clock.txt         |  5 ++++
 .../devicetree/bindings/clock/snps,pll-clock.txt   |  5 ++++
 drivers/clk/axs10x/pll_clock.c                     | 34 ++++++++++++++++++++--
 drivers/clk/clk-hsdk-pll.c                         | 34 ++++++++++++++++++++--
 4 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/clock/snps,hsdk-pll-clock.txt b/Documentation/devicetree/bindings/clock/snps,hsdk-pll-clock.txt
index c56c755..5703059 100644
--- a/Documentation/devicetree/bindings/clock/snps,hsdk-pll-clock.txt
+++ b/Documentation/devicetree/bindings/clock/snps,hsdk-pll-clock.txt
@@ -13,6 +13,10 @@ Required properties:
 - clocks: shall be the input parent clock phandle for the PLL.
 - #clock-cells: from common clock binding; Should always be set to 0.
 
+Optional properties:
+- clock-frequency: output frequency generated by pll in Hz which will be set
+while probing. Should be a single cell.
+
 Example:
 	input_clk: input-clk {
 		clock-frequency = <33333333>;
@@ -25,4 +29,5 @@ Example:
 		reg = <0x00 0x10>;
 		#clock-cells = <0>;
 		clocks = <&input_clk>;
+		clock-frequency = <1000000000>;
 	};
diff --git a/Documentation/devicetree/bindings/clock/snps,pll-clock.txt b/Documentation/devicetree/bindings/clock/snps,pll-clock.txt
index 11fe487..5908f99 100644
--- a/Documentation/devicetree/bindings/clock/snps,pll-clock.txt
+++ b/Documentation/devicetree/bindings/clock/snps,pll-clock.txt
@@ -13,6 +13,10 @@ registers and second for corresponding LOCK CGU register.
 - clocks: shall be the input parent clock phandle for the PLL.
 - #clock-cells: from common clock binding; Should always be set to 0.
 
+Optional properties:
+- clock-frequency: output frequency generated by pll in Hz which will be set
+while probing. Should be a single cell.
+
 Example:
 	input-clk: input-clk {
 		clock-frequency = <33333333>;
@@ -25,4 +29,5 @@ Example:
 		reg = <0x80 0x10>, <0x100 0x10>;
 		#clock-cells = <0>;
 		clocks = <&input-clk>;
+		clock-frequency = <100000000>;
 	};
diff --git a/drivers/clk/axs10x/pll_clock.c b/drivers/clk/axs10x/pll_clock.c
index 25d8c24..3f4345d 100644
--- a/drivers/clk/axs10x/pll_clock.c
+++ b/drivers/clk/axs10x/pll_clock.c
@@ -11,6 +11,7 @@
 #include <linux/platform_device.h>
 #include <linux/module.h>
 #include <linux/clk-provider.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/device.h>
@@ -215,6 +216,25 @@ static const struct clk_ops axs10x_pll_ops = {
 	.set_rate = axs10x_pll_set_rate,
 };
 
+static void set_pll_rate_from_of(struct clk *clk, struct device_node *node)
+{
+	u32 requested_rate;
+
+	/* If we specify initial pll output frequency try to set it */
+	if (of_property_read_u32(node, "clock-frequency", &requested_rate))
+		return;
+
+	if (clk_prepare_enable(clk)) {
+		pr_err("Cannot enable %s clock.\n", node->name);
+		return;
+	}
+
+	if (clk_set_rate(clk, requested_rate))
+		pr_err("Cannot set %s clock rate.\n", node->name);
+
+	pr_debug("Set %s clock to %u\n", node->name, requested_rate);
+}
+
 static int axs10x_pll_clk_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -258,8 +278,15 @@ static int axs10x_pll_clk_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
-			&pll_clk->hw);
+	ret =  of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
+				      &pll_clk->hw);
+	if (ret)
+		return ret;
+
+	/* If we specify initial pll output frequency in dts try to set it */
+	set_pll_rate_from_of(pll_clk->hw.clk, dev->of_node);
+
+	return 0;
 }
 
 static int axs10x_pll_clk_remove(struct platform_device *pdev)
@@ -311,6 +338,9 @@ static void __init of_axs10x_pll_clk_setup(struct device_node *node)
 		goto err_unregister_clk;
 	}
 
+	/* If we specify initial pll output frequency in dts try to set it */
+	set_pll_rate_from_of(pll_clk->hw.clk, node);
+
 	return;
 
 err_unregister_clk:
diff --git a/drivers/clk/clk-hsdk-pll.c b/drivers/clk/clk-hsdk-pll.c
index bbf23717..74fd006 100644
--- a/drivers/clk/clk-hsdk-pll.c
+++ b/drivers/clk/clk-hsdk-pll.c
@@ -9,6 +9,7 @@
  */
 
 #include <linux/clk-provider.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/err.h>
@@ -295,6 +296,25 @@ static const struct clk_ops hsdk_pll_ops = {
 	.set_rate = hsdk_pll_set_rate,
 };
 
+static void set_pll_rate_from_of(struct clk *clk, struct device_node *node)
+{
+	u32 requested_rate;
+
+	/* If we specify initial pll output frequency try to set it */
+	if (of_property_read_u32(node, "clock-frequency", &requested_rate))
+		return;
+
+	if (clk_prepare_enable(clk)) {
+		pr_err("Cannot enable %s clock.\n", node->name);
+		return;
+	}
+
+	if (clk_set_rate(clk, requested_rate))
+		pr_err("Cannot set %s clock rate.\n", node->name);
+
+	pr_debug("Set %s clock to %u\n", node->name, requested_rate);
+}
+
 static int hsdk_pll_clk_probe(struct platform_device *pdev)
 {
 	int ret;
@@ -340,8 +360,15 @@ static int hsdk_pll_clk_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
-			&pll_clk->hw);
+	ret =  of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
+				      &pll_clk->hw);
+	if (ret)
+		return ret;
+
+	/* If we specify initial pll output frequency in dts try to set it */
+	set_pll_rate_from_of(pll_clk->hw.clk, dev->of_node);
+
+	return 0;
 }
 
 static int hsdk_pll_clk_remove(struct platform_device *pdev)
@@ -400,6 +427,9 @@ static void __init of_hsdk_pll_clk_setup(struct device_node *node)
 		goto err_unmap_spec_regs;
 	}
 
+	/* If we specify initial pll output frequency in dts try to set it */
+	set_pll_rate_from_of(pll_clk->hw.clk, node);
+
 	return;
 
 err_unmap_spec_regs:
-- 
2.9.3

WARNING: multiple messages have this Message-ID (diff)
From: Eugeniy.Paltsev@synopsys.com (Eugeniy Paltsev)
To: linux-snps-arc@lists.infradead.org
Subject: [PATCH] CLK: ARC: Set initial pll output frequency specified in device tree
Date: Fri, 29 Sep 2017 16:13:57 +0300	[thread overview]
Message-ID: <20170929131357.26796-1-Eugeniy.Paltsev@synopsys.com> (raw)

Add option to set initial output frequency of plls via
"clock-frequency" property in pll's device tree node.
This frequency will be set while pll driver probed.

The usage example is setting CPU clock frequency on boot
See discussion:
https://www.mail-archive.com/linux-snps-arc at lists.infradead.org/msg02689.html

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev at synopsys.com>
---
 .../bindings/clock/snps,hsdk-pll-clock.txt         |  5 ++++
 .../devicetree/bindings/clock/snps,pll-clock.txt   |  5 ++++
 drivers/clk/axs10x/pll_clock.c                     | 34 ++++++++++++++++++++--
 drivers/clk/clk-hsdk-pll.c                         | 34 ++++++++++++++++++++--
 4 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/clock/snps,hsdk-pll-clock.txt b/Documentation/devicetree/bindings/clock/snps,hsdk-pll-clock.txt
index c56c755..5703059 100644
--- a/Documentation/devicetree/bindings/clock/snps,hsdk-pll-clock.txt
+++ b/Documentation/devicetree/bindings/clock/snps,hsdk-pll-clock.txt
@@ -13,6 +13,10 @@ Required properties:
 - clocks: shall be the input parent clock phandle for the PLL.
 - #clock-cells: from common clock binding; Should always be set to 0.
 
+Optional properties:
+- clock-frequency: output frequency generated by pll in Hz which will be set
+while probing. Should be a single cell.
+
 Example:
 	input_clk: input-clk {
 		clock-frequency = <33333333>;
@@ -25,4 +29,5 @@ Example:
 		reg = <0x00 0x10>;
 		#clock-cells = <0>;
 		clocks = <&input_clk>;
+		clock-frequency = <1000000000>;
 	};
diff --git a/Documentation/devicetree/bindings/clock/snps,pll-clock.txt b/Documentation/devicetree/bindings/clock/snps,pll-clock.txt
index 11fe487..5908f99 100644
--- a/Documentation/devicetree/bindings/clock/snps,pll-clock.txt
+++ b/Documentation/devicetree/bindings/clock/snps,pll-clock.txt
@@ -13,6 +13,10 @@ registers and second for corresponding LOCK CGU register.
 - clocks: shall be the input parent clock phandle for the PLL.
 - #clock-cells: from common clock binding; Should always be set to 0.
 
+Optional properties:
+- clock-frequency: output frequency generated by pll in Hz which will be set
+while probing. Should be a single cell.
+
 Example:
 	input-clk: input-clk {
 		clock-frequency = <33333333>;
@@ -25,4 +29,5 @@ Example:
 		reg = <0x80 0x10>, <0x100 0x10>;
 		#clock-cells = <0>;
 		clocks = <&input-clk>;
+		clock-frequency = <100000000>;
 	};
diff --git a/drivers/clk/axs10x/pll_clock.c b/drivers/clk/axs10x/pll_clock.c
index 25d8c24..3f4345d 100644
--- a/drivers/clk/axs10x/pll_clock.c
+++ b/drivers/clk/axs10x/pll_clock.c
@@ -11,6 +11,7 @@
 #include <linux/platform_device.h>
 #include <linux/module.h>
 #include <linux/clk-provider.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/device.h>
@@ -215,6 +216,25 @@ static const struct clk_ops axs10x_pll_ops = {
 	.set_rate = axs10x_pll_set_rate,
 };
 
+static void set_pll_rate_from_of(struct clk *clk, struct device_node *node)
+{
+	u32 requested_rate;
+
+	/* If we specify initial pll output frequency try to set it */
+	if (of_property_read_u32(node, "clock-frequency", &requested_rate))
+		return;
+
+	if (clk_prepare_enable(clk)) {
+		pr_err("Cannot enable %s clock.\n", node->name);
+		return;
+	}
+
+	if (clk_set_rate(clk, requested_rate))
+		pr_err("Cannot set %s clock rate.\n", node->name);
+
+	pr_debug("Set %s clock to %u\n", node->name, requested_rate);
+}
+
 static int axs10x_pll_clk_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -258,8 +278,15 @@ static int axs10x_pll_clk_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
-			&pll_clk->hw);
+	ret =  of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
+				      &pll_clk->hw);
+	if (ret)
+		return ret;
+
+	/* If we specify initial pll output frequency in dts try to set it */
+	set_pll_rate_from_of(pll_clk->hw.clk, dev->of_node);
+
+	return 0;
 }
 
 static int axs10x_pll_clk_remove(struct platform_device *pdev)
@@ -311,6 +338,9 @@ static void __init of_axs10x_pll_clk_setup(struct device_node *node)
 		goto err_unregister_clk;
 	}
 
+	/* If we specify initial pll output frequency in dts try to set it */
+	set_pll_rate_from_of(pll_clk->hw.clk, node);
+
 	return;
 
 err_unregister_clk:
diff --git a/drivers/clk/clk-hsdk-pll.c b/drivers/clk/clk-hsdk-pll.c
index bbf23717..74fd006 100644
--- a/drivers/clk/clk-hsdk-pll.c
+++ b/drivers/clk/clk-hsdk-pll.c
@@ -9,6 +9,7 @@
  */
 
 #include <linux/clk-provider.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/err.h>
@@ -295,6 +296,25 @@ static const struct clk_ops hsdk_pll_ops = {
 	.set_rate = hsdk_pll_set_rate,
 };
 
+static void set_pll_rate_from_of(struct clk *clk, struct device_node *node)
+{
+	u32 requested_rate;
+
+	/* If we specify initial pll output frequency try to set it */
+	if (of_property_read_u32(node, "clock-frequency", &requested_rate))
+		return;
+
+	if (clk_prepare_enable(clk)) {
+		pr_err("Cannot enable %s clock.\n", node->name);
+		return;
+	}
+
+	if (clk_set_rate(clk, requested_rate))
+		pr_err("Cannot set %s clock rate.\n", node->name);
+
+	pr_debug("Set %s clock to %u\n", node->name, requested_rate);
+}
+
 static int hsdk_pll_clk_probe(struct platform_device *pdev)
 {
 	int ret;
@@ -340,8 +360,15 @@ static int hsdk_pll_clk_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
-			&pll_clk->hw);
+	ret =  of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
+				      &pll_clk->hw);
+	if (ret)
+		return ret;
+
+	/* If we specify initial pll output frequency in dts try to set it */
+	set_pll_rate_from_of(pll_clk->hw.clk, dev->of_node);
+
+	return 0;
 }
 
 static int hsdk_pll_clk_remove(struct platform_device *pdev)
@@ -400,6 +427,9 @@ static void __init of_hsdk_pll_clk_setup(struct device_node *node)
 		goto err_unmap_spec_regs;
 	}
 
+	/* If we specify initial pll output frequency in dts try to set it */
+	set_pll_rate_from_of(pll_clk->hw.clk, node);
+
 	return;
 
 err_unmap_spec_regs:
-- 
2.9.3

             reply	other threads:[~2017-09-29 13:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-29 13:13 Eugeniy Paltsev [this message]
2017-09-29 13:13 ` [PATCH] CLK: ARC: Set initial pll output frequency specified in device tree Eugeniy Paltsev
2017-10-26 18:25 ` Vineet Gupta
2017-10-26 18:25   ` Vineet Gupta
2017-11-13 15:35 ` Eugeniy Paltsev
2017-11-13 15:35   ` Eugeniy Paltsev
2017-11-13 15:35   ` Eugeniy Paltsev
2017-11-13 22:29   ` sboyd
2017-11-13 22:29     ` sboyd
2017-11-13 22:29     ` sboyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170929131357.26796-1-Eugeniy.Paltsev@synopsys.com \
    --to=eugeniy.paltsev@synopsys.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-snps-arc@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=mturquette@baylibre.com \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.