1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2010 Google, Inc.
6 * Colin Cross <ccross@google.com>
7 * Based on arch/arm/plat-omap/cpu-omap.c, (C) 2005 Nokia Corporation
10 #include <linux/bits.h>
11 #include <linux/cpu.h>
12 #include <linux/err.h>
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/of_device.h>
16 #include <linux/platform_device.h>
17 #include <linux/pm_opp.h>
18 #include <linux/types.h>
20 #include <soc/tegra/common.h>
21 #include <soc/tegra/fuse.h>
23 static bool cpu0_node_has_opp_v2_prop(void)
25 struct device_node *np = of_cpu_device_node_get(0);
28 if (of_get_property(np, "operating-points-v2", NULL))
35 static void tegra20_cpufreq_put_supported_hw(void *opp_table)
37 dev_pm_opp_put_supported_hw(opp_table);
40 static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt)
42 platform_device_unregister(cpufreq_dt);
45 static int tegra20_cpufreq_probe(struct platform_device *pdev)
47 struct platform_device *cpufreq_dt;
48 struct opp_table *opp_table;
49 struct device *cpu_dev;
53 if (!cpu0_node_has_opp_v2_prop()) {
54 dev_err(&pdev->dev, "operating points not found\n");
55 dev_err(&pdev->dev, "please update your device tree\n");
59 if (of_machine_is_compatible("nvidia,tegra20")) {
60 versions[0] = BIT(tegra_sku_info.cpu_process_id);
61 versions[1] = BIT(tegra_sku_info.soc_speedo_id);
63 versions[0] = BIT(tegra_sku_info.cpu_process_id);
64 versions[1] = BIT(tegra_sku_info.cpu_speedo_id);
67 dev_info(&pdev->dev, "hardware version 0x%x 0x%x\n",
68 versions[0], versions[1]);
70 cpu_dev = get_cpu_device(0);
71 if (WARN_ON(!cpu_dev))
74 opp_table = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2);
75 err = PTR_ERR_OR_ZERO(opp_table);
77 dev_err(&pdev->dev, "failed to set supported hw: %d\n", err);
81 err = devm_add_action_or_reset(&pdev->dev,
82 tegra20_cpufreq_put_supported_hw,
87 cpufreq_dt = platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
88 err = PTR_ERR_OR_ZERO(cpufreq_dt);
91 "failed to create cpufreq-dt device: %d\n", err);
95 err = devm_add_action_or_reset(&pdev->dev,
96 tegra20_cpufreq_dt_unregister,
104 static struct platform_driver tegra20_cpufreq_driver = {
105 .probe = tegra20_cpufreq_probe,
107 .name = "tegra20-cpufreq",
110 module_platform_driver(tegra20_cpufreq_driver);
112 MODULE_ALIAS("platform:tegra20-cpufreq");
113 MODULE_AUTHOR("Colin Cross <ccross@android.com>");
114 MODULE_DESCRIPTION("NVIDIA Tegra20 cpufreq driver");
115 MODULE_LICENSE("GPL");