Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: mvebu: add helper file for Armada AP and CP clocks

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>

authored by

Gregory CLEMENT and committed by
Stephen Boyd
33c02590 096f4597

+61 -42
+5
drivers/clk/mvebu/Kconfig
··· 8 8 config MVEBU_CLK_COREDIV 9 9 bool 10 10 11 + config ARMADA_AP_CP_HELPER 12 + bool 13 + 11 14 config ARMADA_370_CLK 12 15 bool 13 16 select MVEBU_CLK_COMMON ··· 38 35 39 36 config ARMADA_AP806_SYSCON 40 37 bool 38 + select ARMADA_AP_CP_HELPER 41 39 42 40 config ARMADA_CP110_SYSCON 43 41 bool 42 + select ARMADA_AP_CP_HELPER 44 43 45 44 config DOVE_CLK 46 45 bool
+1
drivers/clk/mvebu/Makefile
··· 2 2 obj-$(CONFIG_MVEBU_CLK_COMMON) += common.o 3 3 obj-$(CONFIG_MVEBU_CLK_CPU) += clk-cpu.o 4 4 obj-$(CONFIG_MVEBU_CLK_COREDIV) += clk-corediv.o 5 + obj-$(CONFIG_ARMADA_AP_CP_HELPER) += armada_ap_cp_helper.o 5 6 6 7 obj-$(CONFIG_ARMADA_370_CLK) += armada-370.o 7 8 obj-$(CONFIG_ARMADA_375_CLK) += armada-375.o
+6 -18
drivers/clk/mvebu/ap806-system-controller.c
··· 10 10 11 11 #define pr_fmt(fmt) "ap806-system-controller: " fmt 12 12 13 + #include "armada_ap_cp_helper.h" 13 14 #include <linux/clk-provider.h> 14 15 #include <linux/mfd/syscon.h> 15 16 #include <linux/init.h> 16 17 #include <linux/of.h> 17 - #include <linux/of_address.h> 18 18 #include <linux/platform_device.h> 19 19 #include <linux/regmap.h> 20 20 ··· 29 29 .clks = ap806_clks, 30 30 .clk_num = AP806_CLK_NUM, 31 31 }; 32 - 33 - static char *ap806_unique_name(struct device *dev, struct device_node *np, 34 - char *name) 35 - { 36 - const __be32 *reg; 37 - u64 addr; 38 - 39 - reg = of_get_property(np, "reg", NULL); 40 - addr = of_translate_address(np, reg); 41 - return devm_kasprintf(dev, GFP_KERNEL, "%llx-%s", 42 - (unsigned long long)addr, name); 43 - } 44 32 45 33 static int ap806_syscon_common_probe(struct platform_device *pdev, 46 34 struct device_node *syscon_node) ··· 97 109 cpuclk_freq *= 1000 * 1000; 98 110 99 111 /* CPU clocks depend on the Sample At Reset configuration */ 100 - name = ap806_unique_name(dev, syscon_node, "cpu-cluster-0"); 112 + name = ap_cp_unique_name(dev, syscon_node, "cpu-cluster-0"); 101 113 ap806_clks[0] = clk_register_fixed_rate(dev, name, NULL, 102 114 0, cpuclk_freq); 103 115 if (IS_ERR(ap806_clks[0])) { ··· 105 117 goto fail0; 106 118 } 107 119 108 - name = ap806_unique_name(dev, syscon_node, "cpu-cluster-1"); 120 + name = ap_cp_unique_name(dev, syscon_node, "cpu-cluster-1"); 109 121 ap806_clks[1] = clk_register_fixed_rate(dev, name, NULL, 0, 110 122 cpuclk_freq); 111 123 if (IS_ERR(ap806_clks[1])) { ··· 114 126 } 115 127 116 128 /* Fixed clock is always 1200 Mhz */ 117 - fixedclk_name = ap806_unique_name(dev, syscon_node, "fixed"); 129 + fixedclk_name = ap_cp_unique_name(dev, syscon_node, "fixed"); 118 130 ap806_clks[2] = clk_register_fixed_rate(dev, fixedclk_name, NULL, 119 131 0, 1200 * 1000 * 1000); 120 132 if (IS_ERR(ap806_clks[2])) { ··· 123 135 } 124 136 125 137 /* MSS Clock is fixed clock divided by 6 */ 126 - name = ap806_unique_name(dev, syscon_node, "mss"); 138 + name = ap_cp_unique_name(dev, syscon_node, "mss"); 127 139 ap806_clks[3] = clk_register_fixed_factor(NULL, name, fixedclk_name, 128 140 0, 1, 6); 129 141 if (IS_ERR(ap806_clks[3])) { ··· 132 144 } 133 145 134 146 /* SDIO(/eMMC) Clock is fixed clock divided by 3 */ 135 - name = ap806_unique_name(dev, syscon_node, "sdio"); 147 + name = ap_cp_unique_name(dev, syscon_node, "sdio"); 136 148 ap806_clks[4] = clk_register_fixed_factor(NULL, name, 137 149 fixedclk_name, 138 150 0, 1, 3);
+30
drivers/clk/mvebu/armada_ap_cp_helper.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Marvell Armada AP and CP110 helper 4 + * 5 + * Copyright (C) 2018 Marvell 6 + * 7 + * Gregory Clement <gregory.clement@bootlin.com> 8 + * 9 + */ 10 + 11 + #include "armada_ap_cp_helper.h" 12 + #include <linux/device.h> 13 + #include <linux/of.h> 14 + #include <linux/of_address.h> 15 + 16 + char *ap_cp_unique_name(struct device *dev, struct device_node *np, 17 + const char *name) 18 + { 19 + const __be32 *reg; 20 + u64 addr; 21 + 22 + /* Do not create a name if there is no clock */ 23 + if (!name) 24 + return NULL; 25 + 26 + reg = of_get_property(np, "reg", NULL); 27 + addr = of_translate_address(np, reg); 28 + return devm_kasprintf(dev, GFP_KERNEL, "%llx-%s", 29 + (unsigned long long)addr, name); 30 + }
+11
drivers/clk/mvebu/armada_ap_cp_helper.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + 3 + #ifndef __ARMADA_AP_CP_HELPER_H 4 + #define __ARMADA_AP_CP_HELPER_H 5 + 6 + struct device; 7 + struct device_node; 8 + 9 + char *ap_cp_unique_name(struct device *dev, struct device_node *np, 10 + const char *name); 11 + #endif
+8 -24
drivers/clk/mvebu/cp110-system-controller.c
··· 26 26 27 27 #define pr_fmt(fmt) "cp110-system-controller: " fmt 28 28 29 + #include "armada_ap_cp_helper.h" 29 30 #include <linux/clk-provider.h> 30 31 #include <linux/mfd/syscon.h> 31 32 #include <linux/init.h> 32 33 #include <linux/of.h> 33 - #include <linux/of_address.h> 34 34 #include <linux/platform_device.h> 35 35 #include <linux/regmap.h> 36 36 #include <linux/slab.h> ··· 212 212 return ERR_PTR(-EINVAL); 213 213 } 214 214 215 - static char *cp110_unique_name(struct device *dev, struct device_node *np, 216 - const char *name) 217 - { 218 - const __be32 *reg; 219 - u64 addr; 220 - 221 - /* Do not create a name if there is no clock */ 222 - if (!name) 223 - return NULL; 224 - 225 - reg = of_get_property(np, "reg", NULL); 226 - addr = of_translate_address(np, reg); 227 - return devm_kasprintf(dev, GFP_KERNEL, "%llx-%s", 228 - (unsigned long long)addr, name); 229 - } 230 - 231 215 static int cp110_syscon_common_probe(struct platform_device *pdev, 232 216 struct device_node *syscon_node) 233 217 { ··· 245 261 cp110_clk_data->num = CP110_CLK_NUM; 246 262 247 263 /* Register the PLL0 which is the root of the hw tree */ 248 - pll0_name = cp110_unique_name(dev, syscon_node, "pll0"); 264 + pll0_name = ap_cp_unique_name(dev, syscon_node, "pll0"); 249 265 hw = clk_hw_register_fixed_rate(NULL, pll0_name, NULL, 0, 250 266 1000 * 1000 * 1000); 251 267 if (IS_ERR(hw)) { ··· 256 272 cp110_clks[CP110_CORE_PLL0] = hw; 257 273 258 274 /* PPv2 is PLL0/3 */ 259 - ppv2_name = cp110_unique_name(dev, syscon_node, "ppv2-core"); 275 + ppv2_name = ap_cp_unique_name(dev, syscon_node, "ppv2-core"); 260 276 hw = clk_hw_register_fixed_factor(NULL, ppv2_name, pll0_name, 0, 1, 3); 261 277 if (IS_ERR(hw)) { 262 278 ret = PTR_ERR(hw); ··· 266 282 cp110_clks[CP110_CORE_PPV2] = hw; 267 283 268 284 /* X2CORE clock is PLL0/2 */ 269 - x2core_name = cp110_unique_name(dev, syscon_node, "x2core"); 285 + x2core_name = ap_cp_unique_name(dev, syscon_node, "x2core"); 270 286 hw = clk_hw_register_fixed_factor(NULL, x2core_name, pll0_name, 271 287 0, 1, 2); 272 288 if (IS_ERR(hw)) { ··· 277 293 cp110_clks[CP110_CORE_X2CORE] = hw; 278 294 279 295 /* Core clock is X2CORE/2 */ 280 - core_name = cp110_unique_name(dev, syscon_node, "core"); 296 + core_name = ap_cp_unique_name(dev, syscon_node, "core"); 281 297 hw = clk_hw_register_fixed_factor(NULL, core_name, x2core_name, 282 298 0, 1, 2); 283 299 if (IS_ERR(hw)) { ··· 287 303 288 304 cp110_clks[CP110_CORE_CORE] = hw; 289 305 /* NAND can be either PLL0/2.5 or core clock */ 290 - nand_name = cp110_unique_name(dev, syscon_node, "nand-core"); 306 + nand_name = ap_cp_unique_name(dev, syscon_node, "nand-core"); 291 307 if (nand_clk_ctrl & NF_CLOCK_SEL_400_MASK) 292 308 hw = clk_hw_register_fixed_factor(NULL, nand_name, 293 309 pll0_name, 0, 2, 5); ··· 302 318 cp110_clks[CP110_CORE_NAND] = hw; 303 319 304 320 /* SDIO clock is PLL0/2.5 */ 305 - sdio_name = cp110_unique_name(dev, syscon_node, "sdio-core"); 321 + sdio_name = ap_cp_unique_name(dev, syscon_node, "sdio-core"); 306 322 hw = clk_hw_register_fixed_factor(NULL, sdio_name, 307 323 pll0_name, 0, 2, 5); 308 324 if (IS_ERR(hw)) { ··· 314 330 315 331 /* create the unique name for all the gate clocks */ 316 332 for (i = 0; i < ARRAY_SIZE(gate_base_names); i++) 317 - gate_name[i] = cp110_unique_name(dev, syscon_node, 333 + gate_name[i] = ap_cp_unique_name(dev, syscon_node, 318 334 gate_base_names[i]); 319 335 320 336 for (i = 0; i < ARRAY_SIZE(gate_base_names); i++) {