66#include <linux/io.h>
77#include <linux/clk-provider.h>
88#include <linux/clkdev.h>
9+ #include <linux/init.h>
910#include <linux/of.h>
1011#include <linux/of_address.h>
12+ #include <linux/of_device.h>
13+ #include <linux/platform_device.h>
1114#include <linux/clk/tegra.h>
1215#include <linux/delay.h>
1316#include <dt-bindings/clock/tegra20-car.h>
@@ -414,7 +417,7 @@ static struct tegra_clk_pll_params pll_e_params = {
414417 .fixed_rate = 100000000 ,
415418};
416419
417- static struct tegra_devclk devclks [] __initdata = {
420+ static struct tegra_devclk devclks [] = {
418421 { .con_id = "pll_c" , .dt_id = TEGRA20_CLK_PLL_C },
419422 { .con_id = "pll_c_out1" , .dt_id = TEGRA20_CLK_PLL_C_OUT1 },
420423 { .con_id = "pll_p" , .dt_id = TEGRA20_CLK_PLL_P },
@@ -710,13 +713,6 @@ static void tegra20_super_clk_init(void)
710713 NULL );
711714 clks [TEGRA20_CLK_CCLK ] = clk ;
712715
713- /* SCLK */
714- clk = tegra_clk_register_super_mux ("sclk" , sclk_parents ,
715- ARRAY_SIZE (sclk_parents ),
716- CLK_SET_RATE_PARENT | CLK_IS_CRITICAL ,
717- clk_base + SCLK_BURST_POLICY , 0 , 4 , 0 , 0 , NULL );
718- clks [TEGRA20_CLK_SCLK ] = clk ;
719-
720716 /* twd */
721717 clk = clk_register_fixed_factor (NULL , "twd" , "cclk" , 0 , 1 , 4 );
722718 clks [TEGRA20_CLK_TWD ] = clk ;
@@ -1014,7 +1010,7 @@ static struct tegra_cpu_car_ops tegra20_cpu_car_ops = {
10141010#endif
10151011};
10161012
1017- static struct tegra_clk_init_table init_table [] __initdata = {
1013+ static struct tegra_clk_init_table init_table [] = {
10181014 { TEGRA20_CLK_PLL_P , TEGRA20_CLK_CLK_MAX , 216000000 , 1 },
10191015 { TEGRA20_CLK_PLL_P_OUT1 , TEGRA20_CLK_CLK_MAX , 28800000 , 1 },
10201016 { TEGRA20_CLK_PLL_P_OUT2 , TEGRA20_CLK_CLK_MAX , 48000000 , 1 },
@@ -1052,11 +1048,6 @@ static struct tegra_clk_init_table init_table[] __initdata = {
10521048 { TEGRA20_CLK_CLK_MAX , TEGRA20_CLK_CLK_MAX , 0 , 0 },
10531049};
10541050
1055- static void __init tegra20_clock_apply_init_table (void )
1056- {
1057- tegra_init_from_table (init_table , clks , TEGRA20_CLK_CLK_MAX );
1058- }
1059-
10601051/*
10611052 * Some clocks may be used by different drivers depending on the board
10621053 * configuration. List those here to register them twice in the clock lookup
@@ -1076,13 +1067,25 @@ static const struct of_device_id pmc_match[] __initconst = {
10761067 { },
10771068};
10781069
1070+ static bool tegra20_car_initialized ;
1071+
10791072static struct clk * tegra20_clk_src_onecell_get (struct of_phandle_args * clkspec ,
10801073 void * data )
10811074{
10821075 struct clk_hw * parent_hw ;
10831076 struct clk_hw * hw ;
10841077 struct clk * clk ;
10851078
1079+ /*
1080+ * Timer clocks are needed early, the rest of the clocks shouldn't be
1081+ * available to device drivers until clock tree is fully initialized.
1082+ */
1083+ if (clkspec -> args [0 ] != TEGRA20_CLK_RTC &&
1084+ clkspec -> args [0 ] != TEGRA20_CLK_TWD &&
1085+ clkspec -> args [0 ] != TEGRA20_CLK_TIMER &&
1086+ !tegra20_car_initialized )
1087+ return ERR_PTR (- EPROBE_DEFER );
1088+
10861089 clk = of_clk_src_onecell_get (clkspec , data );
10871090 if (IS_ERR (clk ))
10881091 return clk ;
@@ -1149,10 +1152,48 @@ static void __init tegra20_clock_init(struct device_node *np)
11491152 tegra_init_dup_clks (tegra_clk_duplicates , clks , TEGRA20_CLK_CLK_MAX );
11501153
11511154 tegra_add_of_provider (np , tegra20_clk_src_onecell_get );
1152- tegra_register_devclks (devclks , ARRAY_SIZE (devclks ));
1153-
1154- tegra_clk_apply_init_table = tegra20_clock_apply_init_table ;
11551155
11561156 tegra_cpu_car_ops = & tegra20_cpu_car_ops ;
11571157}
1158- CLK_OF_DECLARE (tegra20 , "nvidia,tegra20-car" , tegra20_clock_init );
1158+ CLK_OF_DECLARE_DRIVER (tegra20 , "nvidia,tegra20-car" , tegra20_clock_init );
1159+
1160+ /*
1161+ * Clocks that use runtime PM can't be created at the tegra20_clock_init
1162+ * time because drivers' base isn't initialized yet, and thus platform
1163+ * devices can't be created for the clocks. Hence we need to split the
1164+ * registration of the clocks into two phases. The first phase registers
1165+ * essential clocks which don't require RPM and are actually used during
1166+ * early boot. The second phase registers clocks which use RPM and this
1167+ * is done when device drivers' core API is ready.
1168+ */
1169+ static int tegra20_car_probe (struct platform_device * pdev )
1170+ {
1171+ struct clk * clk ;
1172+
1173+ clk = tegra_clk_register_super_mux ("sclk" , sclk_parents ,
1174+ ARRAY_SIZE (sclk_parents ),
1175+ CLK_SET_RATE_PARENT | CLK_IS_CRITICAL ,
1176+ clk_base + SCLK_BURST_POLICY , 0 , 4 , 0 , 0 , NULL );
1177+ clks [TEGRA20_CLK_SCLK ] = clk ;
1178+
1179+ tegra_register_devclks (devclks , ARRAY_SIZE (devclks ));
1180+ tegra_init_from_table (init_table , clks , TEGRA20_CLK_CLK_MAX );
1181+ tegra20_car_initialized = true;
1182+
1183+ return 0 ;
1184+ }
1185+
1186+ static const struct of_device_id tegra20_car_match [] = {
1187+ { .compatible = "nvidia,tegra20-car" },
1188+ { }
1189+ };
1190+
1191+ static struct platform_driver tegra20_car_driver = {
1192+ .driver = {
1193+ .name = "tegra20-car" ,
1194+ .of_match_table = tegra20_car_match ,
1195+ .suppress_bind_attrs = true,
1196+ },
1197+ .probe = tegra20_car_probe ,
1198+ };
1199+ builtin_platform_driver (tegra20_car_driver );
0 commit comments