clk: mvebu: add helper file for Armada AP and CP clocks
authorGregory CLEMENT <gregory.clement@bootlin.com>
Wed, 10 Jul 2019 13:43:42 +0000 (15:43 +0200)
committerStephen Boyd <sboyd@kernel.org>
Thu, 8 Aug 2019 16:08:09 +0000 (09:08 -0700)
Clock drivers for Armada AP and Armada CP use the same function to
generate unique clock name. A third drivers is coming with the same
need, so it's time to move this function in a common file.

Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com>
Link: https://lkml.kernel.org/r/20190710134346.30239-3-gregory.clement@bootlin.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/mvebu/Kconfig
drivers/clk/mvebu/Makefile
drivers/clk/mvebu/ap806-system-controller.c
drivers/clk/mvebu/armada_ap_cp_helper.c [new file with mode: 0644]
drivers/clk/mvebu/armada_ap_cp_helper.h [new file with mode: 0644]
drivers/clk/mvebu/cp110-system-controller.c

index b09f6ded0a30d31f70b6c48395c8bbf354de9df8..19f1b51ed15e676b7c0a38afe783cad83ea46756 100644 (file)
@@ -8,6 +8,9 @@ config MVEBU_CLK_CPU
 config MVEBU_CLK_COREDIV
        bool
 
+config ARMADA_AP_CP_HELPER
+       bool
+
 config ARMADA_370_CLK
        bool
        select MVEBU_CLK_COMMON
@@ -35,9 +38,11 @@ config ARMADA_XP_CLK
 
 config ARMADA_AP806_SYSCON
        bool
+       select ARMADA_AP_CP_HELPER
 
 config ARMADA_CP110_SYSCON
        bool
+       select ARMADA_AP_CP_HELPER
 
 config DOVE_CLK
        bool
index 93ac3685271f92d5cf9e976a48c38c85563bc49f..6638ad962ec188ab027a4e1d49c5aeb1bf7cdd40 100644 (file)
@@ -2,6 +2,7 @@
 obj-$(CONFIG_MVEBU_CLK_COMMON) += common.o
 obj-$(CONFIG_MVEBU_CLK_CPU)    += clk-cpu.o
 obj-$(CONFIG_MVEBU_CLK_COREDIV)        += clk-corediv.o
+obj-$(CONFIG_ARMADA_AP_CP_HELPER) += armada_ap_cp_helper.o
 
 obj-$(CONFIG_ARMADA_370_CLK)   += armada-370.o
 obj-$(CONFIG_ARMADA_375_CLK)   += armada-375.o
index ea54a874bbdadd0a58843a637ef0885a1f65a02d..0a58824ff053087bddeb4a181b55f1811eb63e01 100644 (file)
 
 #define pr_fmt(fmt) "ap806-system-controller: " fmt
 
+#include "armada_ap_cp_helper.h"
 #include <linux/clk-provider.h>
 #include <linux/mfd/syscon.h>
 #include <linux/init.h>
 #include <linux/of.h>
-#include <linux/of_address.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 
@@ -30,18 +30,6 @@ static struct clk_onecell_data ap806_clk_data = {
        .clk_num = AP806_CLK_NUM,
 };
 
