Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: tegra: Support runtime PM and power domain

The Clock-and-Reset controller resides in a core power domain on NVIDIA
Tegra SoCs. In order to support voltage scaling of the core power domain,
we hook up DVFS-capable clocks to the core GENPD for managing of the
GENPD's performance state based on the clock changes.

Some clocks don't have any specific physical hardware unit that backs
them, like root PLLs and system clock and they have theirs own voltage
requirements. This patch adds new clk-device driver that backs the clocks
and provides runtime PM functionality for them. A virtual clk-device is
created for each such DVFS-capable clock at the clock's registration time
by the new tegra_clk_register() helper. Driver changes clock's device
GENPD performance state based on clk-rate notifications.

In result we have this sequence of events:

1. Clock driver creates virtual device for selective clocks, enables
runtime PM for the created device and registers the clock.
2. Clk-device driver starts to listen to clock rate changes.
3. Something changes clk rate or enables/disables clk.
4. CCF core propagates the change through the clk tree.
5. Clk-device driver gets clock rate-change notification or GENPD core
handles prepare/unprepare of the clock.
6. Clk-device driver changes GENPD performance state on clock rate
change.
7. GENPD driver changes voltage regulator state change.
8. The regulator state is committed to hardware via I2C.

We rely on fact that DVFS is not needed for Tegra I2C and that Tegra I2C
driver already keeps clock always-prepared. Hence I2C subsystem stays
independent from the clk power management and there are no deadlock spots
in the sequence.

Currently all clocks are registered very early during kernel boot when the
device driver core isn't available yet. The clk-device can't be created
at that time. This patch splits the registration of the clocks in two
phases:

1. Register all essential clocks which don't use RPM and are needed
during early boot.

2. Register at a later boot time the rest of clocks.

This patch adds power management support for Tegra20 and Tegra30 clocks.

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Peter Geis <pgwipeout@gmail.com> # Ouya T30
Tested-by: Paul Fertser <fercerpav@gmail.com> # PAZ00 T20
Tested-by: Nicolas Chauvet <kwizart@gmail.com> # PAZ00 T20 and TK1 T124
Tested-by: Matt Merhar <mattmerhar@protonmail.com> # Ouya T30
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>

authored by

Dmitry Osipenko and committed by
Thierry Reding
b1bc04a2 e360e116

