xref: /openbmc/linux/drivers/clk/ti/clk-814x.c (revision 44d2b566)
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License as
4  * published by the Free Software Foundation version 2.
5  */
6 
7 #include <linux/kernel.h>
8 #include <linux/clk.h>
9 #include <linux/clk-provider.h>
10 #include <linux/clk/ti.h>
11 #include <linux/of_platform.h>
12 
13 #include "clock.h"
14 
15 static struct ti_dt_clk dm814_clks[] = {
16 	DT_CLK(NULL, "timer_sys_ck", "devosc_ck"),
17 	{ .node_name = NULL },
18 };
19 
20 static bool timer_clocks_initialized;
21 
22 static int __init dm814x_adpll_early_init(void)
23 {
24 	struct device_node *np;
25 
26 	if (!timer_clocks_initialized)
27 		return -ENODEV;
28 
29 	np = of_find_node_by_name(NULL, "pllss");
30 	if (!np) {
31 		pr_err("Could not find node for plls\n");
32 		return -ENODEV;
33 	}
34 
35 	of_platform_populate(np, NULL, NULL, NULL);
36 
37 	return 0;
38 }
39 core_initcall(dm814x_adpll_early_init);
40 
41 static const char * const init_clocks[] = {
42 	"pll040clkout",		/* MPU 481c5040.adpll.clkout */
43 	"pll290clkout",		/* DDR 481c5290.adpll.clkout */
44 };
45 
46 static int __init dm814x_adpll_enable_init_clocks(void)
47 {
48 	int i, err;
49 
50 	if (!timer_clocks_initialized)
51 		return -ENODEV;
52 
53 	for (i = 0; i < ARRAY_SIZE(init_clocks); i++) {
54 		struct clk *clock;
55 
56 		clock = clk_get(NULL, init_clocks[i]);
57 		if (WARN(IS_ERR(clock), "could not find init clock %s\n",
58 			 init_clocks[i]))
59 			continue;
60 		err = clk_prepare_enable(clock);
61 		if (WARN(err, "could not enable init clock %s\n",
62 			 init_clocks[i]))
63 			continue;
64 	}
65 
66 	return 0;
67 }
68 postcore_initcall(dm814x_adpll_enable_init_clocks);
69 
70 int __init dm814x_dt_clk_init(void)
71 {
72 	ti_dt_clocks_register(dm814_clks);
73 	omap2_clk_disable_autoidle_all();
74 	ti_clk_add_aliases();
75 	omap2_clk_enable_init_clocks(NULL, 0);
76 	timer_clocks_initialized = true;
77 
78 	return 0;
79 }
80