1a10e763bSThomas 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_MPU_CLKCTRL, NULL, CLKF_SW_SUP, "mpu_ck" }, 2926ca2e97STero Kristo { DM814_RTC_CLKCTRL, NULL, CLKF_SW_SUP | CLKF_NO_IDLEST, "sysclk18_ck" }, 3026ca2e97STero Kristo { DM814_TPCC_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 3126ca2e97STero Kristo { DM814_TPTC0_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 3226ca2e97STero Kristo { DM814_TPTC1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 3326ca2e97STero Kristo { DM814_TPTC2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 3426ca2e97STero Kristo { DM814_TPTC3_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 3526ca2e97STero Kristo { DM814_MMC1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk8_ck" }, 3626ca2e97STero Kristo { DM814_MMC2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk8_ck" }, 3726ca2e97STero Kristo { DM814_MMC3_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk8_ck" }, 3826ca2e97STero Kristo { 0 }, 3926ca2e97STero Kristo }; 4026ca2e97STero Kristo 41*1bf4b15bSTony Lindgren static const struct 42*1bf4b15bSTony Lindgren omap_clkctrl_reg_data dm814_alwon_ethernet_clkctrl_regs[] __initconst = { 43*1bf4b15bSTony Lindgren { 0, NULL, CLKF_SW_SUP, "cpsw_125mhz_gclk" }, 44*1bf4b15bSTony Lindgren }; 45*1bf4b15bSTony Lindgren 4626ca2e97STero Kristo const struct omap_clkctrl_data dm814_clkctrl_data[] __initconst = { 4726ca2e97STero Kristo { 0x48180500, dm814_default_clkctrl_regs }, 4826ca2e97STero Kristo { 0x48181400, dm814_alwon_clkctrl_regs }, 49*1bf4b15bSTony Lindgren { 0x481815d4, dm814_alwon_ethernet_clkctrl_regs }, 5026ca2e97STero Kristo { 0 }, 5126ca2e97STero Kristo }; 5226ca2e97STero Kristo 539cf705deSTony Lindgren static struct ti_dt_clk dm814_clks[] = { 549cf705deSTony Lindgren DT_CLK(NULL, "timer_sys_ck", "devosc_ck"), 559cf705deSTony Lindgren { .node_name = NULL }, 569cf705deSTony Lindgren }; 579cf705deSTony Lindgren 5821330497STony Lindgren static bool timer_clocks_initialized; 5921330497STony Lindgren 608a8b6eb7SStephen Boyd static int __init dm814x_adpll_early_init(void) 6121330497STony Lindgren { 6221330497STony Lindgren struct device_node *np; 6321330497STony Lindgren 6421330497STony Lindgren if (!timer_clocks_initialized) 6521330497STony Lindgren return -ENODEV; 6621330497STony Lindgren 6721330497STony Lindgren np = of_find_node_by_name(NULL, "pllss"); 6821330497STony Lindgren if (!np) { 6921330497STony Lindgren pr_err("Could not find node for plls\n"); 7021330497STony Lindgren return -ENODEV; 7121330497STony Lindgren } 7221330497STony Lindgren 7321330497STony Lindgren of_platform_populate(np, NULL, NULL, NULL); 74b684702fSNishka Dasgupta of_node_put(np); 7521330497STony Lindgren 7621330497STony Lindgren return 0; 7721330497STony Lindgren } 7821330497STony Lindgren core_initcall(dm814x_adpll_early_init); 7921330497STony Lindgren 8021330497STony Lindgren static const char * const init_clocks[] = { 8121330497STony Lindgren "pll040clkout", /* MPU 481c5040.adpll.clkout */ 8221330497STony Lindgren "pll290clkout", /* DDR 481c5290.adpll.clkout */ 8321330497STony Lindgren }; 8421330497STony Lindgren 858a8b6eb7SStephen Boyd static int __init dm814x_adpll_enable_init_clocks(void) 8621330497STony Lindgren { 8721330497STony Lindgren int i, err; 8821330497STony Lindgren 8921330497STony Lindgren if (!timer_clocks_initialized) 9021330497STony Lindgren return -ENODEV; 9121330497STony Lindgren 9221330497STony Lindgren for (i = 0; i < ARRAY_SIZE(init_clocks); i++) { 9321330497STony Lindgren struct clk *clock; 9421330497STony Lindgren 9521330497STony Lindgren clock = clk_get(NULL, init_clocks[i]); 9621330497STony Lindgren if (WARN(IS_ERR(clock), "could not find init clock %s\n", 9721330497STony Lindgren init_clocks[i])) 9821330497STony Lindgren continue; 9921330497STony Lindgren err = clk_prepare_enable(clock); 10021330497STony Lindgren if (WARN(err, "could not enable init clock %s\n", 10121330497STony Lindgren init_clocks[i])) 10221330497STony Lindgren continue; 10321330497STony Lindgren } 10421330497STony Lindgren 10521330497STony Lindgren return 0; 10621330497STony Lindgren } 10721330497STony Lindgren postcore_initcall(dm814x_adpll_enable_init_clocks); 10821330497STony Lindgren 1099cf705deSTony Lindgren int __init dm814x_dt_clk_init(void) 1109cf705deSTony Lindgren { 1119cf705deSTony Lindgren ti_dt_clocks_register(dm814_clks); 1129cf705deSTony Lindgren omap2_clk_disable_autoidle_all(); 11344d2b566STero Kristo ti_clk_add_aliases(); 1149cf705deSTony Lindgren omap2_clk_enable_init_clocks(NULL, 0); 11521330497STony Lindgren timer_clocks_initialized = true; 1169cf705deSTony Lindgren 1179cf705deSTony Lindgren return 0; 1189cf705deSTony Lindgren } 119