-static char *ap806_unique_name(struct device *dev, struct device_node *np,
-                              char *name)
-{
-       const __be32 *reg;
-       u64 addr;
-
-       reg = of_get_property(np, "reg", NULL);
-       addr = of_translate_address(np, reg);
-       return devm_kasprintf(dev, GFP_KERNEL, "%llx-%s",
-                       (unsigned long long)addr, name);
-}
-
 static int ap806_syscon_common_probe(struct platform_device *pdev,
                                     struct device_node *syscon_node)
 {
@@ -109,7 +97,7 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
        cpuclk_freq *= 1000 * 1000;
 
        /* CPU clocks depend on the Sample At Reset configuration */
-       name = ap806_unique_name(dev, syscon_node, "cpu-cluster-0");
+       name = ap_cp_unique_name(dev, syscon_node, "cpu-cluster-0");
        ap806_clks[0] = clk_register_fixed_rate(dev, name, NULL,
                                                0, cpuclk_freq);
        if (IS_ERR(ap806_clks[0])) {
@@ -117,7 +105,7 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
                goto fail0;
        }
 
-       name = ap806_unique_name(dev, syscon_node, "cpu-cluster-1");
+       name = ap_cp_unique_name(dev, syscon_node, "cpu-cluster-1");
        ap806_clks[1] = clk_register_fixed_rate(dev, name, NULL, 0,
                                                cpuclk_freq);
        if (IS_ERR(ap806_clks[1])) {
@@ -126,7 +114,7 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
        }
 
        /* Fixed clock is always 1200 Mhz */
-       fixedclk_name = ap806_unique_name(dev, syscon_node, "fixed");
+       fixedclk_name = ap_cp_unique_name(dev, syscon_node, "fixed");
        ap806_clks[2] = clk_register_fixed_rate(dev, fixedclk_name, NULL,
                                                0, 1200 * 1000 * 1000);
        if (IS_ERR(ap806_clks[2])) {
@@ -135,7 +123,7 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
        }
 
        /* MSS Clock is fixed clock divided by 6 */
-       name = ap806_unique_name(dev, syscon_node, "mss");
+       name = ap_cp_unique_name(dev, syscon_node, "mss");
        ap806_clks[3] = clk_register_fixed_factor(NULL, name, fixedclk_name,
                                                  0, 1, 6);
        if (IS_ERR(ap806_clks[3])) {
@@ -144,7 +132,7 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
        }
 
        /* SDIO(/eMMC) Clock is fixed clock divided by 3 */
-       name = ap806_unique_name(dev, syscon_node, "sdio");
+       name = ap_cp_unique_name(dev, syscon_node, "sdio");
        ap806_clks[4] = clk_register_fixed_factor(NULL, name,
                                                  fixedclk_name,
                                                  0, 1, 3);
diff --git a/drivers/clk/mvebu/armada_ap_cp_helper.c b/drivers/clk/mvebu/armada_ap_cp_helper.c
new file mode 100644 (file)
index 0000000..6a930f6
--- /dev/null
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Marvell Armada AP and CP110 helper
+ *
+ * Copyright (C) 2018 Marvell
+ *
+ * Gregory Clement <gregory.clement@bootlin.com>
+ *
+ */
+
+#include "armada_ap_cp_helper.h"
+#include <linux/device.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+
+char *ap_cp_unique_name(struct device *dev, struct device_node *np,
+                       const char *name)
+{
+       const __be32 *reg;
+       u64 addr;
+
+       /* Do not create a name if there is no clock */
+       if (!name)
+               return NULL;
+
+       reg = of_get_property(np, "reg", NULL);
+       addr = of_translate_address(np, reg);
+       return devm_kasprintf(dev, GFP_KERNEL, "%llx-%s",
+                             (unsigned long long)addr, name);
+}
diff --git a/drivers/clk/mvebu/armada_ap_cp_helper.h b/drivers/clk/mvebu/armada_ap_cp_helper.h
new file mode 100644 (file)
index 0000000..810af1e
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef __ARMADA_AP_CP_HELPER_H
+#define __ARMADA_AP_CP_HELPER_H
+
+struct device;
+struct device_node;
+
+char *ap_cp_unique_name(struct device *dev, struct device_node *np,
+                       const char *name);
+#endif
index b6de283f45e3739744b293785062cb4670a2f479..808463276145b009305d3390e0ce1a366a922fb5 100644 (file)
 
 #define pr_fmt(fmt) "cp110-system-controller: " fmt
 
+#include "armada_ap_cp_helper.h"
 #include <linux/clk-provider.h>
 #include <linux/mfd/syscon.h>
 #include <linux/init.h>
 #include <linux/of.h>
-#include <linux/of_address.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
@@ -212,22 +212,6 @@ static struct clk_hw *cp110_of_clk_get(struct of_phandle_args *clkspec,
        return ERR_PTR(-EINVAL);
 }
 
-static char *cp110_unique_name(struct device *dev, struct device_node *np,
-                              const char *name)
-{
-       const __be32 *reg;
-       u64 addr;
-
-       /* Do not create a name if there is no clock */
-       if (!name)
-               return NULL;
-
-       reg = of_get_property(np, "reg", NULL);
-       addr = of_translate_address(np, reg);
-       return devm_kasprintf(dev, GFP_KERNEL, "%llx-%s",
-                             (unsigned long long)addr, name);
-}
-
 static int cp110_syscon_common_probe(struct platform_device *pdev,
                                     struct device_node *syscon_node)
 {
@@ -261,7 +245,7 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
        cp110_clk_data->num = CP110_CLK_NUM;
 
        /* Register the PLL0 which is the root of the hw tree */
-       pll0_name = cp110_unique_name(dev, syscon_node, "pll0");
+       pll0_name = ap_cp_unique_name(dev, syscon_node, "pll0");
        hw = clk_hw_register_fixed_rate(NULL, pll0_name, NULL, 0,
                                        1000 * 1000 * 1000);
        if (IS_ERR(hw)) {
@@ -272,7 +256,7 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
        cp110_clks[CP110_CORE_PLL0] = hw;
 
        /* PPv2 is PLL0/3 */
-       ppv2_name = cp110_unique_name(dev, syscon_node, "ppv2-core");
+       ppv2_name = ap_cp_unique_name(dev, syscon_node, "ppv2-core");
        hw = clk_hw_register_fixed_factor(NULL, ppv2_name, pll0_name, 0, 1, 3);
        if (IS_ERR(hw)) {
                ret = PTR_ERR(hw);
@@ -282,7 +266,7 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
        cp110_clks[CP110_CORE_PPV2] = hw;
 
        /* X2CORE clock is PLL0/2 */
-       x2core_name = cp110_unique_name(dev, syscon_node, "x2core");
+       x2core_name = ap_cp_unique_name(dev, syscon_node, "x2core");
        hw = clk_hw_register_fixed_factor(NULL, x2core_name, pll0_name,
                                          0, 1, 2);
        if (IS_ERR(hw)) {
@@ -293,7 +277,7 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
        cp110_clks[CP110_CORE_X2CORE] = hw;
 
        /* Core clock is X2CORE/2 */
-       core_name = cp110_unique_name(dev, syscon_node, "core");
+       core_name = ap_cp_unique_name(dev, syscon_node, "core");
        hw = clk_hw_register_fixed_factor(NULL, core_name, x2core_name,
                                          0, 1, 2);
        if (IS_ERR(hw)) {
@@ -303,7 +287,7 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
 
        cp110_clks[CP110_CORE_CORE] = hw;
        /* NAND can be either PLL0/2.5 or core clock */
-       nand_name = cp110_unique_name(dev, syscon_node, "nand-core");
+       nand_name = ap_cp_unique_name(dev, syscon_node, "nand-core");
        if (nand_clk_ctrl & NF_CLOCK_SEL_400_MASK)
                hw = clk_hw_register_fixed_factor(NULL, nand_name,
                                                   pll0_name, 0, 2, 5);
@@ -318,7 +302,7 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
        cp110_clks[CP110_CORE_NAND] = hw;
 
        /* SDIO clock is PLL0/2.5 */
-       sdio_name = cp110_unique_name(dev, syscon_node, "sdio-core");
+       sdio_name = ap_cp_unique_name(dev, syscon_node, "sdio-core");
        hw = clk_hw_register_fixed_factor(NULL, sdio_name,
                                          pll0_name, 0, 2, 5);
        if (IS_ERR(hw)) {
@@ -330,7 +314,7 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
 
        /* create the unique name for all the gate clocks */
        for (i = 0; i < ARRAY_SIZE(gate_base_names); i++)
-               gate_name[i] =  cp110_unique_name(dev, syscon_node,
+               gate_name[i] =  ap_cp_unique_name(dev, syscon_node,
                                                  gate_base_names[i]);
 
        for (i = 0; i < ARRAY_SIZE(gate_base_names); i++) {