Skip to content

Commit 0ae9338

Browse files
webgeek1234vireshk
authored andcommitted
cpufreq: tegra124: Allow building as a module
This requires four changes: * Using the cpufreq-dt register helper to establish a hard dependency for depmod to track * Adding a remove routine to remove the cpufreq-dt device * Adding a exit routine to handle cleaning up the driver * Populating module license Signed-off-by: Aaron Kling <webgeek1234@gmail.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent d812734 commit 0ae9338

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

drivers/cpufreq/Kconfig.arm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ config ARM_TEGRA20_CPUFREQ
237237
This adds the CPUFreq driver support for Tegra20/30 SOCs.
238238

239239
config ARM_TEGRA124_CPUFREQ
240-
bool "Tegra124 CPUFreq support"
240+
tristate "Tegra124 CPUFreq support"
241241
depends on ARCH_TEGRA || COMPILE_TEST
242242
depends on CPUFREQ_DT
243243
default ARCH_TEGRA

drivers/cpufreq/tegra124-cpufreq.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include <linux/pm_opp.h>
1717
#include <linux/types.h>
1818

19+
#include "cpufreq-dt.h"
20+
21+
static struct platform_device *tegra124_cpufreq_pdev;
22+
1923
struct tegra124_cpufreq_priv {
2024
struct clk *cpu_clk;
2125
struct clk *pllp_clk;
@@ -55,7 +59,6 @@ static int tegra124_cpufreq_probe(struct platform_device *pdev)
5559
struct device_node *np __free(device_node) = of_cpu_device_node_get(0);
5660
struct tegra124_cpufreq_priv *priv;
5761
struct device *cpu_dev;
58-
struct platform_device_info cpufreq_dt_devinfo = {};
5962
int ret;
6063

6164
if (!np)
@@ -95,11 +98,7 @@ static int tegra124_cpufreq_probe(struct platform_device *pdev)
9598
if (ret)
9699
goto out_put_pllp_clk;
97100

98-
cpufreq_dt_devinfo.name = "cpufreq-dt";
99-
cpufreq_dt_devinfo.parent = &pdev->dev;
100-
101-
priv->cpufreq_dt_pdev =
102-
platform_device_register_full(&cpufreq_dt_devinfo);
101+
priv->cpufreq_dt_pdev = cpufreq_dt_pdev_register(&pdev->dev);
103102
if (IS_ERR(priv->cpufreq_dt_pdev)) {
104103
ret = PTR_ERR(priv->cpufreq_dt_pdev);
105104
goto out_put_pllp_clk;
@@ -173,6 +172,21 @@ static int __maybe_unused tegra124_cpufreq_resume(struct device *dev)
173172
return err;
174173
}
175174

175+
static void tegra124_cpufreq_remove(struct platform_device *pdev)
176+
{
177+
struct tegra124_cpufreq_priv *priv = dev_get_drvdata(&pdev->dev);
178+
179+
if (!IS_ERR(priv->cpufreq_dt_pdev)) {
180+
platform_device_unregister(priv->cpufreq_dt_pdev);
181+
priv->cpufreq_dt_pdev = ERR_PTR(-ENODEV);
182+
}
183+
184+
clk_put(priv->pllp_clk);
185+
clk_put(priv->pllx_clk);
186+
clk_put(priv->dfll_clk);
187+
clk_put(priv->cpu_clk);
188+
}
189+
176190
static const struct dev_pm_ops tegra124_cpufreq_pm_ops = {
177191
SET_SYSTEM_SLEEP_PM_OPS(tegra124_cpufreq_suspend,
178192
tegra124_cpufreq_resume)
@@ -182,12 +196,12 @@ static struct platform_driver tegra124_cpufreq_platdrv = {
182196
.driver.name = "cpufreq-tegra124",
183197
.driver.pm = &tegra124_cpufreq_pm_ops,
184198
.probe = tegra124_cpufreq_probe,
199+
.remove = tegra124_cpufreq_remove,
185200
};
186201

187202
static int __init tegra_cpufreq_init(void)
188203
{
189204
int ret;
190-
struct platform_device *pdev;
191205

192206
if (!(of_machine_is_compatible("nvidia,tegra124") ||
193207
of_machine_is_compatible("nvidia,tegra210")))
@@ -201,15 +215,25 @@ static int __init tegra_cpufreq_init(void)
201215
if (ret)
202216
return ret;
203217

204-
pdev = platform_device_register_simple("cpufreq-tegra124", -1, NULL, 0);
205-
if (IS_ERR(pdev)) {
218+
tegra124_cpufreq_pdev = platform_device_register_simple("cpufreq-tegra124", -1, NULL, 0);
219+
if (IS_ERR(tegra124_cpufreq_pdev)) {
206220
platform_driver_unregister(&tegra124_cpufreq_platdrv);
207-
return PTR_ERR(pdev);
221+
return PTR_ERR(tegra124_cpufreq_pdev);
208222
}
209223

210224
return 0;
211225
}
212226
module_init(tegra_cpufreq_init);
213227

228+
static void __exit tegra_cpufreq_module_exit(void)
229+
{
230+
if (!IS_ERR_OR_NULL(tegra124_cpufreq_pdev))
231+
platform_device_unregister(tegra124_cpufreq_pdev);
232+
233+
platform_driver_unregister(&tegra124_cpufreq_platdrv);
234+
}
235+
module_exit(tegra_cpufreq_module_exit);
236+
214237
MODULE_AUTHOR("Tuomas Tynkkynen <ttynkkynen@nvidia.com>");
215238
MODULE_DESCRIPTION("cpufreq driver for NVIDIA Tegra124");
239+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)