xref: /openbmc/linux/drivers/clk/ti/clk-814x.c (revision 8a8b6eb7a87f12804f44128d6e4c59b19f224308)
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>
821330497STony Lindgren #include <linux/clk.h>
99cf705deSTony Lindgren #include <linux/clk-provider.h>
109cf705deSTony Lindgren #include <linux/clk/ti.h>
1121330497STony 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 
3221330497STony Lindgren static bool timer_clocks_initialized;
3321330497STony Lindgren 
34*8a8b6eb7SStephen Boyd static int __init dm814x_adpll_early_init(void)
3521330497STony Lindgren {
3621330497STony Lindgren 	struct device_node *np;
3721330497STony Lindgren 
3821330497STony Lindgren 	if (!timer_clocks_initialized)
3921330497STony Lindgren 		return -ENODEV;
4021330497STony Lindgren 
4121330497STony Lindgren 	np = of_find_node_by_name(NULL, "pllss");
4221330497STony Lindgren 	if (!np) {
4321330497STony Lindgren 		pr_err("Could not find node for plls\n");
4421330497STony Lindgren 		return -ENODEV;
4521330497STony Lindgren 	}
4621330497STony Lindgren 
4721330497STony Lindgren 	of_platform_populate(np, NULL, NULL, NULL);
4821330497STony Lindgren 
4921330497STony Lindgren 	return 0;
5021330497STony Lindgren }
5121330497STony Lindgren core_initcall(dm814x_adpll_early_init);
5221330497STony Lindgren 
5321330497STony Lindgren static const char * const init_clocks[] = {
5421330497STony Lindgren 	"pll040clkout",		/* MPU 481c5040.adpll.clkout */
5521330497STony Lindgren 	"pll290clkout",		/* DDR 481c5290.adpll.clkout */
5621330497STony Lindgren };
5721330497STony Lindgren 
58*8a8b6eb7SStephen Boyd static int __init dm814x_adpll_enable_init_clocks(void)
5921330497STony Lindgren {
6021330497STony Lindgren 	int i, err;
6121330497STony Lindgren 
6221330497STony Lindgren 	if (!timer_clocks_initialized)
6321330497STony Lindgren 		return -ENODEV;
6421330497STony Lindgren 
6521330497STony Lindgren 	for (i = 0; i < ARRAY_SIZE(init_clocks); i++) {
6621330497STony Lindgren 		struct clk *clock;
6721330497STony Lindgren 
6821330497STony Lindgren 		clock = clk_get(NULL, init_clocks[i]);
6921330497STony Lindgren 		if (WARN(IS_ERR(clock), "could not find init clock %s\n",
7021330497STony Lindgren 			 init_clocks[i]))
7121330497STony Lindgren 			continue;
7221330497STony Lindgren 		err = clk_prepare_enable(clock);
7321330497STony Lindgren 		if (WARN(err, "could not enable init clock %s\n",
7421330497STony Lindgren 			 init_clocks[i]))
7521330497STony Lindgren 			continue;
7621330497STony Lindgren 	}
7721330497STony Lindgren 
7821330497STony Lindgren 	return 0;
7921330497STony Lindgren }
8021330497STony Lindgren postcore_initcall(dm814x_adpll_enable_init_clocks);
8121330497STony 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);
8721330497STony Lindgren 	timer_clocks_initialized = true;
889cf705deSTony Lindgren 
899cf705deSTony Lindgren 	return 0;
909cf705deSTony Lindgren }
91