scpi-cpufreq.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * System Control and Power Interface (SCPI) based CPUFreq Interface driver
  3. *
  4. * It provides necessary ops to arm_big_little cpufreq driver.
  5. *
  6. * Copyright (C) 2015 ARM Ltd.
  7. * Sudeep Holla <sudeep.holla@arm.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/cpufreq.h>
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/pm_opp.h>
  23. #include <linux/scpi_protocol.h>
  24. #include <linux/types.h>
  25. #include "arm_big_little.h"
  26. static struct scpi_ops *scpi_ops;
  27. static struct scpi_dvfs_info *scpi_get_dvfs_info(struct device *cpu_dev)
  28. {
  29. int domain = topology_physical_package_id(cpu_dev->id);
  30. if (domain < 0)
  31. return ERR_PTR(-EINVAL);
  32. return scpi_ops->dvfs_get_info(domain);
  33. }
  34. static int scpi_opp_table_ops(struct device *cpu_dev, bool remove)
  35. {
  36. int idx, ret = 0;
  37. struct scpi_opp *opp;
  38. struct scpi_dvfs_info *info = scpi_get_dvfs_info(cpu_dev);
  39. if (IS_ERR(info))
  40. return PTR_ERR(info);
  41. if (!info->opps)
  42. return -EIO;
  43. for (opp = info->opps, idx = 0; idx < info->count; idx++, opp++) {
  44. if (remove)
  45. dev_pm_opp_remove(cpu_dev, opp->freq);
  46. else
  47. ret = dev_pm_opp_add(cpu_dev, opp->freq,
  48. opp->m_volt * 1000);
  49. if (ret) {
  50. dev_warn(cpu_dev, "failed to add opp %uHz %umV\n",
  51. opp->freq, opp->m_volt);
  52. while (idx-- > 0)
  53. dev_pm_opp_remove(cpu_dev, (--opp)->freq);
  54. return ret;
  55. }
  56. }
  57. return ret;
  58. }
  59. static int scpi_get_transition_latency(struct device *cpu_dev)
  60. {
  61. struct scpi_dvfs_info *info = scpi_get_dvfs_info(cpu_dev);
  62. if (IS_ERR(info))
  63. return PTR_ERR(info);
  64. return info->latency;
  65. }
  66. static int scpi_init_opp_table(struct device *cpu_dev)
  67. {
  68. return scpi_opp_table_ops(cpu_dev, false);
  69. }
  70. static void scpi_free_opp_table(struct device *cpu_dev)
  71. {
  72. scpi_opp_table_ops(cpu_dev, true);
  73. }
  74. static struct cpufreq_arm_bL_ops scpi_cpufreq_ops = {
  75. .name = "scpi",
  76. .get_transition_latency = scpi_get_transition_latency,
  77. .init_opp_table = scpi_init_opp_table,
  78. .free_opp_table = scpi_free_opp_table,
  79. };
  80. static int scpi_cpufreq_probe(struct platform_device *pdev)
  81. {
  82. scpi_ops = get_scpi_ops();
  83. if (!scpi_ops)
  84. return -EIO;
  85. return bL_cpufreq_register(&scpi_cpufreq_ops);
  86. }
  87. static int scpi_cpufreq_remove(struct platform_device *pdev)
  88. {
  89. bL_cpufreq_unregister(&scpi_cpufreq_ops);
  90. scpi_ops = NULL;
  91. return 0;
  92. }
  93. static struct platform_driver scpi_cpufreq_platdrv = {
  94. .driver = {
  95. .name = "scpi-cpufreq",
  96. .owner = THIS_MODULE,
  97. },
  98. .probe = scpi_cpufreq_probe,
  99. .remove = scpi_cpufreq_remove,
  100. };
  101. module_platform_driver(scpi_cpufreq_platdrv);
  102. MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
  103. MODULE_DESCRIPTION("ARM SCPI CPUFreq interface driver");
  104. MODULE_LICENSE("GPL v2");