+421 -55
+1
drivers/clk/tegra/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 obj-y += clk.o 3 3 obj-y += clk-audio-sync.o 4 + obj-y += clk-device.o 4 5 obj-y += clk-dfll.o 5 6 obj-y += clk-divider.o 6 7 obj-y += clk-periph.o
+199
drivers/clk/tegra/clk-device.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + 3 + #include <linux/clk.h> 4 + #include <linux/clk-provider.h> 5 + #include <linux/mutex.h> 6 + #include <linux/of_device.h> 7 + #include <linux/platform_device.h> 8 + #include <linux/pm_domain.h> 9 + #include <linux/pm_opp.h> 10 + #include <linux/pm_runtime.h> 11 + #include <linux/slab.h> 12 + 13 + #include <soc/tegra/common.h> 14 + 15 + #include "clk.h" 16 + 17 + /* 18 + * This driver manages performance state of the core power domain for the 19 + * independent PLLs and system clocks. We created a virtual clock device 20 + * for such clocks, see tegra_clk_dev_register(). 21 + */ 22 + 23 + struct tegra_clk_device { 24 + struct notifier_block clk_nb; 25 + struct device *dev; 26 + struct clk_hw *hw; 27 + struct mutex lock; 28 + }; 29 + 30 + static int tegra_clock_set_pd_state(struct tegra_clk_device *clk_dev, 31 + unsigned long rate) 32 + { 33 + struct device *dev = clk_dev->dev; 34 + struct dev_pm_opp *opp; 35 + unsigned int pstate; 36 + 37 + opp = dev_pm_opp_find_freq_ceil(dev, &rate); 38 + if (opp == ERR_PTR(-ERANGE)) { 39 + /* 40 + * Some clocks may be unused by a particular board and they 41 + * may have uninitiated clock rate that is overly high. In 42 + * this case clock is expected to be disabled, but still we 43 + * need to set up performance state of the power domain and 44 + * not error out clk initialization. A typical example is 45 + * a PCIe clock on Android tablets. 46 + */ 47 + dev_dbg(dev, "failed to find ceil OPP for %luHz\n", rate); 48 + opp = dev_pm_opp_find_freq_floor(dev, &rate); 49 + } 50 + 51 + if (IS_ERR(opp)) { 52 + dev_err(dev, "failed to find OPP for %luHz: %pe\n", rate, opp); 53 + return PTR_ERR(opp); 54 + } 55 + 56 + pstate = dev_pm_opp_get_required_pstate(opp, 0); 57 + dev_pm_opp_put(opp); 58 + 59 + return dev_pm_genpd_set_performance_state(dev, pstate); 60 + } 61 + 62 + static int tegra_clock_change_notify(struct notifier_block *nb, 63 + unsigned long msg, void *data) 64 + { 65 + struct clk_notifier_data *cnd = data; 66 + struct tegra_clk_device *clk_dev; 67 + int err = 0; 68 + 69 + clk_dev = container_of(nb, struct tegra_clk_device, clk_nb); 70 + 71 + mutex_lock(&clk_dev->lock); 72 + switch (msg) { 73 + case PRE_RATE_CHANGE: 74 + if (cnd->new_rate > cnd->old_rate) 75 + err = tegra_clock_set_pd_state(clk_dev, cnd->new_rate); 76 + break; 77 + 78 + case ABORT_RATE_CHANGE: 79 + err = tegra_clock_set_pd_state(clk_dev, cnd->old_rate); 80 + break; 81 + 82 + case POST_RATE_CHANGE: 83 + if (cnd->new_rate < cnd->old_rate) 84 + err = tegra_clock_set_pd_state(clk_dev, cnd->new_rate); 85 + break; 86 + 87 + default: 88 + break; 89 + } 90 + mutex_unlock(&clk_dev->lock); 91 + 92 + return notifier_from_errno(err); 93 + } 94 + 95 + static int tegra_clock_sync_pd_state(struct tegra_clk_device *clk_dev) 96 + { 97 + unsigned long rate; 98 + int ret; 99 + 100 + mutex_lock(&clk_dev->lock); 101 + 102 + rate = clk_hw_get_rate(clk_dev->hw); 103 + ret = tegra_clock_set_pd_state(clk_dev, rate); 104 + 105 + mutex_unlock(&clk_dev->lock); 106 + 107 + return ret; 108 + } 109 + 110 + static int tegra_clock_probe(struct platform_device *pdev) 111 + { 112 + struct tegra_core_opp_params opp_params = {}; 113 + struct tegra_clk_device *clk_dev; 114 + struct device *dev = &pdev->dev; 115 + struct clk *clk; 116 + int err; 117 + 118 + if (!dev->pm_domain) 119 + return -EINVAL; 120 + 121 + clk_dev = devm_kzalloc(dev, sizeof(*clk_dev), GFP_KERNEL); 122 + if (!clk_dev) 123 + return -ENOMEM; 124 + 125 + clk = devm_clk_get(dev, NULL); 126 + if (IS_ERR(clk)) 127 + return PTR_ERR(clk); 128 + 129 + clk_dev->dev = dev; 130 + clk_dev->hw = __clk_get_hw(clk); 131 + clk_dev->clk_nb.notifier_call = tegra_clock_change_notify; 132 + mutex_init(&clk_dev->lock); 133 + 134 + platform_set_drvdata(pdev, clk_dev); 135 + 136 + /* 137 + * Runtime PM was already enabled for this device by the parent clk 138 + * driver and power domain state should be synced under clk_dev lock, 139 + * hence we don't use the common OPP helper that initializes OPP 140 + * state. For some clocks common OPP helper may fail to find ceil 141 + * rate, it's handled by this driver. 142 + */ 143 + err = devm_tegra_core_dev_init_opp_table(dev, &opp_params); 144 + if (err) 145 + return err; 146 + 147 + err = clk_notifier_register(clk, &clk_dev->clk_nb); 148 + if (err) { 149 + dev_err(dev, "failed to register clk notifier: %d\n", err); 150 + return err; 151 + } 152 + 153 + /* 154 + * The driver is attaching to a potentially active/resumed clock, hence 155 + * we need to sync the power domain performance state in a accordance to 156 + * the clock rate if clock is resumed. 157 + */ 158 + err = tegra_clock_sync_pd_state(clk_dev); 159 + if (err) 160 + goto unreg_clk; 161 + 162 + return 0; 163 + 164 + unreg_clk: 165 + clk_notifier_unregister(clk, &clk_dev->clk_nb); 166 + 167 + return err; 168 + } 169 + 170 + /* 171 + * Tegra GENPD driver enables clocks during NOIRQ phase. It can't be done 172 + * for clocks served by this driver because runtime PM is unavailable in 173 + * NOIRQ phase. We will keep clocks resumed during suspend to mitigate this 174 + * problem. In practice this makes no difference from a power management 175 + * perspective since voltage is kept at a nominal level during suspend anyways. 176 + */ 177 + static const struct dev_pm_ops tegra_clock_pm = { 178 + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_resume_and_get, pm_runtime_put) 179 + }; 180 + 181 + static const struct of_device_id tegra_clock_match[] = { 182 + { .compatible = "nvidia,tegra20-sclk" }, 183 + { .compatible = "nvidia,tegra30-sclk" }, 184 + { .compatible = "nvidia,tegra30-pllc" }, 185 + { .compatible = "nvidia,tegra30-plle" }, 186 + { .compatible = "nvidia,tegra30-pllm" }, 187 + { } 188 + }; 189 + 190 + static struct platform_driver tegra_clock_driver = { 191 + .driver = { 192 + .name = "tegra-clock", 193 + .of_match_table = tegra_clock_match, 194 + .pm = &tegra_clock_pm, 195 + .suppress_bind_attrs = true, 196 + }, 197 + .probe = tegra_clock_probe, 198 + }; 199 + builtin_platform_driver(tegra_clock_driver);
+1 -1
drivers/clk/tegra/clk-pll.c
··· 1914 1914 /* Data in .init is copied by clk_register(), so stack variable OK */ 1915 1915 pll->hw.init = &init; 1916 1916 1917 - return clk_register(NULL, &pll->hw); 1917 + return tegra_clk_dev_register(&pll->hw); 1918 1918 } 1919 1919 1920 1920 struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
+1 -1
drivers/clk/tegra/clk-super.c
··· 226 226 /* Data in .init is copied by clk_register(), so stack variable OK */ 227 227 super->hw.init = &init; 228 228 229 - clk = clk_register(NULL, &super->hw); 229 + clk = tegra_clk_dev_register(&super->hw); 230 230 if (IS_ERR(clk)) 231 231 kfree(super); 232 232
+59 -18
drivers/clk/tegra/clk-tegra20.c
··· 6 6 #include <linux/io.h> 7 7 #include <linux/clk-provider.h> 8 8 #include <linux/clkdev.h> 9 + #include <linux/init.h> 9 10 #include <linux/of.h> 10 11 #include <linux/of_address.h> 12 + #include <linux/of_device.h> 13 + #include <linux/platform_device.h> 11 14 #include <linux/clk/tegra.h> 12 15 #include <linux/delay.h> 13 16 #include <dt-bindings/clock/tegra20-car.h> ··· 417 414 .fixed_rate = 100000000, 418 415 }; 419 416 420 - static struct tegra_devclk devclks[] __initdata = { 417 + static struct tegra_devclk devclks[] = { 421 418 { .con_id = "pll_c", .dt_id = TEGRA20_CLK_PLL_C }, 422 419 { .con_id = "pll_c_out1", .dt_id = TEGRA20_CLK_PLL_C_OUT1 }, 423 420 { .con_id = "pll_p", .dt_id = TEGRA20_CLK_PLL_P }, ··· 712 709 clk_base + CCLK_BURST_POLICY, TEGRA20_SUPER_CLK, 713 710 NULL); 714 711 clks[TEGRA20_CLK_CCLK] = clk; 715 - 716 - /* SCLK */ 717 - clk = tegra_clk_register_super_mux("sclk", sclk_parents, 718 - ARRAY_SIZE(sclk_parents), 719 - CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, 720 - clk_base + SCLK_BURST_POLICY, 0, 4, 0, 0, NULL); 721 - clks[TEGRA20_CLK_SCLK] = clk; 722 712 723 713 /* twd */ 724 714 clk = clk_register_fixed_factor(NULL, "twd", "cclk", 0, 1, 4); ··· 1010 1014 #endif 1011 1015 }; 1012 1016 1013 - static struct tegra_clk_init_table init_table[] __initdata = { 1017 + static struct tegra_clk_init_table init_table[] = { 1014 1018 { TEGRA20_CLK_PLL_P, TEGRA20_CLK_CLK_MAX, 216000000, 1 }, 1015 1019 { TEGRA20_CLK_PLL_P_OUT1, TEGRA20_CLK_CLK_MAX, 28800000, 1 }, 1016 1020 { TEGRA20_CLK_PLL_P_OUT2, TEGRA20_CLK_CLK_MAX, 48000000, 1 }, ··· 1048 1052 { TEGRA20_CLK_CLK_MAX, TEGRA20_CLK_CLK_MAX, 0, 0 }, 1049 1053 }; 1050 1054 1051 - static void __init tegra20_clock_apply_init_table(void) 1052 - { 1053 - tegra_init_from_table(init_table, clks, TEGRA20_CLK_CLK_MAX); 1054 - } 1055 - 1056 1055 /* 1057 1056 * Some clocks may be used by different drivers depending on the board 1058 1057 * configuration. List those here to register them twice in the clock lookup ··· 1067 1076 { }, 1068 1077 }; 1069 1078 1079 + static bool tegra20_car_initialized; 1080 + 1070 1081 static struct clk *tegra20_clk_src_onecell_get(struct of_phandle_args *clkspec, 1071 1082 void *data) 1072 1083 { 1073 1084 struct clk_hw *parent_hw; 1074 1085 struct clk_hw *hw; 1075 1086 struct clk *clk; 1087 + 1088 + /* 1089 + * Timer clocks are needed early, the rest of the clocks shouldn't be 1090 + * available to device drivers until clock tree is fully initialized. 1091 + */ 1092 + if (clkspec->args[0] != TEGRA20_CLK_RTC && 1093 + clkspec->args[0] != TEGRA20_CLK_TWD && 1094 + clkspec->args[0] != TEGRA20_CLK_TIMER && 1095 + !tegra20_car_initialized) 1096 + return ERR_PTR(-EPROBE_DEFER); 1076 1097 1077 1098 clk = of_clk_src_onecell_get(clkspec, data); 1078 1099 if (IS_ERR(clk)) ··· 1152 1149 tegra_init_dup_clks(tegra_clk_duplicates, clks, TEGRA20_CLK_CLK_MAX); 1153 1150 1154 1151 tegra_add_of_provider(np, tegra20_clk_src_onecell_get); 1155 - tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); 1156 - 1157 - tegra_clk_apply_init_table = tegra20_clock_apply_init_table; 1158 1152 1159 1153 tegra_cpu_car_ops = &tegra20_cpu_car_ops; 1160 1154 } 1161 - CLK_OF_DECLARE(tegra20, "nvidia,tegra20-car", tegra20_clock_init); 1155 + CLK_OF_DECLARE_DRIVER(tegra20, "nvidia,tegra20-car", tegra20_clock_init); 1156 + 1157 + /* 1158 + * Clocks that use runtime PM can't be created at the tegra20_clock_init 1159 + * time because drivers' base isn't initialized yet, and thus platform 1160 + * devices can't be created for the clocks. Hence we need to split the 1161 + * registration of the clocks into two phases. The first phase registers 1162 + * essential clocks which don't require RPM and are actually used during 1163 + * early boot. The second phase registers clocks which use RPM and this 1164 + * is done when device drivers' core API is ready. 1165 + */ 1166 + static int tegra20_car_probe(struct platform_device *pdev) 1167 + { 1168 + struct clk *clk; 1169 + 1170 + clk = tegra_clk_register_super_mux("sclk", sclk_parents, 1171 + ARRAY_SIZE(sclk_parents), 1172 + CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, 1173 + clk_base + SCLK_BURST_POLICY, 0, 4, 0, 0, NULL); 1174 + clks[TEGRA20_CLK_SCLK] = clk; 1175 + 1176 + tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); 1177 + tegra_init_from_table(init_table, clks, TEGRA20_CLK_CLK_MAX); 1178 + tegra20_car_initialized = true; 1179 + 1180 + return 0; 1181 + } 1182 + 1183 + static const struct of_device_id tegra20_car_match[] = { 1184 + { .compatible = "nvidia,tegra20-car" }, 1185 + { } 1186 + }; 1187 + 1188 + static struct platform_driver tegra20_car_driver = { 1189 + .driver = { 1190 + .name = "tegra20-car", 1191 + .of_match_table = tegra20_car_match, 1192 + .suppress_bind_attrs = true, 1193 + }, 1194 + .probe = tegra20_car_probe, 1195 + }; 1196 + builtin_platform_driver(tegra20_car_driver);
+86 -32
drivers/clk/tegra/clk-tegra30.c
··· 7 7 #include <linux/delay.h> 8 8 #include <linux/clk-provider.h> 9 9 #include <linux/clkdev.h> 10 + #include <linux/init.h> 10 11 #include <linux/of.h> 11 12 #include <linux/of_address.h> 13 + #include <linux/of_device.h> 14 + #include <linux/platform_device.h> 12 15 #include <linux/clk/tegra.h> 13 16 14 17 #include <soc/tegra/pmc.h> ··· 535 532 [12] = 26000000, 536 533 }; 537 534 538 - static struct tegra_devclk devclks[] __initdata = { 535 + static struct tegra_devclk devclks[] = { 539 536 { .con_id = "pll_c", .dt_id = TEGRA30_CLK_PLL_C }, 540 537 { .con_id = "pll_c_out1", .dt_id = TEGRA30_CLK_PLL_C_OUT1 }, 541 538 { .con_id = "pll_p", .dt_id = TEGRA30_CLK_PLL_P }, ··· 815 812 { 816 813 struct clk *clk; 817 814 818 - /* PLLC */ 819 - clk = tegra_clk_register_pll("pll_c", "pll_ref", clk_base, pmc_base, 0, 820 - &pll_c_params, NULL); 821 - clks[TEGRA30_CLK_PLL_C] = clk; 822 - 823 815 /* PLLC_OUT1 */ 824 816 clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c", 825 817 clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP, ··· 823 825 clk_base + PLLC_OUT, 1, 0, CLK_SET_RATE_PARENT, 824 826 0, NULL); 825 827 clks[TEGRA30_CLK_PLL_C_OUT1] = clk; 826 - 827 - /* PLLM */ 828 - clk = tegra_clk_register_pll("pll_m", "pll_ref", clk_base, pmc_base, 829 - CLK_SET_RATE_GATE, &pll_m_params, NULL); 830 - clks[TEGRA30_CLK_PLL_M] = clk; 831 828 832 829 /* PLLM_OUT1 */ 833 830 clk = tegra_clk_register_divider("pll_m_out1_div", "pll_m", ··· 873 880 ARRAY_SIZE(pll_e_parents), 874 881 CLK_SET_RATE_NO_REPARENT, 875 882 clk_base + PLLE_AUX, 2, 1, 0, NULL); 876 - clk = tegra_clk_register_plle("pll_e", "pll_e_mux", clk_base, pmc_base, 877 - CLK_GET_RATE_NOCACHE, &pll_e_params, NULL); 878 - clks[TEGRA30_CLK_PLL_E] = clk; 879 883 } 880 884 881 885 static const char *cclk_g_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m", ··· 960 970 TEGRA_DIVIDER_2, 4, 8, 9, 961 971 NULL); 962 972 clks[TEGRA30_CLK_CCLK_LP] = clk; 963 - 964 - /* SCLK */ 965 - clk = tegra_clk_register_super_mux("sclk", sclk_parents, 966 - ARRAY_SIZE(sclk_parents), 967 - CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, 968 - clk_base + SCLK_BURST_POLICY, 969 - 0, 4, 0, 0, NULL); 970 - clks[TEGRA30_CLK_SCLK] = clk; 971 973 972 974 /* twd */ 973 975 clk = clk_register_fixed_factor(NULL, "twd", "cclk_g", ··· 1196 1214 #endif 1197 1215 }; 1198 1216 1199 - static struct tegra_clk_init_table init_table[] __initdata = { 1217 + static struct tegra_clk_init_table init_table[] = { 1200 1218 { TEGRA30_CLK_UARTA, TEGRA30_CLK_PLL_P, 408000000, 0 }, 1201 1219 { TEGRA30_CLK_UARTB, TEGRA30_CLK_PLL_P, 408000000, 0 }, 1202 1220 { TEGRA30_CLK_UARTC, TEGRA30_CLK_PLL_P, 408000000, 0 }, ··· 1241 1259 { TEGRA30_CLK_CLK_MAX, TEGRA30_CLK_CLK_MAX, 0, 0 }, 1242 1260 }; 1243 1261 1244 - static void __init tegra30_clock_apply_init_table(void) 1245 - { 1246 - tegra_init_from_table(init_table, clks, TEGRA30_CLK_CLK_MAX); 1247 - } 1248 - 1249 1262 /* 1250 1263 * Some clocks may be used by different drivers depending on the board 1251 1264 * configuration. List those here to register them twice in the clock lookup ··· 1271 1294 { "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_p_out1" }, 1272 1295 }; 1273 1296 1297 + static bool tegra30_car_initialized; 1298 + 1274 1299 static struct clk *tegra30_clk_src_onecell_get(struct of_phandle_args *clkspec, 1275 1300 void *data) 1276 1301 { 1277 1302 struct clk_hw *hw; 1278 1303 struct clk *clk; 1304 + 1305 + /* 1306 + * Timer clocks are needed early, the rest of the clocks shouldn't be 1307 + * available to device drivers until clock tree is fully initialized. 1308 + */ 1309 + if (clkspec->args[0] != TEGRA30_CLK_RTC && 1310 + clkspec->args[0] != TEGRA30_CLK_TWD && 1311 + clkspec->args[0] != TEGRA30_CLK_TIMER && 1312 + !tegra30_car_initialized) 1313 + return ERR_PTR(-EPROBE_DEFER); 1279 1314 1280 1315 clk = of_clk_src_onecell_get(clkspec, data); 1281 1316 if (IS_ERR(clk)) ··· 1346 1357 tegra_init_dup_clks(tegra_clk_duplicates, clks, TEGRA30_CLK_CLK_MAX); 1347 1358 1348 1359 tegra_add_of_provider(np, tegra30_clk_src_onecell_get); 1349 - tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); 1350 - 1351 - tegra_clk_apply_init_table = tegra30_clock_apply_init_table; 1352 1360 1353 1361 tegra_cpu_car_ops = &tegra30_cpu_car_ops; 1354 1362 } 1355 - CLK_OF_DECLARE(tegra30, "nvidia,tegra30-car", tegra30_clock_init); 1363 + CLK_OF_DECLARE_DRIVER(tegra30, "nvidia,tegra30-car", tegra30_clock_init); 1364 + 1365 + /* 1366 + * Clocks that use runtime PM can't be created at the tegra30_clock_init 1367 + * time because drivers' base isn't initialized yet, and thus platform 1368 + * devices can't be created for the clocks. Hence we need to split the 1369 + * registration of the clocks into two phases. The first phase registers 1370 + * essential clocks which don't require RPM and are actually used during 1371 + * early boot. The second phase registers clocks which use RPM and this 1372 + * is done when device drivers' core API is ready. 1373 + */ 1374 + static int tegra30_car_probe(struct platform_device *pdev) 1375 + { 1376 + struct clk *clk; 1377 + 1378 + /* PLLC */ 1379 + clk = tegra_clk_register_pll("pll_c", "pll_ref", clk_base, pmc_base, 0, 1380 + &pll_c_params, NULL); 1381 + clks[TEGRA30_CLK_PLL_C] = clk; 1382 + 1383 + /* PLLE */ 1384 + clk = tegra_clk_register_plle("pll_e", "pll_e_mux", clk_base, pmc_base, 1385 + CLK_GET_RATE_NOCACHE, &pll_e_params, NULL); 1386 + clks[TEGRA30_CLK_PLL_E] = clk; 1387 + 1388 + /* PLLM */ 1389 + clk = tegra_clk_register_pll("pll_m", "pll_ref", clk_base, pmc_base, 1390 + CLK_SET_RATE_GATE, &pll_m_params, NULL); 1391 + clks[TEGRA30_CLK_PLL_M] = clk; 1392 + 1393 + /* SCLK */ 1394 + clk = tegra_clk_register_super_mux("sclk", sclk_parents, 1395 + ARRAY_SIZE(sclk_parents), 1396 + CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, 1397 + clk_base + SCLK_BURST_POLICY, 1398 + 0, 4, 0, 0, NULL); 1399 + clks[TEGRA30_CLK_SCLK] = clk; 1400 + 1401 + tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); 1402 + tegra_init_from_table(init_table, clks, TEGRA30_CLK_CLK_MAX); 1403 + tegra30_car_initialized = true; 1404 + 1405 + return 0; 1406 + } 1407 + 1408 + static const struct of_device_id tegra30_car_match[] = { 1409 + { .compatible = "nvidia,tegra30-car" }, 1410 + { } 1411 + }; 1412 + 1413 + static struct platform_driver tegra30_car_driver = { 1414 + .driver = { 1415 + .name = "tegra30-car", 1416 + .of_match_table = tegra30_car_match, 1417 + .suppress_bind_attrs = true, 1418 + }, 1419 + .probe = tegra30_car_probe, 1420 + }; 1421 + 1422 + /* 1423 + * Clock driver must be registered before memory controller driver, 1424 + * which doesn't support deferred probing for today and is registered 1425 + * from arch init-level. 1426 + */ 1427 + static int tegra30_car_init(void) 1428 + { 1429 + return platform_driver_register(&tegra30_car_driver); 1430 + } 1431 + postcore_initcall(tegra30_car_init);
+72 -3
drivers/clk/tegra/clk.c
··· 9 9 #include <linux/delay.h> 10 10 #include <linux/io.h> 11 11 #include <linux/of.h> 12 + #include <linux/of_device.h> 12 13 #include <linux/clk/tegra.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/pm_runtime.h> 13 16 #include <linux/reset-controller.h> 17 + #include <linux/string.h> 14 18 15 19 #include <soc/tegra/fuse.h> 16 20 17 21 #include "clk.h" 18 22 19 23 /* Global data of Tegra CPU CAR ops */ 24 + static struct device_node *tegra_car_np; 20 25 static struct tegra_cpu_car_ops dummy_car_ops; 21 26 struct tegra_cpu_car_ops *tegra_cpu_car_ops = &dummy_car_ops; 22 27 ··· 266 261 } 267 262 } 268 263 269 - void __init tegra_init_from_table(struct tegra_clk_init_table *tbl, 270 - struct clk *clks[], int clk_max) 264 + void tegra_init_from_table(struct tegra_clk_init_table *tbl, 265 + struct clk *clks[], int clk_max) 271 266 { 272 267 struct clk *clk; 273 268 ··· 325 320 { 326 321 int i; 327 322 323 + tegra_car_np = np; 324 + 328 325 for (i = 0; i < clk_num; i++) { 329 326 if (IS_ERR(clks[i])) { 330 327 pr_err ··· 355 348 special_reset_deassert = deassert; 356 349 } 357 350 358 - void __init tegra_register_devclks(struct tegra_devclk *dev_clks, int num) 351 + void tegra_register_devclks(struct tegra_devclk *dev_clks, int num) 359 352 { 360 353 int i; 361 354 ··· 377 370 return &clks[tegra_clk[clk_id].dt_id]; 378 371 else 379 372 return NULL; 373 + } 374 + 375 + static struct device_node *tegra_clk_get_of_node(struct clk_hw *hw) 376 + { 377 + struct device_node *np; 378 + char *node_name; 379 + 380 + node_name = kstrdup(hw->init->name, GFP_KERNEL); 381 + if (!node_name) 382 + return NULL; 383 + 384 + strreplace(node_name, '_', '-'); 385 + 386 + for_each_child_of_node(tegra_car_np, np) { 387 + if (!strcmp(np->name, node_name)) 388 + break; 389 + } 390 + 391 + kfree(node_name); 392 + 393 + return np; 394 + } 395 + 396 + struct clk *tegra_clk_dev_register(struct clk_hw *hw) 397 + { 398 + struct platform_device *pdev, *parent; 399 + const char *dev_name = NULL; 400 + struct device *dev = NULL; 401 + struct device_node *np; 402 + 403 + np = tegra_clk_get_of_node(hw); 404 + 405 + if (!of_device_is_available(np)) 406 + goto put_node; 407 + 408 + dev_name = kasprintf(GFP_KERNEL, "tegra_clk_%s", hw->init->name); 409 + if (!dev_name) 410 + goto put_node; 411 + 412 + parent = of_find_device_by_node(tegra_car_np); 413 + if (parent) { 414 + pdev = of_platform_device_create(np, dev_name, &parent->dev); 415 + put_device(&parent->dev); 416 + 417 + if (!pdev) { 418 + pr_err("%s: failed to create device for %pOF\n", 419 + __func__, np); 420 + goto free_name; 421 + } 422 + 423 + dev = &pdev->dev; 424 + pm_runtime_enable(dev); 425 + } else { 426 + WARN(1, "failed to find device for %pOF\n", tegra_car_np); 427 + } 428 + 429 + free_name: 430 + kfree(dev_name); 431 + put_node: 432 + of_node_put(np); 433 + 434 + return clk_register(dev, hw); 380 435 } 381 436 382 437 tegra_clk_apply_init_table_func tegra_clk_apply_init_table;
+2
drivers/clk/tegra/clk.h
··· 927 927 struct clk *tegra210_clk_register_emc(struct device_node *np, 928 928 void __iomem *regs); 929 929 930 + struct clk *tegra_clk_dev_register(struct clk_hw *hw); 931 + 930 932 #endif /* TEGRA_CLK_H */