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