arm_big_little_dt.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.h>
  25. #include <linux/opp.h>
  26. #include <linux/slab.h>
  27. #include <linux/types.h>
  28. #include "arm_big_little.h"
  29. static int dt_init_opp_table(struct device *cpu_dev)
  30. {
  31. struct device_node *np = NULL;
  32. int count = 0, ret;
  33. for_each_child_of_node(of_find_node_by_path("/cpus"), np) {
  34. if (count++ != cpu_dev->id)
  35. continue;
  36. if (!of_get_property(np, "operating-points", NULL))
  37. return -ENODATA;
  38. cpu_dev->of_node = np;
  39. ret = of_init_opp_table(cpu_dev);
  40. if (ret)
  41. return ret;
  42. return 0;
  43. }
  44. return -ENODEV;
  45. }
  46. static int dt_get_transition_latency(struct device *cpu_dev)
  47. {
  48. struct device_node *np = NULL;
  49. u32 transition_latency = CPUFREQ_ETERNAL;
  50. int count = 0;
  51. for_each_child_of_node(of_find_node_by_path("/cpus"), np) {
  52. if (count++ != cpu_dev->id)
  53. continue;
  54. of_property_read_u32(np, "clock-latency", &transition_latency);
  55. return 0;
  56. }
  57. return -ENODEV;
  58. }
  59. static struct cpufreq_arm_bL_ops dt_bL_ops = {
  60. .name = "dt-bl",
  61. .get_transition_latency = dt_get_transition_latency,
  62. .init_opp_table = dt_init_opp_table,
  63. };
  64. static int generic_bL_init(void)
  65. {
  66. return bL_cpufreq_register(&dt_bL_ops);
  67. }
  68. module_init(generic_bL_init);
  69. static void generic_bL_exit(void)
  70. {
  71. return bL_cpufreq_unregister(&dt_bL_ops);
  72. }
  73. module_exit(generic_bL_exit);
  74. MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>");
  75. MODULE_DESCRIPTION("Generic ARM big LITTLE cpufreq driver via DT");
  76. MODULE_LICENSE("GPL");