aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/clock/tango4-clock.txt23
-rw-r--r--drivers/clk/Makefile1
-rw-r--r--drivers/clk/clk-tango4.c61
3 files changed, 85 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/clock/tango4-clock.txt b/Documentation/devicetree/bindings/clock/tango4-clock.txt
new file mode 100644
index 000000000000..19c580a7bda2
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/tango4-clock.txt
@@ -0,0 +1,23 @@
1* Sigma Designs Tango4 Clock Generator
2
3The Tango4 clock generator outputs cpu_clk and sys_clk (the latter is used
4for RAM and various peripheral devices). The clock binding described here
5is applicable to all Tango4 SoCs.
6
7Required 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
15Example:
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 };
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 820714c72d36..f4165bb9a270 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_COMMON_CLK_SI514) += clk-si514.o
42obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o 42obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o
43obj-$(CONFIG_COMMON_CLK_CDCE925) += clk-cdce925.o 43obj-$(CONFIG_COMMON_CLK_CDCE925) += clk-cdce925.o
44obj-$(CONFIG_ARCH_STM32) += clk-stm32f4.o 44obj-$(CONFIG_ARCH_STM32) += clk-stm32f4.o
45obj-$(CONFIG_ARCH_TANGOX) += clk-tango4.o
45obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o 46obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o
46obj-$(CONFIG_ARCH_U300) += clk-u300.o 47obj-$(CONFIG_ARCH_U300) += clk-u300.o
47obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o 48obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o
diff --git a/drivers/clk/clk-tango4.c b/drivers/clk/clk-tango4.c
new file mode 100644
index 000000000000..004ab7dfcfe3
--- /dev/null
+++ b/drivers/clk/clk-tango4.c
@@ -0,0 +1,61 @@
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
7static struct clk *out[2];
8static 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
19static 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
31static 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
39static 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}
61CLK_OF_DECLARE(tango4_clkgen, "sigma,tango4-clkgen", tango4_clkgen_setup);