scpi-cpufreq.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 int scpi_get_transition_latency(struct device *cpu_dev)
  29. {
  30. return scpi_ops->get_transition_latency(cpu_dev);
  31. }
  32. static int scpi_init_opp_table(const struct cpumask *cpumask)
  33. {
  34. int ret;
  35. struct device *cpu_dev = get_cpu_device(cpumask_first(cpumask));
  36. ret = scpi_ops->add_opps_to_device(cpu_dev);
  37. if (ret) {
  38. dev_warn(cpu_dev, "failed to add opps to the device\n");
  39. return ret;
  40. }
  41. ret = dev_pm_opp_set_sharing_cpus(cpu_dev, cpumask);
  42. if (ret)
  43. dev_err(cpu_dev, "%s: failed to mark OPPs as shared: %d\n",
  44. __func__, ret);
  45. return ret;
  46. }
  47. static struct cpufreq_arm_bL_ops scpi_cpufreq_ops = {
  48. .name = "scpi",
  49. .get_transition_latency = scpi_get_transition_latency,
  50. .init_opp_table = scpi_init_opp_table,
  51. .free_opp_table = dev_pm_opp_cpumask_remove_table,
  52. };
  53. static int scpi_cpufreq_probe(struct platform_device *pdev)
  54. {
  55. scpi_ops = get_scpi_ops();
  56. if (!scpi_ops)
  57. return -EIO;
  58. return bL_cpufreq_register(&scpi_cpufreq_ops);
  59. }
  60. static int scpi_cpufreq_remove(struct platform_device *pdev)
  61. {
  62. bL_cpufreq_unregister(&scpi_cpufreq_ops);
  63. scpi_ops = NULL;
  64. return 0;
  65. }
  66. static struct platform_driver scpi_cpufreq_platdrv = {
  67. .driver = {
  68. .name = "scpi-cpufreq",
  69. },
  70. .probe = scpi_cpufreq_probe,
  71. .remove = scpi_cpufreq_remove,
  72. };
  73. module_platform_driver(scpi_cpufreq_platdrv);
  74. MODULE_ALIAS("platform:scpi-cpufreq");
  75. MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
  76. MODULE_DESCRIPTION("ARM SCPI CPUFreq interface driver");
  77. MODULE_LICENSE("GPL v2");