xref: /openbmc/linux/drivers/clk/ti/clk-814x.c (revision a10e763b87134a9a4ca3a38b5c4b533e75ec63a3)
1*a10e763bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
29cf705deSTony Lindgren 
39cf705deSTony Lindgren #include <linux/kernel.h>
421330497STony Lindgren #include <linux/clk.h>
59cf705deSTony Lindgren #include <linux/clk-provider.h>
69cf705deSTony Lindgren #include <linux/clk/ti.h>
721330497STony Lindgren #include <linux/of_platform.h>
826ca2e97STero Kristo #include <dt-bindings/clock/dm814.h>
99cf705deSTony Lindgren 
10f9511a4fSStephen Rothwell #include "clock.h"
11f9511a4fSStephen Rothwell 
1226ca2e97STero Kristo static const struct omap_clkctrl_reg_data dm814_default_clkctrl_regs[] __initconst = {
1326ca2e97STero Kristo 	{ DM814_USB_OTG_HS_CLKCTRL, NULL, CLKF_SW_SUP, "pll260dcoclkldo" },
1426ca2e97STero Kristo 	{ 0 },
1526ca2e97STero Kristo };
1626ca2e97STero Kristo 
1726ca2e97STero Kristo static const struct omap_clkctrl_reg_data dm814_alwon_clkctrl_regs[] __initconst = {
1826ca2e97STero Kristo 	{ DM814_UART1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" },
1926ca2e97STero Kristo 	{ DM814_UART2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" },
2026ca2e97STero Kristo 	{ DM814_UART3_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" },
2126ca2e97STero Kristo 	{ DM814_GPIO1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk6_ck" },
2226ca2e97STero Kristo 	{ DM814_GPIO2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk6_ck" },
2326ca2e97STero Kristo 	{ DM814_I2C1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" },
2426ca2e97STero Kristo 	{ DM814_I2C2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" },
2526ca2e97STero Kristo 	{ DM814_WD_TIMER_CLKCTRL, NULL, CLKF_SW_SUP | CLKF_NO_IDLEST, "sysclk18_ck" },
2626ca2e97STero Kristo 	{ DM814_MCSPI1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" },
2726ca2e97STero Kristo 	{ DM814_GPMC_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk6_ck" },
2826ca2e97STero Kristo 	{ DM814_CPGMAC0_CLKCTRL, NULL, CLKF_SW_SUP, "cpsw_125mhz_gclk" },
2926ca2e97STero Kristo 	{ DM814_MPU_CLKCTRL, NULL, CLKF_SW_SUP, "mpu_ck" },
3026ca2e97STero Kristo 	{ DM814_RTC_CLKCTRL, NULL, CLKF_SW_SUP | CLKF_NO_IDLEST, "sysclk18_ck" },
3126ca2e97STero Kristo 	{ DM814_TPCC_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" },
3226ca2e97STero Kristo 	{ DM814_TPTC0_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" },
3326ca2e97STero Kristo 	{ DM814_TPTC1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" },
3426ca2e97STero Kristo 	{ DM814_TPTC2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" },
3526ca2e97STero Kristo 	{ DM814_TPTC3_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" },
3626ca2e97STero Kristo 	{ DM814_MMC1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk8_ck" },
3726ca2e97STero Kristo 	{ DM814_MMC2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk8_ck" },
3826ca2e97STero Kristo 	{ DM814_MMC3_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk8_ck" },
3926ca2e97STero Kristo 	{ 0 },
4026ca2e97STero Kristo };
4126ca2e97STero Kristo 
4226ca2e97STero Kristo const struct omap_clkctrl_data dm814_clkctrl_data[] __initconst = {
4326ca2e97STero Kristo 	{ 0x48180500, dm814_default_clkctrl_regs },
4426ca2e97STero Kristo 	{ 0x48181400, dm814_alwon_clkctrl_regs },
4526ca2e97STero Kristo 	{ 0 },
4626ca2e97STero Kristo };
4726ca2e97STero Kristo 
489cf705deSTony Lindgren static struct ti_dt_clk dm814_clks[] = {
499cf705deSTony Lindgren 	DT_CLK(NULL, "timer_sys_ck", "devosc_ck"),
509cf705deSTony Lindgren 	{ .node_name = NULL },
519cf705deSTony Lindgren };
529cf705deSTony Lindgren 
5321330497STony Lindgren static bool timer_clocks_initialized;
5421330497STony Lindgren 
558a8b6eb7SStephen Boyd static int __init dm814x_adpll_early_init(void)
5621330497STony Lindgren {
5721330497STony Lindgren 	struct device_node *np;
5821330497STony Lindgren 
5921330497STony Lindgren 	if (!timer_clocks_initialized)
6021330497STony Lindgren 		return -ENODEV;
6121330497STony Lindgren 
6221330497STony Lindgren 	np = of_find_node_by_name(NULL, "pllss");
6321330497STony Lindgren 	if (!np) {
6421330497STony Lindgren 		pr_err("Could not find node for plls\n");
6521330497STony Lindgren 		return -ENODEV;
6621330497STony Lindgren 	}
6721330497STony Lindgren 
6821330497STony Lindgren 	of_platform_populate(np, NULL, NULL, NULL);
6921330497STony Lindgren 
7021330497STony Lindgren 	return 0;
7121330497STony Lindgren }
7221330497STony Lindgren core_initcall(dm814x_adpll_early_init);
7321330497STony Lindgren 
7421330497STony Lindgren static const char * const init_clocks[] = {
7521330497STony Lindgren 	"pll040clkout",		/* MPU 481c5040.adpll.clkout */
7621330497STony Lindgren 	"pll290clkout",		/* DDR 481c5290.adpll.clkout */
7721330497STony Lindgren };
7821330497STony Lindgren 
798a8b6eb7SStephen Boyd static int __init dm814x_adpll_enable_init_clocks(void)
8021330497STony Lindgren {
8121330497STony Lindgren 	int i, err;
8221330497STony Lindgren 
8321330497STony Lindgren 	if (!timer_clocks_initialized)
8421330497STony Lindgren 		return -ENODEV;
8521330497STony Lindgren 
8621330497STony Lindgren 	for (i = 0; i < ARRAY_SIZE(init_clocks); i++) {
8721330497STony Lindgren 		struct clk *clock;
8821330497STony Lindgren 
8921330497STony Lindgren 		clock = clk_get(NULL, init_clocks[i]);
9021330497STony Lindgren 		if (WARN(IS_ERR(clock), "could not find init clock %s\n",
9121330497STony Lindgren 			 init_clocks[i]))
9221330497STony Lindgren 			continue;
9321330497STony Lindgren 		err = clk_prepare_enable(clock);
9421330497STony Lindgren 		if (WARN(err, "could not enable init clock %s\n",
9521330497STony Lindgren 			 init_clocks[i]))
9621330497STony Lindgren 			continue;
9721330497STony Lindgren 	}
9821330497STony Lindgren 
9921330497STony Lindgren 	return 0;
10021330497STony Lindgren }
10121330497STony Lindgren postcore_initcall(dm814x_adpll_enable_init_clocks);
10221330497STony Lindgren 
1039cf705deSTony Lindgren int __init dm814x_dt_clk_init(void)
1049cf705deSTony Lindgren {
1059cf705deSTony Lindgren 	ti_dt_clocks_register(dm814_clks);
1069cf705deSTony Lindgren 	omap2_clk_disable_autoidle_all();
10744d2b566STero Kristo 	ti_clk_add_aliases();
1089cf705deSTony Lindgren 	omap2_clk_enable_init_clocks(NULL, 0);
10921330497STony Lindgren 	timer_clocks_initialized = true;
1109cf705deSTony Lindgren 
1119cf705deSTony Lindgren 	return 0;
1129cf705deSTony Lindgren }
113