xref: /openbmc/linux/drivers/clk/ti/clk-814x.c (revision 21330497f303c55fd6a34d511a98eb0a31aa1bd7)
19cf705deSTony Lindgren /*
29cf705deSTony Lindgren  * This program is free software; you can redistribute it and/or
39cf705deSTony Lindgren  * modify it under the terms of the GNU General Public License as
49cf705deSTony Lindgren  * published by the Free Software Foundation version 2.
59cf705deSTony Lindgren  */
69cf705deSTony Lindgren 
79cf705deSTony Lindgren #include <linux/kernel.h>
8*21330497STony Lindgren #include <linux/clk.h>
99cf705deSTony Lindgren #include <linux/clk-provider.h>
109cf705deSTony Lindgren #include <linux/clk/ti.h>
11*21330497STony Lindgren #include <linux/of_platform.h>
129cf705deSTony Lindgren 
13f9511a4fSStephen Rothwell #include "clock.h"
14f9511a4fSStephen Rothwell 
159cf705deSTony Lindgren static struct ti_dt_clk dm814_clks[] = {
169cf705deSTony Lindgren 	DT_CLK(NULL, "devosc_ck", "devosc_ck"),
179cf705deSTony Lindgren 	DT_CLK(NULL, "mpu_ck", "mpu_ck"),
189cf705deSTony Lindgren 	DT_CLK(NULL, "sysclk4_ck", "sysclk4_ck"),
195fbeef58STony Lindgren 	DT_CLK(NULL, "sysclk5_ck", "sysclk5_ck"),
209cf705deSTony Lindgren 	DT_CLK(NULL, "sysclk6_ck", "sysclk6_ck"),
215fbeef58STony Lindgren 	DT_CLK(NULL, "sysclk8_ck", "sysclk8_ck"),
229cf705deSTony Lindgren 	DT_CLK(NULL, "sysclk10_ck", "sysclk10_ck"),
239cf705deSTony Lindgren 	DT_CLK(NULL, "sysclk18_ck", "sysclk18_ck"),
249cf705deSTony Lindgren 	DT_CLK(NULL, "timer_sys_ck", "devosc_ck"),
255fbeef58STony Lindgren 	DT_CLK(NULL, "timer1_fck", "timer1_fck"),
265fbeef58STony Lindgren 	DT_CLK(NULL, "timer2_fck", "timer2_fck"),
279cf705deSTony Lindgren 	DT_CLK(NULL, "cpsw_125mhz_gclk", "cpsw_125mhz_gclk"),
289cf705deSTony Lindgren 	DT_CLK(NULL, "cpsw_cpts_rft_clk", "cpsw_cpts_rft_clk"),
299cf705deSTony Lindgren 	{ .node_name = NULL },
309cf705deSTony Lindgren };
319cf705deSTony Lindgren 
32*21330497STony Lindgren static bool timer_clocks_initialized;
33*21330497STony Lindgren 
34*21330497STony Lindgren int __init dm814x_adpll_early_init(void)
35*21330497STony Lindgren {
36*21330497STony Lindgren 	struct device_node *np;
37*21330497STony Lindgren 
38*21330497STony Lindgren 	if (!timer_clocks_initialized)
39*21330497STony Lindgren 		return -ENODEV;
40*21330497STony Lindgren 
41*21330497STony Lindgren 	np = of_find_node_by_name(NULL, "pllss");
42*21330497STony Lindgren 	if (!np) {
43*21330497STony Lindgren 		pr_err("Could not find node for plls\n");
44*21330497STony Lindgren 		return -ENODEV;
45*21330497STony Lindgren 	}
46*21330497STony Lindgren 
47*21330497STony Lindgren 	of_platform_populate(np, NULL, NULL, NULL);
48*21330497STony Lindgren 
49*21330497STony Lindgren 	return 0;
50*21330497STony Lindgren }
51*21330497STony Lindgren core_initcall(dm814x_adpll_early_init);
52*21330497STony Lindgren 
53*21330497STony Lindgren static const char * const init_clocks[] = {
54*21330497STony Lindgren 	"pll040clkout",		/* MPU 481c5040.adpll.clkout */
55*21330497STony Lindgren 	"pll290clkout",		/* DDR 481c5290.adpll.clkout */
56*21330497STony Lindgren };
57*21330497STony Lindgren 
58*21330497STony Lindgren int __init dm814x_adpll_enable_init_clocks(void)
59*21330497STony Lindgren {
60*21330497STony Lindgren 	int i, err;
61*21330497STony Lindgren 
62*21330497STony Lindgren 	if (!timer_clocks_initialized)
63*21330497STony Lindgren 		return -ENODEV;
64*21330497STony Lindgren 
65*21330497STony Lindgren 	for (i = 0; i < ARRAY_SIZE(init_clocks); i++) {
66*21330497STony Lindgren 		struct clk *clock;
67*21330497STony Lindgren 
68*21330497STony Lindgren 		clock = clk_get(NULL, init_clocks[i]);
69*21330497STony Lindgren 		if (WARN(IS_ERR(clock), "could not find init clock %s\n",
70*21330497STony Lindgren 			 init_clocks[i]))
71*21330497STony Lindgren 			continue;
72*21330497STony Lindgren 		err = clk_prepare_enable(clock);
73*21330497STony Lindgren 		if (WARN(err, "could not enable init clock %s\n",
74*21330497STony Lindgren 			 init_clocks[i]))
75*21330497STony Lindgren 			continue;
76*21330497STony Lindgren 	}
77*21330497STony Lindgren 
78*21330497STony Lindgren 	return 0;
79*21330497STony Lindgren }
80*21330497STony Lindgren postcore_initcall(dm814x_adpll_enable_init_clocks);
81*21330497STony Lindgren 
829cf705deSTony Lindgren int __init dm814x_dt_clk_init(void)
839cf705deSTony Lindgren {
849cf705deSTony Lindgren 	ti_dt_clocks_register(dm814_clks);
859cf705deSTony Lindgren 	omap2_clk_disable_autoidle_all();
869cf705deSTony Lindgren 	omap2_clk_enable_init_clocks(NULL, 0);
87*21330497STony Lindgren 	timer_clocks_initialized = true;
889cf705deSTony Lindgren 
899cf705deSTony Lindgren 	return 0;
909cf705deSTony Lindgren }
91