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

cpufreq: tegra124: Add suspend and resume support

This patch adds suspend and resume pm ops for cpufreq driver.

PLLP is the safe clock source for CPU during system suspend and
resume as PLLP rate is below the CPU Fmax at Vmin.

CPUFreq driver suspend switches the CPU clock source to PLLP and
disables the DFLL clock.

During system resume, warmboot code powers up the CPU with PLLP
clock source. So CPUFreq driver resume enabled DFLL clock and
switches CPU back to DFLL clock source.

Acked-by: Thierry Reding <treding@nvidia.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>

authored by

Sowjanya Komatineni and committed by
Thierry Reding
0fb438ee 54ecb8f7

+59
+59
drivers/cpufreq/tegra124-cpufreq.c
··· 6 6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 7 7 8 8 #include <linux/clk.h> 9 + #include <linux/cpufreq.h> 9 10 #include <linux/err.h> 10 11 #include <linux/init.h> 11 12 #include <linux/kernel.h> ··· 129 128 return ret; 130 129 } 131 130 131 + static int __maybe_unused tegra124_cpufreq_suspend(struct device *dev) 132 + { 133 + struct tegra124_cpufreq_priv *priv = dev_get_drvdata(dev); 134 + int err; 135 + 136 + /* 137 + * PLLP rate 408Mhz is below the CPU Fmax at Vmin and is safe to 138 + * use during suspend and resume. So, switch the CPU clock source 139 + * to PLLP and disable DFLL. 140 + */ 141 + err = clk_set_parent(priv->cpu_clk, priv->pllp_clk); 142 + if (err < 0) { 143 + dev_err(dev, "failed to reparent to PLLP: %d\n", err); 144 + return err; 145 + } 146 + 147 + clk_disable_unprepare(priv->dfll_clk); 148 + 149 + return 0; 150 + } 151 + 152 + static int __maybe_unused tegra124_cpufreq_resume(struct device *dev) 153 + { 154 + struct tegra124_cpufreq_priv *priv = dev_get_drvdata(dev); 155 + int err; 156 + 157 + /* 158 + * Warmboot code powers up the CPU with PLLP clock source. 159 + * Enable DFLL clock and switch CPU clock source back to DFLL. 160 + */ 161 + err = clk_prepare_enable(priv->dfll_clk); 162 + if (err < 0) { 163 + dev_err(dev, "failed to enable DFLL clock for CPU: %d\n", err); 164 + goto disable_cpufreq; 165 + } 166 + 167 + err = clk_set_parent(priv->cpu_clk, priv->dfll_clk); 168 + if (err < 0) { 169 + dev_err(dev, "failed to reparent to DFLL clock: %d\n", err); 170 + goto disable_dfll; 171 + } 172 + 173 + return 0; 174 + 175 + disable_dfll: 176 + clk_disable_unprepare(priv->dfll_clk); 177 + disable_cpufreq: 178 + disable_cpufreq(); 179 + 180 + return err; 181 + } 182 + 183 + static const struct dev_pm_ops tegra124_cpufreq_pm_ops = { 184 + SET_SYSTEM_SLEEP_PM_OPS(tegra124_cpufreq_suspend, 185 + tegra124_cpufreq_resume) 186 + }; 187 + 132 188 static struct platform_driver tegra124_cpufreq_platdrv = { 133 189 .driver.name = "cpufreq-tegra124", 190 + .driver.pm = &tegra124_cpufreq_pm_ops, 134 191 .probe = tegra124_cpufreq_probe, 135 192 }; 136 193