vireshk

Untitled

Jun 14th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2016 Linaro.
  3. * Viresh Kumar <[email protected]>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9.  
  10. #include <linux/cpu.h>
  11. #include <linux/pm_domain.h>
  12. #include <linux/slab.h>
  13.  
  14. static int pd_power_on(struct generic_pm_domain *domain)
  15. {
  16. pr_info("%s: %d\n", __func__, __LINE__);
  17. return 0;
  18. }
  19.  
  20. static int pd_power_off(struct generic_pm_domain *domain)
  21. {
  22. pr_info("%s: %d\n", __func__, __LINE__);
  23. return 0;
  24. }
  25.  
  26. int pd_get_performance(struct device *dev, unsigned long rate)
  27. {
  28. struct device *cdev = get_cpu_device(0);
  29. WARN_ON(!rate);
  30. WARN_ON(cdev != dev);
  31.  
  32. dev_info(dev, "%s: freq: %lu\n", __func__, rate);
  33.  
  34. if (rate <= 500000000)
  35. return 1;
  36. else if (rate <= 500000000)
  37. return 2;
  38. else if (rate <= 900000000)
  39. return 3;
  40. else if (rate <= 1200000000)
  41. return 4;
  42. else if (rate <= 1600000000)
  43. return 5;
  44. else
  45. return 6;
  46. }
  47.  
  48. static int pd_set_performance(struct generic_pm_domain *domain, unsigned int state)
  49. {
  50. pr_info("%s: %d: %d\n", __func__, __LINE__, state);
  51. return 0;
  52. }
  53.  
  54. static const struct of_device_id pm_domain_of_match[] __initconst = {
  55. {
  56. .compatible = "foo,genpd",
  57. },
  58. { },
  59. };
  60.  
  61. static int __init add_domains(void)
  62. {
  63. struct device_node *np;
  64. struct generic_pm_domain *pd;
  65.  
  66. for_each_matching_node_and_match(np, pm_domain_of_match, NULL) {
  67. pd = kzalloc(sizeof(*pd), GFP_KERNEL);
  68. if (!pd)
  69. return -ENOMEM;
  70.  
  71. pd->name = kstrdup_const(strrchr(np->full_name, '/') + 1,
  72. GFP_KERNEL);
  73. if (!pd->name) {
  74. of_node_put(np);
  75. return -1;
  76. }
  77.  
  78. pd->power_off = pd_power_off;
  79. pd->power_on = pd_power_on;
  80.  
  81. if (of_find_property(np, "power-domains", NULL))
  82. pd->get_performance_state = pd_get_performance;
  83. else
  84. pd->set_performance_state = pd_set_performance;
  85.  
  86. pm_genpd_init(pd, NULL, false);
  87. of_genpd_add_provider_simple(np, pd);
  88.  
  89. pr_info("%s: %d: %p\n", __func__, __LINE__, pd);
  90. }
  91.  
  92. return 0;
  93. }
  94.  
  95. static int __init add_subdomains(void)
  96. {
  97. struct device_node *np;
  98.  
  99. for_each_matching_node_and_match(np, pm_domain_of_match, NULL) {
  100. struct of_phandle_args child, parent1, parent2;
  101.  
  102. if (of_parse_phandle_with_args(np, "power-domains",
  103. "#power-domain-cells", 0,
  104. &parent1) ||
  105. of_parse_phandle_with_args(np, "power-domains",
  106. "#power-domain-cells", 1,
  107. &parent2))
  108. continue;
  109.  
  110. child.np = np;
  111. child.args_count = 0;
  112.  
  113. if (of_genpd_add_subdomain(&parent1, &child) ||
  114. of_genpd_add_subdomain(&parent2, &child))
  115. pr_warn("%s failed to add subdomain: %s\n",
  116. parent1.np->full_name, child.np->full_name);
  117. else
  118. pr_info("%s has as child subdomain: %s.\n",
  119. parent1.np->full_name, child.np->full_name);
  120. }
  121.  
  122. return 0;
  123. }
  124.  
  125. static int __init genpd_test_init(void)
  126. {
  127. struct device *dev = get_cpu_device(0);
  128.  
  129. if (add_domains()) {
  130. pr_info("%s: %d\n", __func__, __LINE__);
  131. return -ENOMEM;
  132. }
  133.  
  134. if (add_subdomains()) {
  135. pr_info("%s: %d\n", __func__, __LINE__);
  136. return -ENOMEM;
  137. }
  138.  
  139. return dev_pm_domain_attach(dev, false);
  140. }
  141. device_initcall(genpd_test_init);
Add Comment
Please, Sign In to add comment