arm_big_little_dt.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Generic big.LITTLE CPUFreq Interface driver
  3. *
  4. * It provides necessary ops to arm_big_little cpufreq driver and gets
  5. * Frequency information from Device Tree. Freq table in DT must be in KHz.
  6. *
  7. * Copyright (C) 2013 Linaro.
  8. * Viresh Kumar <viresh.kumar@linaro.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  15. * kind, whether express or implied; without even the implied warranty
  16. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/cpu.h>
  21. #include <linux/cpufreq.h>
  22. #include <linux/device.h>
  23. #include <linux/export.h>
  24. #include <linux/module.h>
  25. #include <linux/of.h>
  26. #include <linux/opp.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/slab.h>
  29. #include <linux/types.h>
  30. #include "arm_big_little.h"
  31. /* get cpu node with valid operating-points */
  32. static struct device_node *get_cpu_node_with_valid_op(int cpu)
  33. {
  34. struct device_node *np = NULL, *parent;
  35. int count = 0;
  36. parent = of_find_node_by_path("/cpus");
  37. if (!parent) {
  38. pr_err("failed to find OF /cpus\n");
  39. return NULL;
  40. }
  41. for_each_child_of_node(parent, np) {
  42. if (count++ != cpu)
  43. continue;
  44. if (!of_get_property(np, "operating-points", NULL)) {
  45. of_node_put(np);
  46. np = NULL;
  47. }
  48. break;
  49. }
  50. of_node_put(parent);
  51. return np;
  52. }
  53. static int dt_init_opp_table(struct device *cpu_dev)
  54. {
  55. struct device_node *np;
  56. int ret;
  57. np = get_cpu_node_with_valid_op(cpu_dev->id);
  58. if (!np)
  59. return -ENODATA;
  60. cpu_dev->of_node = np;
  61. ret = of_init_opp_table(cpu_dev);
  62. of_node_put(np);
  63. return ret;
  64. }
  65. static int dt_get_transition_latency(struct device *cpu_dev)
  66. {
  67. struct device_node *np;
  68. u32 transition_latency = CPUFREQ_ETERNAL;
  69. np = get_cpu_node_with_valid_op(cpu_dev->id);
  70. if (!np)
  71. return CPUFREQ_ETERNAL;
  72. of_property_read_u32(np, "clock-latency", &transition_latency);
  73. of_node_put(np);
  74. pr_debug("%s: clock-latency: %d\n", __func__, transition_latency);
  75. return transition_latency;
  76. }
  77. static struct cpufreq_arm_bL_ops dt_bL_ops = {
  78. .name = "dt-bl",
  79. .get_transition_latency = dt_get_transition_latency,
  80. .init_opp_table = dt_init_opp_table,
  81. };
  82. static int generic_bL_probe(struct platform_device *pdev)
  83. {
  84. struct device_node *np;
  85. np = get_cpu_node_with_valid_op(0);
  86. if (!np)
  87. return -ENODEV;
  88. of_node_put(np);
  89. return bL_cpufreq_register(&dt_bL_ops);
  90. }
  91. static int generic_bL_remove(struct platform_device *pdev)
  92. {
  93. bL_cpufreq_unregister(&dt_bL_ops);
  94. return 0;
  95. }
  96. static struct platform_driver generic_bL_platdrv = {
  97. .driver = {
  98. .name = "arm-bL-cpufreq-dt",
  99. .owner = THIS_MODULE,
  100. },
  101. .probe = generic_bL_probe,
  102. .remove = generic_bL_remove,
  103. };
  104. module_platform_driver(generic_bL_platdrv);
  105. MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>");
  106. MODULE_DESCRIPTION("Generic ARM big LITTLE cpufreq driver via DT");
  107. MODULE_LICENSE("GPL");