devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
  • * [PATCH v2 06/18] MIPS: dts: qca: ar9132_tl_wr1043nd_v1.dts: use "ref" for reference clock name
           [not found] <1458185665-4521-1-git-send-email-antonynpavlov@gmail.com>
           [not found] ` <1458185665-4521-1-git-send-email-antonynpavlov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
    @ 2016-03-17  3:34 ` Antony Pavlov
      2016-03-17  3:34 ` [PATCH v2 07/18] MIPS: ath79: introduce <dt-bindings/clock/ath79-clk.h> Antony Pavlov
                       ` (2 subsequent siblings)
      4 siblings, 0 replies; 15+ messages in thread
    From: Antony Pavlov @ 2016-03-17  3:34 UTC (permalink / raw)
      To: linux-mips
      Cc: Alban Bedel, Michael Turquette, linux-clk, Ralf Baechle,
    	Rob Herring, devicetree
    
    Current ath79 clock.c code does not read reference clock and
    pll setup from devicetree. The ar724x_clocks_init() function
    recreates the clocks from scratch so devicetree clock
    information is dropped. After adding the code which picked up
    reference clock from devicetree I have found
    that kernel does not boot anymore. The SPI and UART drivers
    can't get clk; here are the bootlog error messages:
    
        of_serial: probe of 18020000.uart failed with error -22
        ath79-spi: probe of 1f000000.spi failed with error -22
    
    The problem is that clock code assumes that reference clock
    name is "ref" but current dts-file uses another name: "oscillator".
    
    This patch fixes the problem by changing external oscillator
    dt node name to "ref".
    
    Please note that there is an alternative solution for the problem:
    
        > --- a/arch/mips/boot/dts/qca/ar9132_tl_wr1043nd_v1.dts
        > +++ b/arch/mips/boot/dts/qca/ar9132_tl_wr1043nd_v1.dts
        > @@ -16,6 +16,7 @@
        >
        >         extosc: oscillator {
        >                 compatible = "fixed-clock";
        > +               clock-output-names = "ref";
        >                 #clock-cells = <0>;
        >                 clock-frequency = <40000000>;
        >         };
    
    Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
    Cc: Alban Bedel <albeu@free.fr>
    Cc: Michael Turquette <mturquette@baylibre.com>
    Cc: linux-clk@vger.kernel.org
    Cc: Ralf Baechle <ralf@linux-mips.org>
    Cc: linux-mips@linux-mips.org
    Cc: Rob Herring <robh+dt@kernel.org>
    Cc: devicetree@vger.kernel.org
    ---
     arch/mips/boot/dts/qca/ar9132_tl_wr1043nd_v1.dts | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/arch/mips/boot/dts/qca/ar9132_tl_wr1043nd_v1.dts b/arch/mips/boot/dts/qca/ar9132_tl_wr1043nd_v1.dts
    index eb632a2..3c3b7ce 100644
    --- a/arch/mips/boot/dts/qca/ar9132_tl_wr1043nd_v1.dts
    +++ b/arch/mips/boot/dts/qca/ar9132_tl_wr1043nd_v1.dts
    @@ -14,7 +14,7 @@
     		reg = <0x0 0x2000000>;
     	};
     
    -	extosc: oscillator {
    +	extosc: ref {
     		compatible = "fixed-clock";
     		#clock-cells = <0>;
     		clock-frequency = <40000000>;
    -- 
    2.7.0
    
    
    ^ permalink raw reply related	[flat|nested] 15+ messages in thread
  • * [PATCH v2 07/18] MIPS: ath79: introduce <dt-bindings/clock/ath79-clk.h>
           [not found] <1458185665-4521-1-git-send-email-antonynpavlov@gmail.com>
           [not found] ` <1458185665-4521-1-git-send-email-antonynpavlov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
      2016-03-17  3:34 ` [PATCH v2 06/18] MIPS: dts: qca: ar9132_tl_wr1043nd_v1.dts: use "ref" for reference clock name Antony Pavlov
    @ 2016-03-17  3:34 ` Antony Pavlov
      2016-03-17  3:34 ` [PATCH v2 08/18] MIPS: ath79: update devicetree clock support for AR9132 Antony Pavlov
      2016-03-17  3:34 ` [PATCH v2 11/18] MIPS: ath79: update devicetree clock support for AR9331 Antony Pavlov
      4 siblings, 0 replies; 15+ messages in thread
    From: Antony Pavlov @ 2016-03-17  3:34 UTC (permalink / raw)
      To: linux-mips
      Cc: Gabor Juhos, Alban Bedel, Michael Turquette, Stephen Boyd,
    	Rob Herring, linux-clk, devicetree
    
    The include/dt-bindings/clock/ath79-clk.h header file
    is introduced so we can use symbolic identifiers for SoC clocks.
    
    Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
    Cc: Gabor Juhos <juhosg@openwrt.org>
    Cc: Alban Bedel <albeu@free.fr>
    Cc: Michael Turquette <mturquette@baylibre.com>
    Cc: Stephen Boyd <sboyd@codeaurora.org>
    Cc: Rob Herring <robh+dt@kernel.org>
    Cc: linux-mips@linux-mips.org
    Cc: linux-clk@vger.kernel.org
    Cc: devicetree@vger.kernel.org
    ---
     arch/mips/ath79/clock.c               | 33 +++++++++++++++++----------------
     arch/mips/boot/dts/qca/ar9132.dtsi    |  8 +++++---
     include/dt-bindings/clock/ath79-clk.h | 19 +++++++++++++++++++
     3 files changed, 41 insertions(+), 19 deletions(-)
    
    diff --git a/arch/mips/ath79/clock.c b/arch/mips/ath79/clock.c
    index 618dfd7..c3a94ea 100644
    --- a/arch/mips/ath79/clock.c
    +++ b/arch/mips/ath79/clock.c
    @@ -18,6 +18,7 @@
     #include <linux/clk.h>
     #include <linux/clkdev.h>
     #include <linux/clk-provider.h>
    +#include <dt-bindings/clock/ath79-clk.h>
     
     #include <asm/div64.h>
     
    @@ -28,7 +29,7 @@
     #define AR71XX_BASE_FREQ	40000000
     #define AR724X_BASE_FREQ	40000000
     
    -static struct clk *clks[3];
    +static struct clk *clks[ATH79_CLK_END];
     static struct clk_onecell_data clk_data = {
     	.clks = clks,
     	.clk_num = ARRAY_SIZE(clks),
    @@ -78,9 +79,9 @@ static void __init ar71xx_clocks_init(void)
     	ahb_rate = cpu_rate / div;
     
     	ath79_add_sys_clkdev("ref", ref_rate);
    -	clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
    -	clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
    -	clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
    +	clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
    +	clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
    +	clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
     
     	clk_add_alias("wdt", NULL, "ahb", NULL);
     	clk_add_alias("uart", NULL, "ahb", NULL);
    @@ -114,9 +115,9 @@ static void __init ar724x_clocks_init(void)
     	ahb_rate = cpu_rate / div;
     
     	ath79_add_sys_clkdev("ref", ref_rate);
    -	clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
    -	clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
    -	clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
    +	clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
    +	clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
    +	clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
     
     	clk_add_alias("wdt", NULL, "ahb", NULL);
     	clk_add_alias("uart", NULL, "ahb", NULL);
    @@ -176,9 +177,9 @@ static void __init ar933x_clocks_init(void)
     	}
     
     	ath79_add_sys_clkdev("ref", ref_rate);
    -	clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
    -	clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
    -	clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
    +	clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
    +	clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
    +	clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
     
     	clk_add_alias("wdt", NULL, "ahb", NULL);
     	clk_add_alias("uart", NULL, "ref", NULL);
    @@ -310,9 +311,9 @@ static void __init ar934x_clocks_init(void)
     		ahb_rate = cpu_pll / (postdiv + 1);
     
     	ath79_add_sys_clkdev("ref", ref_rate);
    -	clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
    -	clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
    -	clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
    +	clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
    +	clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
    +	clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
     
     	clk_add_alias("wdt", NULL, "ref", NULL);
     	clk_add_alias("uart", NULL, "ref", NULL);
    @@ -397,9 +398,9 @@ static void __init qca955x_clocks_init(void)
     		ahb_rate = cpu_pll / (postdiv + 1);
     
     	ath79_add_sys_clkdev("ref", ref_rate);
    -	clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
    -	clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
    -	clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
    +	clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
    +	clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
    +	clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
     
     	clk_add_alias("wdt", NULL, "ref", NULL);
     	clk_add_alias("uart", NULL, "ref", NULL);
    diff --git a/arch/mips/boot/dts/qca/ar9132.dtsi b/arch/mips/boot/dts/qca/ar9132.dtsi
    index 3bff63b..2f9a3ee 100644
    --- a/arch/mips/boot/dts/qca/ar9132.dtsi
    +++ b/arch/mips/boot/dts/qca/ar9132.dtsi
    @@ -1,3 +1,5 @@
    +#include <dt-bindings/clock/ath79-clk.h>
    +
     / {
     	compatible = "qca,ar9132";
     
    @@ -57,7 +59,7 @@
     				reg = <0x18020000 0x20>;
     				interrupts = <3>;
     
    -				clocks = <&pll 2>;
    +				clocks = <&pll ATH79_CLK_AHB>;
     				clock-names = "uart";
     
     				reg-io-width = <4>;
    @@ -100,7 +102,7 @@
     
     				interrupts = <4>;
     
    -				clocks = <&pll 2>;
    +				clocks = <&pll ATH79_CLK_AHB>;
     				clock-names = "wdt";
     			};
     
    @@ -144,7 +146,7 @@
     			compatible = "qca,ar9132-spi", "qca,ar7100-spi";
     			reg = <0x1f000000 0x10>;
     
    -			clocks = <&pll 2>;
    +			clocks = <&pll ATH79_CLK_AHB>;
     			clock-names = "ahb";
     
     			status = "disabled";
    diff --git a/include/dt-bindings/clock/ath79-clk.h b/include/dt-bindings/clock/ath79-clk.h
    new file mode 100644
    index 0000000..27359ad
    --- /dev/null
    +++ b/include/dt-bindings/clock/ath79-clk.h
    @@ -0,0 +1,19 @@
    +/*
    + * Copyright (C) 2014, 2016 Antony Pavlov <antonynpavlov@gmail.com>
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License version 2 as
    + * published by the Free Software Foundation.
    + *
    + */
    +
    +#ifndef __DT_BINDINGS_ATH79_CLK_H
    +#define __DT_BINDINGS_ATH79_CLK_H
    +
    +#define ATH79_CLK_CPU		0
    +#define ATH79_CLK_DDR		1
    +#define ATH79_CLK_AHB		2
    +
    +#define ATH79_CLK_END		3
    +
    +#endif /* __DT_BINDINGS_ATH79_CLK_H */
    -- 
    2.7.0
    
    
    ^ permalink raw reply related	[flat|nested] 15+ messages in thread
  • * [PATCH v2 08/18] MIPS: ath79: update devicetree clock support for AR9132
           [not found] <1458185665-4521-1-git-send-email-antonynpavlov@gmail.com>
                       ` (2 preceding siblings ...)
      2016-03-17  3:34 ` [PATCH v2 07/18] MIPS: ath79: introduce <dt-bindings/clock/ath79-clk.h> Antony Pavlov
    @ 2016-03-17  3:34 ` Antony Pavlov
      2016-03-17  3:34 ` [PATCH v2 11/18] MIPS: ath79: update devicetree clock support for AR9331 Antony Pavlov
      4 siblings, 0 replies; 15+ messages in thread
    From: Antony Pavlov @ 2016-03-17  3:34 UTC (permalink / raw)
      To: linux-mips
      Cc: Gabor Juhos, Alban Bedel, Michael Turquette, Stephen Boyd,
    	Rob Herring, linux-clk, devicetree
    
    Current ath79 clock.c code does not read reference clock and
    pll setup from devicetree. E.g. you can set any clock rate value
    in board DTS but it will have no effect on the real clk calculation.
    
    This patch fixes some AR9132 devicetree clock support defects:
    
      * clk initialization function ath79_clocks_init_dt_ng()
        is introduced; it actually gets pll block base register
        address and reference clock from devicetree;
      * pll register parsing code is moved to the separate
        ar724x_clk_init() function; this function
        can be called from platform code or from devicetree code.
    
    Also mips_hpt_frequency value is set from dt, so the appropriate
    clock parameter is added to the cpu@0 devicetree node.
    
    The same approach can be used for adding AR9331 devicetree support.
    
    Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
    Cc: Gabor Juhos <juhosg@openwrt.org>
    Cc: Alban Bedel <albeu@free.fr>
    Cc: Michael Turquette <mturquette@baylibre.com>
    Cc: Stephen Boyd <sboyd@codeaurora.org>
    Cc: Rob Herring <robh+dt@kernel.org>
    Cc: linux-clk@vger.kernel.org
    Cc: linux-mips@linux-mips.org
    Cc: devicetree@vger.kernel.org
    ---
     arch/mips/ath79/clock.c            | 104 ++++++++++++++++++++++++++-----------
     arch/mips/ath79/setup.c            |  36 +++++++++++++
     arch/mips/boot/dts/qca/ar9132.dtsi |   1 +
     3 files changed, 112 insertions(+), 29 deletions(-)
    
    diff --git a/arch/mips/ath79/clock.c b/arch/mips/ath79/clock.c
    index c3a94ea..79fb8b4 100644
    --- a/arch/mips/ath79/clock.c
    +++ b/arch/mips/ath79/clock.c
    @@ -18,6 +18,8 @@
     #include <linux/clk.h>
     #include <linux/clkdev.h>
     #include <linux/clk-provider.h>
    +#include <linux/of.h>
    +#include <linux/of_address.h>
     #include <dt-bindings/clock/ath79-clk.h>
     
     #include <asm/div64.h>
    @@ -25,6 +27,7 @@
     #include <asm/mach-ath79/ath79.h>
     #include <asm/mach-ath79/ar71xx_regs.h>
     #include "common.h"
    +#include "machtypes.h"
     
     #define AR71XX_BASE_FREQ	40000000
     #define AR724X_BASE_FREQ	40000000
    @@ -87,37 +90,48 @@ static void __init ar71xx_clocks_init(void)
     	clk_add_alias("uart", NULL, "ahb", NULL);
     }
     
    +static struct clk * __init ath79_reg_ffclk(const char *name,
    +		const char *parent_name, unsigned int mult, unsigned int div)
    +{
    +	struct clk *clk;
    +
    +	clk = clk_register_fixed_factor(NULL, name, parent_name, 0, mult, div);
    +	if (!clk)
    +		panic("failed to allocate %s clock structure", name);
    +
    +	return clk;
    +}
    +
    +static void __init ar724x_clk_init(struct clk *ref_clk, void __iomem *pll_base)
    +{
    +	u32 pll;
    +	u32 mult, div, ddr_div, ahb_div;
    +
    +	pll = __raw_readl(pll_base + AR724X_PLL_REG_CPU_CONFIG);
    +
    +	mult = ((pll >> AR724X_PLL_FB_SHIFT) & AR724X_PLL_FB_MASK);
    +	div = ((pll >> AR724X_PLL_REF_DIV_SHIFT) & AR724X_PLL_REF_DIV_MASK) * 2;
    +
    +	ddr_div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
    +	ahb_div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
    +
    +	clks[ATH79_CLK_CPU] = ath79_reg_ffclk("cpu", "ref", mult, div);
    +	clks[ATH79_CLK_DDR] = ath79_reg_ffclk("ddr", "ref", mult, div * ddr_div);
    +	clks[ATH79_CLK_AHB] = ath79_reg_ffclk("ahb", "ref", mult, div * ahb_div);
    +}
    +
     static void __init ar724x_clocks_init(void)
     {
    -	unsigned long ref_rate;
    -	unsigned long cpu_rate;
    -	unsigned long ddr_rate;
    -	unsigned long ahb_rate;
    -	u32 pll;
    -	u32 freq;
    -	u32 div;
    +	struct clk *ref_clk;
     
    -	ref_rate = AR724X_BASE_FREQ;
    -	pll = ath79_pll_rr(AR724X_PLL_REG_CPU_CONFIG);
    +	ref_clk = ath79_add_sys_clkdev("ref", AR724X_BASE_FREQ);
     
    -	div = ((pll >> AR724X_PLL_FB_SHIFT) & AR724X_PLL_FB_MASK);
    -	freq = div * ref_rate;
    +	ar724x_clk_init(ref_clk, ath79_pll_base);
     
    -	div = ((pll >> AR724X_PLL_REF_DIV_SHIFT) & AR724X_PLL_REF_DIV_MASK) * 2;
    -	freq /= div;
    -
    -	cpu_rate = freq;
    -
    -	div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
    -	ddr_rate = freq / div;
    -
    -	div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
    -	ahb_rate = cpu_rate / div;
    -
    -	ath79_add_sys_clkdev("ref", ref_rate);
    -	clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
    -	clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
    -	clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
    +	/* just make happy plat_time_init() from arch/mips/ath79/setup.c */
    +	clk_register_clkdev(clks[ATH79_CLK_CPU], "cpu", NULL);
    +	clk_register_clkdev(clks[ATH79_CLK_DDR], "ddr", NULL);
    +	clk_register_clkdev(clks[ATH79_CLK_AHB], "ahb", NULL);
     
     	clk_add_alias("wdt", NULL, "ahb", NULL);
     	clk_add_alias("uart", NULL, "ahb", NULL);
    @@ -420,8 +434,6 @@ void __init ath79_clocks_init(void)
     		qca955x_clocks_init();
     	else
     		BUG();
    -
    -	of_clk_init(NULL);
     }
     
     unsigned long __init
    @@ -448,8 +460,42 @@ static void __init ath79_clocks_init_dt(struct device_node *np)
     
     CLK_OF_DECLARE(ar7100, "qca,ar7100-pll", ath79_clocks_init_dt);
     CLK_OF_DECLARE(ar7240, "qca,ar7240-pll", ath79_clocks_init_dt);
    -CLK_OF_DECLARE(ar9130, "qca,ar9130-pll", ath79_clocks_init_dt);
     CLK_OF_DECLARE(ar9330, "qca,ar9330-pll", ath79_clocks_init_dt);
     CLK_OF_DECLARE(ar9340, "qca,ar9340-pll", ath79_clocks_init_dt);
     CLK_OF_DECLARE(ar9550, "qca,qca9550-pll", ath79_clocks_init_dt);
    +
    +static void __init ath79_clocks_init_dt_ng(struct device_node *np)
    +{
    +	struct clk *ref_clk;
    +	void __iomem *pll_base;
    +	const char *dnfn = of_node_full_name(np);
    +
    +	ref_clk = of_clk_get(np, 0);
    +	if (IS_ERR(ref_clk)) {
    +		pr_err("%s: of_clk_get failed\n", dnfn);
    +		goto err;
    +	}
    +
    +	pll_base = of_iomap(np, 0);
    +	if (!pll_base) {
    +		pr_err("%s: can't map pll registers\n", dnfn);
    +		goto err_clk;
    +	}
    +
    +	ar724x_clk_init(ref_clk, pll_base);
    +
    +	if (of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data)) {
    +		pr_err("%s: could not register clk provider\n", dnfn);
    +		goto err_clk;
    +	}
    +
    +	return;
    +
    +err_clk:
    +	clk_put(ref_clk);
    +
    +err:
    +	return;
    +}
    +CLK_OF_DECLARE(ar9130_clk, "qca,ar9130-pll", ath79_clocks_init_dt_ng);
     #endif
    diff --git a/arch/mips/ath79/setup.c b/arch/mips/ath79/setup.c
    index 99ab4bb..61e3a59 100644
    --- a/arch/mips/ath79/setup.c
    +++ b/arch/mips/ath79/setup.c
    @@ -17,6 +17,7 @@
     #include <linux/bootmem.h>
     #include <linux/err.h>
     #include <linux/clk.h>
    +#include <linux/clk-provider.h>
     #include <linux/of_platform.h>
     #include <linux/of_fdt.h>
     
    @@ -221,6 +222,36 @@ void __init plat_mem_setup(void)
     	pm_power_off = ath79_halt;
     }
     
    +static void __init ath79_of_plat_time_init(void)
    +{
    +	struct device_node *np;
    +	struct clk *clk;
    +	unsigned long cpu_clk_rate;
    +
    +	of_clk_init(NULL);
    +
    +	np = of_get_cpu_node(0, NULL);
    +	if (!np) {
    +		pr_err("Failed to get CPU node\n");
    +		return;
    +	}
    +
    +	clk = of_clk_get(np, 0);
    +	if (IS_ERR(clk)) {
    +		pr_err("Failed to get CPU clock: %ld\n", PTR_ERR(clk));
    +		return;
    +	}
    +
    +	cpu_clk_rate = clk_get_rate(clk);
    +
    +	pr_info("CPU clock: %lu.%03lu MHz\n",
    +		cpu_clk_rate / 1000000, (cpu_clk_rate / 1000) % 1000);
    +
    +	mips_hpt_frequency = cpu_clk_rate / 2;
    +
    +	clk_put(clk);
    +}
    +
     void __init plat_time_init(void)
     {
     	unsigned long cpu_clk_rate;
    @@ -228,6 +259,11 @@ void __init plat_time_init(void)
     	unsigned long ddr_clk_rate;
     	unsigned long ref_clk_rate;
     
    +	if (IS_ENABLED(CONFIG_OF) && mips_machtype == ATH79_MACH_GENERIC_OF) {
    +		ath79_of_plat_time_init();
    +		return;
    +	}
    +
     	ath79_clocks_init();
     
     	cpu_clk_rate = ath79_get_sys_clk_rate("cpu");
    diff --git a/arch/mips/boot/dts/qca/ar9132.dtsi b/arch/mips/boot/dts/qca/ar9132.dtsi
    index 2f9a3ee..302f0a8 100644
    --- a/arch/mips/boot/dts/qca/ar9132.dtsi
    +++ b/arch/mips/boot/dts/qca/ar9132.dtsi
    @@ -13,6 +13,7 @@
     		cpu@0 {
     			device_type = "cpu";
     			compatible = "mips,mips24Kc";
    +			clocks = <&pll ATH79_CLK_CPU>;
     			reg = <0>;
     		};
     	};
    -- 
    2.7.0
    
    
    ^ permalink raw reply related	[flat|nested] 15+ messages in thread
  • * [PATCH v2 11/18] MIPS: ath79: update devicetree clock support for AR9331
           [not found] <1458185665-4521-1-git-send-email-antonynpavlov@gmail.com>
                       ` (3 preceding siblings ...)
      2016-03-17  3:34 ` [PATCH v2 08/18] MIPS: ath79: update devicetree clock support for AR9132 Antony Pavlov
    @ 2016-03-17  3:34 ` Antony Pavlov
      4 siblings, 0 replies; 15+ messages in thread
    From: Antony Pavlov @ 2016-03-17  3:34 UTC (permalink / raw)
      To: linux-mips
      Cc: Gabor Juhos, Alban Bedel, Michael Turquette, Stephen Boyd,
    	Rob Herring, linux-clk, devicetree
    
    Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
    Cc: Gabor Juhos <juhosg@openwrt.org>
    Cc: Alban Bedel <albeu@free.fr>
    Cc: Michael Turquette <mturquette@baylibre.com>
    Cc: Stephen Boyd <sboyd@codeaurora.org>
    Cc: Rob Herring <robh+dt@kernel.org>
    Cc: linux-clk@vger.kernel.org
    Cc: linux-mips@linux-mips.org
    Cc: devicetree@vger.kernel.org
    ---
     arch/mips/ath79/clock.c | 120 +++++++++++++++++++++++++++++-------------------
     1 file changed, 74 insertions(+), 46 deletions(-)
    
    diff --git a/arch/mips/ath79/clock.c b/arch/mips/ath79/clock.c
    index 79fb8b4..3cfc5ec 100644
    --- a/arch/mips/ath79/clock.c
    +++ b/arch/mips/ath79/clock.c
    @@ -137,15 +137,68 @@ static void __init ar724x_clocks_init(void)
     	clk_add_alias("uart", NULL, "ahb", NULL);
     }
     
    +static void __init ar9330_clk_init(struct clk *ref_clk, void __iomem *pll_base)
    +{
    +	u32 clock_ctrl;
    +	u32 ref_div;
    +	u32 ninit_mul;
    +	u32 out_div;
    +
    +	u32 cpu_div;
    +	u32 ddr_div;
    +	u32 ahb_div;
    +
    +	clock_ctrl = __raw_readl(pll_base + AR933X_PLL_CLOCK_CTRL_REG);
    +	if (clock_ctrl & AR933X_PLL_CLOCK_CTRL_BYPASS) {
    +		ref_div = 1;
    +		ninit_mul = 1;
    +		out_div = 1;
    +
    +		cpu_div = 1;
    +		ddr_div = 1;
    +		ahb_div = 1;
    +	} else {
    +		u32 cpu_config;
    +		u32 t;
    +
    +		cpu_config = __raw_readl(pll_base + AR933X_PLL_CPU_CONFIG_REG);
    +
    +		t = (cpu_config >> AR933X_PLL_CPU_CONFIG_REFDIV_SHIFT) &
    +		    AR933X_PLL_CPU_CONFIG_REFDIV_MASK;
    +		ref_div = t;
    +
    +		ninit_mul = (cpu_config >> AR933X_PLL_CPU_CONFIG_NINT_SHIFT) &
    +		    AR933X_PLL_CPU_CONFIG_NINT_MASK;
    +
    +		t = (cpu_config >> AR933X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
    +		    AR933X_PLL_CPU_CONFIG_OUTDIV_MASK;
    +		if (t == 0)
    +			t = 1;
    +
    +		out_div = (1 << t);
    +
    +		cpu_div = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_CPU_DIV_SHIFT) &
    +		     AR933X_PLL_CLOCK_CTRL_CPU_DIV_MASK) + 1;
    +
    +		ddr_div = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_DDR_DIV_SHIFT) &
    +		      AR933X_PLL_CLOCK_CTRL_DDR_DIV_MASK) + 1;
    +
    +		ahb_div = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_AHB_DIV_SHIFT) &
    +		     AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK) + 1;
    +	}
    +
    +	clks[ATH79_CLK_CPU] = ath79_reg_ffclk("cpu", "ref",
    +					ninit_mul, ref_div * out_div * cpu_div);
    +	clks[ATH79_CLK_DDR] = ath79_reg_ffclk("ddr", "ref",
    +					ninit_mul, ref_div * out_div * ddr_div);
    +	clks[ATH79_CLK_AHB] = ath79_reg_ffclk("ahb", "ref",
    +					ninit_mul, ref_div * out_div * ahb_div);
    +}
    +
     static void __init ar933x_clocks_init(void)
     {
    +	struct clk *ref_clk;
     	unsigned long ref_rate;
    -	unsigned long cpu_rate;
    -	unsigned long ddr_rate;
    -	unsigned long ahb_rate;
    -	u32 clock_ctrl;
    -	u32 cpu_config;
    -	u32 freq;
     	u32 t;
     
     	t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
    @@ -154,46 +207,14 @@ static void __init ar933x_clocks_init(void)
     	else
     		ref_rate = (25 * 1000 * 1000);
     
    -	clock_ctrl = ath79_pll_rr(AR933X_PLL_CLOCK_CTRL_REG);
    -	if (clock_ctrl & AR933X_PLL_CLOCK_CTRL_BYPASS) {
    -		cpu_rate = ref_rate;
    -		ahb_rate = ref_rate;
    -		ddr_rate = ref_rate;
    -	} else {
    -		cpu_config = ath79_pll_rr(AR933X_PLL_CPU_CONFIG_REG);
    +	ref_clk = ath79_add_sys_clkdev("ref", ref_rate);
     
    -		t = (cpu_config >> AR933X_PLL_CPU_CONFIG_REFDIV_SHIFT) &
    -		    AR933X_PLL_CPU_CONFIG_REFDIV_MASK;
    -		freq = ref_rate / t;
    +	ar9330_clk_init(ref_clk, ath79_pll_base);
     
    -		t = (cpu_config >> AR933X_PLL_CPU_CONFIG_NINT_SHIFT) &
    -		    AR933X_PLL_CPU_CONFIG_NINT_MASK;
    -		freq *= t;
    -
    -		t = (cpu_config >> AR933X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
    -		    AR933X_PLL_CPU_CONFIG_OUTDIV_MASK;
    -		if (t == 0)
    -			t = 1;
    -
    -		freq >>= t;
    -
    -		t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_CPU_DIV_SHIFT) &
    -		     AR933X_PLL_CLOCK_CTRL_CPU_DIV_MASK) + 1;
    -		cpu_rate = freq / t;
    -
    -		t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_DDR_DIV_SHIFT) &
    -		      AR933X_PLL_CLOCK_CTRL_DDR_DIV_MASK) + 1;
    -		ddr_rate = freq / t;
    -
    -		t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_AHB_DIV_SHIFT) &
    -		     AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK) + 1;
    -		ahb_rate = freq / t;
    -	}
    -
    -	ath79_add_sys_clkdev("ref", ref_rate);
    -	clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
    -	clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
    -	clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
    +	/* just make happy plat_time_init() from arch/mips/ath79/setup.c */
    +	clk_register_clkdev(clks[ATH79_CLK_CPU], "cpu", NULL);
    +	clk_register_clkdev(clks[ATH79_CLK_DDR], "ddr", NULL);
    +	clk_register_clkdev(clks[ATH79_CLK_AHB], "ahb", NULL);
     
     	clk_add_alias("wdt", NULL, "ahb", NULL);
     	clk_add_alias("uart", NULL, "ref", NULL);
    @@ -460,7 +481,6 @@ static void __init ath79_clocks_init_dt(struct device_node *np)
     
     CLK_OF_DECLARE(ar7100, "qca,ar7100-pll", ath79_clocks_init_dt);
     CLK_OF_DECLARE(ar7240, "qca,ar7240-pll", ath79_clocks_init_dt);
    -CLK_OF_DECLARE(ar9330, "qca,ar9330-pll", ath79_clocks_init_dt);
     CLK_OF_DECLARE(ar9340, "qca,ar9340-pll", ath79_clocks_init_dt);
     CLK_OF_DECLARE(ar9550, "qca,qca9550-pll", ath79_clocks_init_dt);
     
    @@ -482,7 +502,14 @@ static void __init ath79_clocks_init_dt_ng(struct device_node *np)
     		goto err_clk;
     	}
     
    -	ar724x_clk_init(ref_clk, pll_base);
    +	if (of_device_is_compatible(np, "qca,ar9130-pll"))
    +		ar724x_clk_init(ref_clk, pll_base);
    +	else if (of_device_is_compatible(np, "qca,ar9330-pll"))
    +		ar9330_clk_init(ref_clk, pll_base);
    +	else {
    +		pr_err("%s: could not find any appropriate clk_init()\n", dnfn);
    +		goto err_clk;
    +	}
     
     	if (of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data)) {
     		pr_err("%s: could not register clk provider\n", dnfn);
    @@ -498,4 +525,5 @@ err:
     	return;
     }
     CLK_OF_DECLARE(ar9130_clk, "qca,ar9130-pll", ath79_clocks_init_dt_ng);
    +CLK_OF_DECLARE(ar9330_clk, "qca,ar9330-pll", ath79_clocks_init_dt_ng);
     #endif
    -- 
    2.7.0
    
    
    ^ permalink raw reply related	[flat|nested] 15+ messages in thread

  • end of thread, other threads:[~2016-03-17  3:34 UTC | newest]
    
    Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
    -- links below jump to the message on this page --
         [not found] <1458185665-4521-1-git-send-email-antonynpavlov@gmail.com>
         [not found] ` <1458185665-4521-1-git-send-email-antonynpavlov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
    2016-03-17  3:34   ` [PATCH v2 01/18] dt-bindings: clock: qca,ath79-pll: fix copy-paste typos Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 04/18] MIPS: dts: qca: ar9132_tl_wr1043nd_v1.dts: drop unused alias node Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 05/18] MIPS: dts: qca: ar9132: use short references for dt nodes Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 10/18] MIPS: dts: qca: introduce AR9331 devicetree Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 12/18] MIPS: ath79: add initial support for TP-LINK MR3020 Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 13/18] devicetree: add Dragino vendor id Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 14/18] MIPS: ath79: add initial support for Dragino MS14 (Dragino 2) Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 15/18] devicetree: add Onion Corporation vendor id Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 16/18] MIPS: ath79: add initial support for Onion Omega Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 17/18] devicetree: add DPTechnics vendor id Antony Pavlov
    2016-03-17  3:34   ` [PATCH v2 18/18] MIPS: ath79: add initial support for DPT-Module Antony Pavlov
    2016-03-17  3:34 ` [PATCH v2 06/18] MIPS: dts: qca: ar9132_tl_wr1043nd_v1.dts: use "ref" for reference clock name Antony Pavlov
    2016-03-17  3:34 ` [PATCH v2 07/18] MIPS: ath79: introduce <dt-bindings/clock/ath79-clk.h> Antony Pavlov
    2016-03-17  3:34 ` [PATCH v2 08/18] MIPS: ath79: update devicetree clock support for AR9132 Antony Pavlov
    2016-03-17  3:34 ` [PATCH v2 11/18] MIPS: ath79: update devicetree clock support for AR9331 Antony Pavlov
    

    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).