tegra20-cpufreq.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  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
  8. */
  9. #include <linux/bits.h>
  10. #include <linux/cpu.h>
  11. #include <linux/err.h>
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/of_device.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pm_opp.h>
  17. #include <linux/types.h>
  18. #include <soc/tegra/common.h>
  19. #include <soc/tegra/fuse.h>
  20. static bool cpu0_node_has_opp_v2_prop(void)
  21. {
  22. struct device_node *np = of_cpu_device_node_get(0);
  23. bool ret = false;
  24. if (of_get_property(np, "operating-points-v2", NULL))
  25. ret = true;
  26. of_node_put(np);
  27. return ret;
  28. }
  29. static int tegra20_cpufreq_probe(struct platform_device *pdev)
  30. {
  31. struct platform_device *cpufreq_dt;
  32. struct opp_table *opp_table;
  33. struct device *cpu_dev;
  34. u32 versions[2];
  35. int err;
  36. if (!cpu0_node_has_opp_v2_prop()) {
  37. dev_err(&pdev->dev, "operating points not found\n");
  38. dev_err(&pdev->dev, "please update your device tree\n");
  39. return -ENODEV;
  40. }
  41. if (of_machine_is_compatible("nvidia,tegra20")) {
  42. versions[0] = BIT(tegra_sku_info.cpu_process_id);
  43. versions[1] = BIT(tegra_sku_info.soc_speedo_id);
  44. } else {
  45. versions[0] = BIT(tegra_sku_info.cpu_process_id);
  46. versions[1] = BIT(tegra_sku_info.cpu_speedo_id);
  47. }
  48. dev_info(&pdev->dev, "hardware version 0x%x 0x%x\n",
  49. versions[0], versions[1]);
  50. cpu_dev = get_cpu_device(0);
  51. if (WARN_ON(!cpu_dev))
  52. return -ENODEV;
  53. opp_table = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2);
  54. err = PTR_ERR_OR_ZERO(opp_table);
  55. if (err) {
  56. dev_err(&pdev->dev, "failed to set supported hw: %d\n", err);
  57. return err;
  58. }
  59. cpufreq_dt = platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
  60. err = PTR_ERR_OR_ZERO(cpufreq_dt);
  61. if (err) {
  62. dev_err(&pdev->dev,
  63. "failed to create cpufreq-dt device: %d\n", err);
  64. goto err_put_supported_hw;
  65. }
  66. platform_set_drvdata(pdev, cpufreq_dt);
  67. return 0;
  68. err_put_supported_hw:
  69. dev_pm_opp_put_supported_hw(opp_table);
  70. return err;
  71. }
  72. static int tegra20_cpufreq_remove(struct platform_device *pdev)
  73. {
  74. struct platform_device *cpufreq_dt;
  75. struct opp_table *opp_table;
  76. cpufreq_dt = platform_get_drvdata(pdev);
  77. platform_device_unregister(cpufreq_dt);
  78. opp_table = dev_pm_opp_get_opp_table(get_cpu_device(0));
  79. dev_pm_opp_put_supported_hw(opp_table);
  80. dev_pm_opp_put_opp_table(opp_table);
  81. return 0;
  82. }
  83. static struct platform_driver tegra20_cpufreq_driver = {
  84. .probe = tegra20_cpufreq_probe,
  85. .remove = tegra20_cpufreq_remove,
  86. .driver = {
  87. .name = "tegra20-cpufreq",
  88. },
  89. };
  90. module_platform_driver(tegra20_cpufreq_driver);
  91. MODULE_ALIAS("platform:tegra20-cpufreq");
  92. MODULE_AUTHOR("Colin Cross <ccross@android.com>");
  93. MODULE_DESCRIPTION("NVIDIA Tegra20 cpufreq driver");
  94. MODULE_LICENSE("GPL");