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

clk: tango4: clkgen driver for Tango4 platforms

Provide support for Sigma Designs Tango4 clock generator.
NOTE: This driver is incompatible with Tango3 clkgen.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
[sboyd@codeaurora.org: Add kernel.h include for panic/sprintf]
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Marc Gonzalez and committed by
Stephen Boyd
ed12dfc9 a085f877

+85
+23
Documentation/devicetree/bindings/clock/tango4-clock.txt
··· 1 + * Sigma Designs Tango4 Clock Generator 2 + 3 + The Tango4 clock generator outputs cpu_clk and sys_clk (the latter is used 4 + for RAM and various peripheral devices). The clock binding described here 5 + is applicable to all Tango4 SoCs. 6 + 7 + Required Properties: 8 + 9 + - compatible: should be "sigma,tango4-clkgen". 10 + - reg: physical base address of the device and length of memory mapped region. 11 + - clocks: phandle of the input clock (crystal oscillator). 12 + - clock-output-names: should be "cpuclk" and "sysclk". 13 + - #clock-cells: should be set to 1. 14 + 15 + Example: 16 + 17 + clkgen: clkgen@10000 { 18 + compatible = "sigma,tango4-clkgen"; 19 + reg = <0x10000 0x40>; 20 + clocks = <&xtal>; 21 + clock-output-names = "cpuclk", "sysclk"; 22 + #clock-cells = <1>; 23 + };
+1
drivers/clk/Makefile
··· 42 42 obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o 43 43 obj-$(CONFIG_COMMON_CLK_CDCE925) += clk-cdce925.o 44 44 obj-$(CONFIG_ARCH_STM32) += clk-stm32f4.o 45 + obj-$(CONFIG_ARCH_TANGOX) += clk-tango4.o 45 46 obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o 46 47 obj-$(CONFIG_ARCH_U300) += clk-u300.o 47 48 obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o
+61
drivers/clk/clk-tango4.c
··· 1 + #include <linux/kernel.h> 2 + #include <linux/clk-provider.h> 3 + #include <linux/of_address.h> 4 + #include <linux/init.h> 5 + #include <linux/io.h> 6 + 7 + static struct clk *out[2]; 8 + static struct clk_onecell_data clk_data = { out, 2 }; 9 + 10 + #define SYSCLK_CTRL 0x20 11 + #define CPUCLK_CTRL 0x24 12 + #define LEGACY_DIV 0x3c 13 + 14 + #define PLL_N(val) (((val) >> 0) & 0x7f) 15 + #define PLL_K(val) (((val) >> 13) & 0x7) 16 + #define PLL_M(val) (((val) >> 16) & 0x7) 17 + #define DIV_INDEX(val) (((val) >> 8) & 0xf) 18 + 19 + static void __init make_pll(int idx, const char *parent, void __iomem *base) 20 + { 21 + char name[8]; 22 + u32 val, mul, div; 23 + 24 + sprintf(name, "pll%d", idx); 25 + val = readl_relaxed(base + idx*8); 26 + mul = PLL_N(val) + 1; 27 + div = (PLL_M(val) + 1) << PLL_K(val); 28 + clk_register_fixed_factor(NULL, name, parent, 0, mul, div); 29 + } 30 + 31 + static int __init get_div(void __iomem *base) 32 + { 33 + u8 sysclk_tab[16] = { 2, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4 }; 34 + int idx = DIV_INDEX(readl_relaxed(base + LEGACY_DIV)); 35 + 36 + return sysclk_tab[idx]; 37 + } 38 + 39 + static void __init tango4_clkgen_setup(struct device_node *np) 40 + { 41 + int div, ret; 42 + void __iomem *base = of_iomap(np, 0); 43 + const char *parent = of_clk_get_parent_name(np, 0); 44 + 45 + if (!base) 46 + panic("%s: invalid address\n", np->full_name); 47 + 48 + make_pll(0, parent, base); 49 + make_pll(1, parent, base); 50 + 51 + out[0] = clk_register_divider(NULL, "cpuclk", "pll0", 0, 52 + base + CPUCLK_CTRL, 8, 8, CLK_DIVIDER_ONE_BASED, NULL); 53 + 54 + div = readl_relaxed(base + SYSCLK_CTRL) & BIT(23) ? get_div(base) : 4; 55 + out[1] = clk_register_fixed_factor(NULL, "sysclk", "pll1", 0, 1, div); 56 + 57 + ret = of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data); 58 + if (IS_ERR(out[0]) || IS_ERR(out[1]) || ret < 0) 59 + panic("%s: clk registration failed\n", np->full_name); 60 + } 61 + CLK_OF_DECLARE(tango4_clkgen, "sigma,tango4-clkgen", tango4_clkgen_setup);