Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2010 Google, Inc.
0004  *
0005  * Author:
0006  *  Colin Cross <ccross@google.com>
0007  *  Based on arch/arm/plat-omap/cpu-omap.c, (C) 2005 Nokia Corporation
0008  */
0009 
0010 #include <linux/bits.h>
0011 #include <linux/cpu.h>
0012 #include <linux/err.h>
0013 #include <linux/init.h>
0014 #include <linux/module.h>
0015 #include <linux/of_device.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/pm_opp.h>
0018 #include <linux/types.h>
0019 
0020 #include <soc/tegra/common.h>
0021 #include <soc/tegra/fuse.h>
0022 
0023 static bool cpu0_node_has_opp_v2_prop(void)
0024 {
0025     struct device_node *np = of_cpu_device_node_get(0);
0026     bool ret = false;
0027 
0028     if (of_get_property(np, "operating-points-v2", NULL))
0029         ret = true;
0030 
0031     of_node_put(np);
0032     return ret;
0033 }
0034 
0035 static void tegra20_cpufreq_put_supported_hw(void *opp_token)
0036 {
0037     dev_pm_opp_put_supported_hw((unsigned long) opp_token);
0038 }
0039 
0040 static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt)
0041 {
0042     platform_device_unregister(cpufreq_dt);
0043 }
0044 
0045 static int tegra20_cpufreq_probe(struct platform_device *pdev)
0046 {
0047     struct platform_device *cpufreq_dt;
0048     struct device *cpu_dev;
0049     u32 versions[2];
0050     int err;
0051 
0052     if (!cpu0_node_has_opp_v2_prop()) {
0053         dev_err(&pdev->dev, "operating points not found\n");
0054         dev_err(&pdev->dev, "please update your device tree\n");
0055         return -ENODEV;
0056     }
0057 
0058     if (of_machine_is_compatible("nvidia,tegra20")) {
0059         versions[0] = BIT(tegra_sku_info.cpu_process_id);
0060         versions[1] = BIT(tegra_sku_info.soc_speedo_id);
0061     } else {
0062         versions[0] = BIT(tegra_sku_info.cpu_process_id);
0063         versions[1] = BIT(tegra_sku_info.cpu_speedo_id);
0064     }
0065 
0066     dev_info(&pdev->dev, "hardware version 0x%x 0x%x\n",
0067          versions[0], versions[1]);
0068 
0069     cpu_dev = get_cpu_device(0);
0070     if (WARN_ON(!cpu_dev))
0071         return -ENODEV;
0072 
0073     err = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2);
0074     if (err < 0) {
0075         dev_err(&pdev->dev, "failed to set supported hw: %d\n", err);
0076         return err;
0077     }
0078 
0079     err = devm_add_action_or_reset(&pdev->dev,
0080                        tegra20_cpufreq_put_supported_hw,
0081                        (void *)((unsigned long) err));
0082     if (err)
0083         return err;
0084 
0085     cpufreq_dt = platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
0086     err = PTR_ERR_OR_ZERO(cpufreq_dt);
0087     if (err) {
0088         dev_err(&pdev->dev,
0089             "failed to create cpufreq-dt device: %d\n", err);
0090         return err;
0091     }
0092 
0093     err = devm_add_action_or_reset(&pdev->dev,
0094                        tegra20_cpufreq_dt_unregister,
0095                        cpufreq_dt);
0096     if (err)
0097         return err;
0098 
0099     return 0;
0100 }
0101 
0102 static struct platform_driver tegra20_cpufreq_driver = {
0103     .probe      = tegra20_cpufreq_probe,
0104     .driver     = {
0105         .name   = "tegra20-cpufreq",
0106     },
0107 };
0108 module_platform_driver(tegra20_cpufreq_driver);
0109 
0110 MODULE_ALIAS("platform:tegra20-cpufreq");
0111 MODULE_AUTHOR("Colin Cross <ccross@android.com>");
0112 MODULE_DESCRIPTION("NVIDIA Tegra20 cpufreq driver");
0113 MODULE_LICENSE("GPL");