Re: [PATCH] CLK: ARC: Set initial pll output frequency specified in device tree

From: Eugeniy Paltsev
Date: Mon Nov 13 2017 - 10:35:40 EST


Hi Stephen, Michael,

Please treat this message as a polite reminder to review my patch.
It would be really nice to see this patch in 4.15.

Thanks.

On Fri, 2017-09-29 at 16:13 +0300, Eugeniy Paltsev wrote:
> 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@xxxxxxxxxxxxxxxxxxx/msg02689.html
>
> Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@xxxxxxxxxxxx>
> ---
> Â.../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:
--
ÂEugeniy Paltsev