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> 12*26ca2e97STero Kristo #include <dt-bindings/clock/dm814.h> 139cf705deSTony Lindgren 14f9511a4fSStephen Rothwell #include "clock.h" 15f9511a4fSStephen Rothwell 16*26ca2e97STero Kristo static const struct omap_clkctrl_reg_data dm814_default_clkctrl_regs[] __initconst = { 17*26ca2e97STero Kristo { DM814_USB_OTG_HS_CLKCTRL, NULL, CLKF_SW_SUP, "pll260dcoclkldo" }, 18*26ca2e97STero Kristo { 0 }, 19*26ca2e97STero Kristo }; 20*26ca2e97STero Kristo 21*26ca2e97STero Kristo static const struct omap_clkctrl_reg_data dm814_alwon_clkctrl_regs[] __initconst = { 22*26ca2e97STero Kristo { DM814_UART1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" }, 23*26ca2e97STero Kristo { DM814_UART2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" }, 24*26ca2e97STero Kristo { DM814_UART3_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" }, 25*26ca2e97STero Kristo { DM814_GPIO1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk6_ck" }, 26*26ca2e97STero Kristo { DM814_GPIO2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk6_ck" }, 27*26ca2e97STero Kristo { DM814_I2C1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" }, 28*26ca2e97STero Kristo { DM814_I2C2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" }, 29*26ca2e97STero Kristo { DM814_WD_TIMER_CLKCTRL, NULL, CLKF_SW_SUP | CLKF_NO_IDLEST, "sysclk18_ck" }, 30*26ca2e97STero Kristo { DM814_MCSPI1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk10_ck" }, 31*26ca2e97STero Kristo { DM814_GPMC_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk6_ck" }, 32*26ca2e97STero Kristo { DM814_CPGMAC0_CLKCTRL, NULL, CLKF_SW_SUP, "cpsw_125mhz_gclk" }, 33*26ca2e97STero Kristo { DM814_MPU_CLKCTRL, NULL, CLKF_SW_SUP, "mpu_ck" }, 34*26ca2e97STero Kristo { DM814_RTC_CLKCTRL, NULL, CLKF_SW_SUP | CLKF_NO_IDLEST, "sysclk18_ck" }, 35*26ca2e97STero Kristo { DM814_TPCC_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 36*26ca2e97STero Kristo { DM814_TPTC0_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 37*26ca2e97STero Kristo { DM814_TPTC1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 38*26ca2e97STero Kristo { DM814_TPTC2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 39*26ca2e97STero Kristo { DM814_TPTC3_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk4_ck" }, 40*26ca2e97STero Kristo { DM814_MMC1_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk8_ck" }, 41*26ca2e97STero Kristo { DM814_MMC2_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk8_ck" }, 42*26ca2e97STero Kristo { DM814_MMC3_CLKCTRL, NULL, CLKF_SW_SUP, "sysclk8_ck" }, 43*26ca2e97STero Kristo { 0 }, 44*26ca2e97STero Kristo }; 45*26ca2e97STero Kristo 46*26ca2e97STero Kristo const struct omap_clkctrl_data dm814_clkctrl_data[] __initconst = { 47*26ca2e97STero Kristo { 0x48180500, dm814_default_clkctrl_regs }, 48*26ca2e97STero Kristo { 0x48181400, dm814_alwon_clkctrl_regs }, 49*26ca2e97STero Kristo { 0 }, 50*26ca2e97STero Kristo }; 51*26ca2e97STero Kristo 529cf705deSTony Lindgren static struct ti_dt_clk dm814_clks[] = { 539cf705deSTony Lindgren DT_CLK(NULL, "timer_sys_ck", "devosc_ck"), 549cf705deSTony Lindgren { .node_name = NULL }, 559cf705deSTony Lindgren }; 569cf705deSTony Lindgren 5721330497STony Lindgren static bool timer_clocks_initialized; 5821330497STony Lindgren 598a8b6eb7SStephen Boyd static int __init dm814x_adpll_early_init(void) 6021330497STony Lindgren { 6121330497STony Lindgren struct device_node *np; 6221330497STony Lindgren 6321330497STony Lindgren if (!timer_clocks_initialized) 6421330497STony Lindgren return -ENODEV; 6521330497STony Lindgren 6621330497STony Lindgren np = of_find_node_by_name(NULL, "pllss"); 6721330497STony Lindgren if (!np) { 6821330497STony Lindgren pr_err("Could not find node for plls\n"); 6921330497STony Lindgren return -ENODEV; 7021330497STony Lindgren } 7121330497STony Lindgren 7221330497STony Lindgren of_platform_populate(np, NULL, NULL, NULL); 7321330497STony Lindgren 7421330497STony Lindgren return 0; 7521330497STony Lindgren } 7621330497STony Lindgren core_initcall(dm814x_adpll_early_init); 7721330497STony Lindgren 7821330497STony Lindgren static const char * const init_clocks[] = { 7921330497STony Lindgren "pll040clkout", /* MPU 481c5040.adpll.clkout */ 8021330497STony Lindgren "pll290clkout", /* DDR 481c5290.adpll.clkout */ 8121330497STony Lindgren }; 8221330497STony Lindgren 838a8b6eb7SStephen Boyd static int __init dm814x_adpll_enable_init_clocks(void) 8421330497STony Lindgren { 8521330497STony Lindgren int i, err; 8621330497STony Lindgren 8721330497STony Lindgren if (!timer_clocks_initialized) 8821330497STony Lindgren return -ENODEV; 8921330497STony Lindgren 9021330497STony Lindgren for (i = 0; i < ARRAY_SIZE(init_clocks); i++) { 9121330497STony Lindgren struct clk *clock; 9221330497STony Lindgren 9321330497STony Lindgren clock = clk_get(NULL, init_clocks[i]); 9421330497STony Lindgren if (WARN(IS_ERR(clock), "could not find init clock %s\n", 9521330497STony Lindgren init_clocks[i])) 9621330497STony Lindgren continue; 9721330497STony Lindgren err = clk_prepare_enable(clock); 9821330497STony Lindgren if (WARN(err, "could not enable init clock %s\n", 9921330497STony Lindgren init_clocks[i])) 10021330497STony Lindgren continue; 10121330497STony Lindgren } 10221330497STony Lindgren 10321330497STony Lindgren return 0; 10421330497STony Lindgren } 10521330497STony Lindgren postcore_initcall(dm814x_adpll_enable_init_clocks); 10621330497STony Lindgren 1079cf705deSTony Lindgren int __init dm814x_dt_clk_init(void) 1089cf705deSTony Lindgren { 1099cf705deSTony Lindgren ti_dt_clocks_register(dm814_clks); 1109cf705deSTony Lindgren omap2_clk_disable_autoidle_all(); 11144d2b566STero Kristo ti_clk_add_aliases(); 1129cf705deSTony Lindgren omap2_clk_enable_init_clocks(NULL, 0); 11321330497STony Lindgren timer_clocks_initialized = true; 1149cf705deSTony Lindgren 1159cf705deSTony Lindgren return 0; 1169cf705deSTony Lindgren } 117