arm_big_little_dt.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/cpufreq.h>
  21. #include <linux/device.h>
  22. #include <linux/export.h>
  23. #include <linux/module.h>
  24. #include <linux/of_device.h>
  25. #include <linux/pm_opp.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/slab.h>
  28. #include <linux/types.h>
  29. #include "arm_big_little.h"
  30. /* get cpu node with valid operating-points */
  31. static struct device_node *get_cpu_node_with_valid_op(int cpu)
  32. {
  33. struct device_node *np = of_cpu_device_node_get(cpu);
  34. if (!of_get_property(np, "operating-points", NULL)) {
  35. of_node_put(np);
  36. np = NULL;
  37. }
  38. return np;
  39. }
  40. static int dt_get_transition_latency(struct device *cpu_dev)
  41. {
  42. struct device_node *np;
  43. u32 transition_latency = CPUFREQ_ETERNAL;
  44. np = of_node_get(cpu_dev->of_node);
  45. if (!np) {
  46. pr_info("Failed to find cpu node. Use CPUFREQ_ETERNAL transition latency\n");
  47. return CPUFREQ_ETERNAL;
  48. }
  49. of_property_read_u32(np, "clock-latency", &transition_latency);
  50. of_node_put(np);
  51. pr_debug("%s: clock-latency: %d\n", __func__, transition_latency);
  52. return transition_latency;
  53. }
  54. static struct cpufreq_arm_bL_ops dt_bL_ops = {
  55. .name = "dt-bl",
  56. .get_transition_latency = dt_get_transition_latency,
  57. .init_opp_table = dev_pm_opp_of_cpumask_add_table,
  58. .free_opp_table = dev_pm_opp_of_cpumask_remove_table,
  59. };
  60. static int generic_bL_probe(struct platform_device *pdev)
  61. {
  62. struct device_node *np;
  63. np = get_cpu_node_with_valid_op(0);
  64. if (!np)
  65. return -ENODEV;
  66. of_node_put(np);
  67. return bL_cpufreq_register(&dt_bL_ops);
  68. }
  69. static int generic_bL_remove(struct platform_device *pdev)
  70. {
  71. bL_cpufreq_unregister(&dt_bL_ops);
  72. return 0;
  73. }
  74. static struct platform_driver generic_bL_platdrv = {
  75. .driver = {
  76. .name = "arm-bL-cpufreq-dt",
  77. },
  78. .probe = generic_bL_probe,
  79. .remove = generic_bL_remove,
  80. };
  81. module_platform_driver(generic_bL_platdrv);
  82. MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>");
  83. MODULE_DESCRIPTION("Generic ARM big LITTLE cpufreq driver via DT");
  84. MODULE_LICENSE("GPL v2");