xref: /openbmc/linux/drivers/clk/ti/clk-33xx.c (revision 7368b18d)
145622e21STero Kristo /*
245622e21STero Kristo  * AM33XX Clock init
345622e21STero Kristo  *
445622e21STero Kristo  * Copyright (C) 2013 Texas Instruments, Inc
545622e21STero Kristo  *     Tero Kristo (t-kristo@ti.com)
645622e21STero Kristo  *
745622e21STero Kristo  * This program is free software; you can redistribute it and/or
845622e21STero Kristo  * modify it under the terms of the GNU General Public License as
945622e21STero Kristo  * published by the Free Software Foundation version 2.
1045622e21STero Kristo  *
1145622e21STero Kristo  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
1245622e21STero Kristo  * kind, whether express or implied; without even the implied warranty
1345622e21STero Kristo  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1445622e21STero Kristo  * GNU General Public License for more details.
1545622e21STero Kristo  */
1645622e21STero Kristo 
1745622e21STero Kristo #include <linux/kernel.h>
1845622e21STero Kristo #include <linux/list.h>
191b29e601SStephen Boyd #include <linux/clk.h>
2045622e21STero Kristo #include <linux/clk-provider.h>
2145622e21STero Kristo #include <linux/clk/ti.h>
2245622e21STero Kristo 
23a5aa8a60STero Kristo #include "clock.h"
24a5aa8a60STero Kristo 
2545622e21STero Kristo static struct ti_dt_clk am33xx_clks[] = {
2645622e21STero Kristo 	DT_CLK(NULL, "timer_32k_ck", "clkdiv32k_ick"),
2745622e21STero Kristo 	DT_CLK(NULL, "timer_sys_ck", "sys_clkin_ck"),
2845622e21STero Kristo 	{ .node_name = NULL },
2945622e21STero Kristo };
3045622e21STero Kristo 
3145622e21STero Kristo static const char *enable_init_clks[] = {
3245622e21STero Kristo 	"dpll_ddr_m2_ck",
3345622e21STero Kristo 	"dpll_mpu_m2_ck",
3445622e21STero Kristo 	"l3_gclk",
3545622e21STero Kristo 	"l4hs_gclk",
3645622e21STero Kristo 	"l4fw_gclk",
3745622e21STero Kristo 	"l4ls_gclk",
3845622e21STero Kristo 	/* Required for external peripherals like, Audio codecs */
3945622e21STero Kristo 	"clkout2_ck",
4045622e21STero Kristo };
4145622e21STero Kristo 
4245622e21STero Kristo int __init am33xx_dt_clk_init(void)
4345622e21STero Kristo {
4445622e21STero Kristo 	struct clk *clk1, *clk2;
4545622e21STero Kristo 
4645622e21STero Kristo 	ti_dt_clocks_register(am33xx_clks);
4745622e21STero Kristo 
4845622e21STero Kristo 	omap2_clk_disable_autoidle_all();
4945622e21STero Kristo 
507368b18dSTero Kristo 	ti_clk_add_aliases();
517368b18dSTero Kristo 
5245622e21STero Kristo 	omap2_clk_enable_init_clocks(enable_init_clks,
5345622e21STero Kristo 				     ARRAY_SIZE(enable_init_clks));
5445622e21STero Kristo 
5545622e21STero Kristo 	/* TRM ERRATA: Timer 3 & 6 default parent (TCLKIN) may not be always
5645622e21STero Kristo 	 *    physically present, in such a case HWMOD enabling of
5745622e21STero Kristo 	 *    clock would be failure with default parent. And timer
5845622e21STero Kristo 	 *    probe thinks clock is already enabled, this leads to
5945622e21STero Kristo 	 *    crash upon accessing timer 3 & 6 registers in probe.
6045622e21STero Kristo 	 *    Fix by setting parent of both these timers to master
6145622e21STero Kristo 	 *    oscillator clock.
6245622e21STero Kristo 	 */
6345622e21STero Kristo 
6445622e21STero Kristo 	clk1 = clk_get_sys(NULL, "sys_clkin_ck");
6545622e21STero Kristo 	clk2 = clk_get_sys(NULL, "timer3_fck");
6645622e21STero Kristo 	clk_set_parent(clk2, clk1);
6745622e21STero Kristo 
6845622e21STero Kristo 	clk2 = clk_get_sys(NULL, "timer6_fck");
6945622e21STero Kristo 	clk_set_parent(clk2, clk1);
7045622e21STero Kristo 	/*
7145622e21STero Kristo 	 * The On-Chip 32K RC Osc clock is not an accurate clock-source as per
7245622e21STero Kristo 	 * the design/spec, so as a result, for example, timer which supposed
7345622e21STero Kristo 	 * to get expired @60Sec, but will expire somewhere ~@40Sec, which is
7445622e21STero Kristo 	 * not expected by any use-case, so change WDT1 clock source to PRCM
7545622e21STero Kristo 	 * 32KHz clock.
7645622e21STero Kristo 	 */
7745622e21STero Kristo 	clk1 = clk_get_sys(NULL, "wdt1_fck");
7845622e21STero Kristo 	clk2 = clk_get_sys(NULL, "clkdiv32k_ick");
7945622e21STero Kristo 	clk_set_parent(clk1, clk2);
8045622e21STero Kristo 
8145622e21STero Kristo 	return 0;
8245622e21STero Kristo }
83