Thomas Gleixner | 9c92ab6 | 2019-05-29 07:17:56 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 2 | /* |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 3 | * Copyright (C) 2010 Google, Inc. |
| 4 | * |
| 5 | * Author: |
| 6 | * Colin Cross <ccross@google.com> |
| 7 | * Based on arch/arm/plat-omap/cpu-omap.c, (C) 2005 Nokia Corporation |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 10 | #include <linux/bits.h> |
| 11 | #include <linux/cpu.h> |
Dmitry Osipenko | 9a25ba9 | 2018-05-18 23:06:34 +0300 | [diff] [blame] | 12 | #include <linux/err.h> |
| 13 | #include <linux/init.h> |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 15 | #include <linux/of_device.h> |
Dmitry Osipenko | dc628cd | 2018-05-18 23:06:42 +0300 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 17 | #include <linux/pm_opp.h> |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 18 | #include <linux/types.h> |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 19 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 20 | #include <soc/tegra/common.h> |
| 21 | #include <soc/tegra/fuse.h> |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 22 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 23 | static bool cpu0_node_has_opp_v2_prop(void) |
Viresh Kumar | 00917dd | 2014-06-02 22:49:29 +0530 | [diff] [blame] | 24 | { |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 25 | struct device_node *np = of_cpu_device_node_get(0); |
| 26 | bool ret = false; |
Viresh Kumar | 00917dd | 2014-06-02 22:49:29 +0530 | [diff] [blame] | 27 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 28 | if (of_get_property(np, "operating-points-v2", NULL)) |
| 29 | ret = true; |
Viresh Kumar | 00917dd | 2014-06-02 22:49:29 +0530 | [diff] [blame] | 30 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 31 | of_node_put(np); |
Stephen Warren | ce32dda | 2012-09-10 17:05:01 -0600 | [diff] [blame] | 32 | return ret; |
| 33 | } |
| 34 | |
Dmitry Osipenko | 763ec5d | 2021-01-18 02:18:25 +0300 | [diff] [blame] | 35 | static void tegra20_cpufreq_put_supported_hw(void *opp_table) |
| 36 | { |
| 37 | dev_pm_opp_put_supported_hw(opp_table); |
| 38 | } |
| 39 | |
| 40 | static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt) |
| 41 | { |
| 42 | platform_device_unregister(cpufreq_dt); |
| 43 | } |
| 44 | |
Dmitry Osipenko | dc628cd | 2018-05-18 23:06:42 +0300 | [diff] [blame] | 45 | static int tegra20_cpufreq_probe(struct platform_device *pdev) |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 46 | { |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 47 | struct platform_device *cpufreq_dt; |
| 48 | struct opp_table *opp_table; |
| 49 | struct device *cpu_dev; |
| 50 | u32 versions[2]; |
Dmitry Osipenko | 64cd64e | 2018-05-18 23:06:36 +0300 | [diff] [blame] | 51 | int err; |
| 52 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 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"); |
| 56 | return -ENODEV; |
Dmitry Osipenko | 64cd64e | 2018-05-18 23:06:36 +0300 | [diff] [blame] | 57 | } |
Richard Zhao | c26cefd | 2012-12-21 00:09:55 +0000 | [diff] [blame] | 58 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 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); |
| 62 | } else { |
| 63 | versions[0] = BIT(tegra_sku_info.cpu_process_id); |
| 64 | versions[1] = BIT(tegra_sku_info.cpu_speedo_id); |
Dmitry Osipenko | 64cd64e | 2018-05-18 23:06:36 +0300 | [diff] [blame] | 65 | } |
Richard Zhao | c26cefd | 2012-12-21 00:09:55 +0000 | [diff] [blame] | 66 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 67 | dev_info(&pdev->dev, "hardware version 0x%x 0x%x\n", |
| 68 | versions[0], versions[1]); |
Dmitry Osipenko | dc628cd | 2018-05-18 23:06:42 +0300 | [diff] [blame] | 69 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 70 | cpu_dev = get_cpu_device(0); |
| 71 | if (WARN_ON(!cpu_dev)) |
| 72 | return -ENODEV; |
Dmitry Osipenko | 64cd64e | 2018-05-18 23:06:36 +0300 | [diff] [blame] | 73 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 74 | opp_table = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2); |
| 75 | err = PTR_ERR_OR_ZERO(opp_table); |
| 76 | if (err) { |
| 77 | dev_err(&pdev->dev, "failed to set supported hw: %d\n", err); |
| 78 | return err; |
| 79 | } |
| 80 | |
Dmitry Osipenko | 763ec5d | 2021-01-18 02:18:25 +0300 | [diff] [blame] | 81 | err = devm_add_action_or_reset(&pdev->dev, |
| 82 | tegra20_cpufreq_put_supported_hw, |
| 83 | opp_table); |
| 84 | if (err) |
| 85 | return err; |
| 86 | |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 87 | cpufreq_dt = platform_device_register_simple("cpufreq-dt", -1, NULL, 0); |
| 88 | err = PTR_ERR_OR_ZERO(cpufreq_dt); |
| 89 | if (err) { |
| 90 | dev_err(&pdev->dev, |
| 91 | "failed to create cpufreq-dt device: %d\n", err); |
Dmitry Osipenko | 763ec5d | 2021-01-18 02:18:25 +0300 | [diff] [blame] | 92 | return err; |
Dmitry Osipenko | 9ce2746 | 2020-03-19 22:02:26 +0300 | [diff] [blame] | 93 | } |
| 94 | |
Dmitry Osipenko | 763ec5d | 2021-01-18 02:18:25 +0300 | [diff] [blame] | 95 | err = devm_add_action_or_reset(&pdev->dev, |
| 96 | tegra20_cpufreq_dt_unregister, |
| 97 | cpufreq_dt); |
| 98 | if (err) |
| 99 | return err; |
Dmitry Osipenko | dc628cd | 2018-05-18 23:06:42 +0300 | [diff] [blame] | 100 | |
| 101 | return 0; |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Dmitry Osipenko | dc628cd | 2018-05-18 23:06:42 +0300 | [diff] [blame] | 104 | static struct platform_driver tegra20_cpufreq_driver = { |
| 105 | .probe = tegra20_cpufreq_probe, |
Dmitry Osipenko | dc628cd | 2018-05-18 23:06:42 +0300 | [diff] [blame] | 106 | .driver = { |
| 107 | .name = "tegra20-cpufreq", |
| 108 | }, |
| 109 | }; |
| 110 | module_platform_driver(tegra20_cpufreq_driver); |
| 111 | |
| 112 | MODULE_ALIAS("platform:tegra20-cpufreq"); |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 113 | MODULE_AUTHOR("Colin Cross <ccross@android.com>"); |
Dmitry Osipenko | 4964027 | 2018-05-18 23:06:32 +0300 | [diff] [blame] | 114 | MODULE_DESCRIPTION("NVIDIA Tegra20 cpufreq driver"); |
Colin Cross | 7056d42 | 2010-04-22 20:30:13 -0700 | [diff] [blame] | 115 | MODULE_LICENSE("GPL"); |