Skip to content

Commit fefe053

Browse files
Marc Gonzalezbebarino
authored andcommitted
clk: tango4: improve clkgen driver
Add support for USB and SDIO clocks. Report unsupported setups and panic. Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
1 parent cb0ceaf commit fefe053

1 file changed

Lines changed: 48 additions & 25 deletions

File tree

‎drivers/clk/clk-tango4.c‎

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,81 @@
44
#include <linux/init.h>
55
#include <linux/io.h>
66

7-
static struct clk *out[2];
8-
static struct clk_onecell_data clk_data = { out, 2 };
7+
#define CLK_COUNT 4 /* cpu_clk, sys_clk, usb_clk, sdio_clk */
8+
static struct clk *clks[CLK_COUNT];
9+
static struct clk_onecell_data clk_data = { clks, CLK_COUNT };
910

10-
#define SYSCLK_CTRL 0x20
11-
#define CPUCLK_CTRL 0x24
12-
#define LEGACY_DIV 0x3c
11+
#define SYSCLK_DIV 0x20
12+
#define CPUCLK_DIV 0x24
13+
#define DIV_BYPASS BIT(23)
1314

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)
15+
/*** CLKGEN_PLL ***/
16+
#define extract_pll_n(val) ((val >> 0) & ((1u << 7) - 1))
17+
#define extract_pll_k(val) ((val >> 13) & ((1u << 3) - 1))
18+
#define extract_pll_m(val) ((val >> 16) & ((1u << 3) - 1))
19+
#define extract_pll_isel(val) ((val >> 24) & ((1u << 3) - 1))
1820

1921
static void __init make_pll(int idx, const char *parent, void __iomem *base)
2022
{
2123
char name[8];
2224
u32 val, mul, div;
2325

2426
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);
27+
val = readl(base + idx * 8);
28+
mul = extract_pll_n(val) + 1;
29+
div = (extract_pll_m(val) + 1) << extract_pll_k(val);
2830
clk_register_fixed_factor(NULL, name, parent, 0, mul, div);
31+
if (extract_pll_isel(val) != 1)
32+
panic("%s: input not set to XTAL_IN\n", name);
2933
}
3034

31-
static int __init get_div(void __iomem *base)
35+
static void __init make_cd(int idx, void __iomem *base)
3236
{
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));
37+
char name[8];
38+
u32 val, mul, div;
3539

36-
return sysclk_tab[idx];
40+
sprintf(name, "cd%d", idx);
41+
val = readl(base + idx * 8);
42+
mul = 1 << 27;
43+
div = (2 << 27) + val;
44+
clk_register_fixed_factor(NULL, name, "pll2", 0, mul, div);
45+
if (val > 0xf0000000)
46+
panic("%s: unsupported divider %x\n", name, val);
3747
}
3848

3949
static void __init tango4_clkgen_setup(struct device_node *np)
4050
{
41-
int div, ret;
51+
struct clk **pp = clk_data.clks;
4252
void __iomem *base = of_iomap(np, 0);
4353
const char *parent = of_clk_get_parent_name(np, 0);
4454

4555
if (!base)
46-
panic("%s: invalid address\n", np->full_name);
56+
panic("%s: invalid address\n", np->name);
57+
58+
if (readl(base + CPUCLK_DIV) & DIV_BYPASS)
59+
panic("%s: unsupported cpuclk setup\n", np->name);
60+
61+
if (readl(base + SYSCLK_DIV) & DIV_BYPASS)
62+
panic("%s: unsupported sysclk setup\n", np->name);
63+
64+
writel(0x100, base + CPUCLK_DIV); /* disable frequency ramping */
4765

4866
make_pll(0, parent, base);
4967
make_pll(1, parent, base);
68+
make_pll(2, parent, base);
69+
make_cd(2, base + 0x80);
70+
make_cd(6, base + 0x80);
5071

51-
out[0] = clk_register_divider(NULL, "cpuclk", "pll0", 0,
52-
base + CPUCLK_CTRL, 8, 8, CLK_DIVIDER_ONE_BASED, NULL);
72+
pp[0] = clk_register_divider(NULL, "cpu_clk", "pll0", 0,
73+
base + CPUCLK_DIV, 8, 8, CLK_DIVIDER_ONE_BASED, NULL);
74+
pp[1] = clk_register_fixed_factor(NULL, "sys_clk", "pll1", 0, 1, 4);
75+
pp[2] = clk_register_fixed_factor(NULL, "usb_clk", "cd2", 0, 1, 2);
76+
pp[3] = clk_register_fixed_factor(NULL, "sdio_clk", "cd6", 0, 1, 2);
5377

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);
78+
if (IS_ERR(pp[0]) || IS_ERR(pp[1]) || IS_ERR(pp[2]) || IS_ERR(pp[3]))
79+
panic("%s: clk registration failed\n", np->name);
5680

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);
81+
if (of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data))
82+
panic("%s: clk provider registration failed\n", np->name);
6083
}
6184
CLK_OF_DECLARE(tango4_clkgen, "sigma,tango4-clkgen", tango4_clkgen_setup);

0 commit comments

Comments
 (0)