scpi-cpufreq.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/cpu.h>
  20. #include <linux/cpufreq.h>
  21. #include <linux/module.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/pm_opp.h>
  24. #include <linux/scpi_protocol.h>
  25. #include <linux/types.h>
  26. #include "arm_big_little.h"
  27. static struct scpi_ops *scpi_ops;
  28. static struct scpi_dvfs_info *scpi_get_dvfs_info(struct device *cpu_dev)
  29. {
  30. int domain = topology_physical_package_id(cpu_dev->id);
  31. if (domain < 0)
  32. return ERR_PTR(-EINVAL);
  33. return scpi_ops->dvfs_get_info(domain);
  34. }
  35. static int scpi_get_transition_latency(struct device *cpu_dev)
  36. {
  37. struct scpi_dvfs_info *info = scpi_get_dvfs_info(cpu_dev);
  38. if (IS_ERR(info))
  39. return PTR_ERR(info);
  40. return info->latency;
  41. }
  42. static int scpi_init_opp_table(const struct cpumask *cpumask)
  43. {
  44. int idx, ret;
  45. struct scpi_opp *opp;
  46. struct device *cpu_dev = get_cpu_device(cpumask_first(cpumask));
  47. struct scpi_dvfs_info *info = scpi_get_dvfs_info(cpu_dev);
  48. if (IS_ERR(info))
  49. return PTR_ERR(info);
  50. if (!info->opps)
  51. return -EIO;
  52. for (opp = info->opps, idx = 0; idx < info->count; idx++, opp++) {
  53. ret = dev_pm_opp_add(cpu_dev, opp->freq, opp->m_volt * 1000);
  54. if (ret) {
  55. dev_warn(cpu_dev, "failed to add opp %uHz %umV\n",
  56. opp->freq, opp->m_volt);
  57. while (idx-- > 0)
  58. dev_pm_opp_remove(cpu_dev, (--opp)->freq);
  59. return ret;
  60. }
  61. }
  62. ret = dev_pm_opp_set_sharing_cpus(cpu_dev, cpumask);
  63. if (ret)
  64. dev_err(cpu_dev, "%s: failed to mark OPPs as shared: %d\n",
  65. __func__, ret);
  66. return ret;
  67. }
  68. static struct cpufreq_arm_bL_ops scpi_cpufreq_ops = {
  69. .name = "scpi",
  70. .get_transition_latency = scpi_get_transition_latency,
  71. .init_opp_table = scpi_init_opp_table,
  72. .free_opp_table = dev_pm_opp_cpumask_remove_table,
  73. };
  74. static int scpi_cpufreq_probe(struct platform_device *pdev)
  75. {
  76. scpi_ops = get_scpi_ops();
  77. if (!scpi_ops)
  78. return -EIO;
  79. return bL_cpufreq_register(&scpi_cpufreq_ops);
  80. }
  81. static int scpi_cpufreq_remove(struct platform_device *pdev)
  82. {
  83. bL_cpufreq_unregister(&scpi_cpufreq_ops);
  84. scpi_ops = NULL;
  85. return 0;
  86. }
  87. static struct platform_driver scpi_cpufreq_platdrv = {
  88. .driver = {
  89. .name = "scpi-cpufreq",
  90. },
  91. .probe = scpi_cpufreq_probe,
  92. .remove = scpi_cpufreq_remove,
  93. };
  94. module_platform_driver(scpi_cpufreq_platdrv);
  95. MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
  96. MODULE_DESCRIPTION("ARM SCPI CPUFreq interface driver");
  97. MODULE_LICENSE("GPL v2");