111-v5.19-03-PM-devfreq-passive-Reduce-duplicate-code-when-passiv.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. From 05723e71234b60a1a47313ea1a889797ec648f1c Mon Sep 17 00:00:00 2001
  2. From: Chanwoo Choi <[email protected]>
  3. Date: Tue, 2 Mar 2021 17:22:50 +0900
  4. Subject: [PATCH 3/5] PM / devfreq: passive: Reduce duplicate code when
  5. passive_devfreq case
  6. In order to keep the consistent coding style between passive_devfreq
  7. and passive_cpufreq, use common code for handling required opp property.
  8. Also remove the unneed conditional statement and unify the comment
  9. of both passive_devfreq and passive_cpufreq when getting the target frequency.
  10. Tested-by: Chen-Yu Tsai <[email protected]>
  11. Tested-by: Johnson Wang <[email protected]>
  12. Signed-off-by: Chanwoo Choi <[email protected]>
  13. ---
  14. drivers/devfreq/governor_passive.c | 66 ++++--------------------------
  15. 1 file changed, 8 insertions(+), 58 deletions(-)
  16. --- a/drivers/devfreq/governor_passive.c
  17. +++ b/drivers/devfreq/governor_passive.c
  18. @@ -93,65 +93,16 @@ static int get_target_freq_with_devfreq(
  19. = (struct devfreq_passive_data *)devfreq->data;
  20. struct devfreq *parent_devfreq = (struct devfreq *)p_data->parent;
  21. unsigned long child_freq = ULONG_MAX;
  22. - struct dev_pm_opp *opp, *p_opp;
  23. int i, count;
  24. - /*
  25. - * If the devfreq device with passive governor has the specific method
  26. - * to determine the next frequency, should use the get_target_freq()
  27. - * of struct devfreq_passive_data.
  28. - */
  29. - if (p_data->get_target_freq)
  30. - return p_data->get_target_freq(devfreq, freq);
  31. -
  32. - /*
  33. - * If the parent and passive devfreq device uses the OPP table,
  34. - * get the next frequency by using the OPP table.
  35. - */
  36. -
  37. - /*
  38. - * - parent devfreq device uses the governors except for passive.
  39. - * - passive devfreq device uses the passive governor.
  40. - *
  41. - * Each devfreq has the OPP table. After deciding the new frequency
  42. - * from the governor of parent devfreq device, the passive governor
  43. - * need to get the index of new frequency on OPP table of parent
  44. - * device. And then the index is used for getting the suitable
  45. - * new frequency for passive devfreq device.
  46. - */
  47. - if (!devfreq->profile || !devfreq->profile->freq_table
  48. - || devfreq->profile->max_state <= 0)
  49. - return -EINVAL;
  50. -
  51. - /*
  52. - * The passive governor have to get the correct frequency from OPP
  53. - * list of parent device. Because in this case, *freq is temporary
  54. - * value which is decided by ondemand governor.
  55. - */
  56. - if (devfreq->opp_table && parent_devfreq->opp_table) {
  57. - p_opp = devfreq_recommended_opp(parent_devfreq->dev.parent,
  58. - freq, 0);
  59. - if (IS_ERR(p_opp))
  60. - return PTR_ERR(p_opp);
  61. -
  62. - opp = dev_pm_opp_xlate_required_opp(parent_devfreq->opp_table,
  63. - devfreq->opp_table, p_opp);
  64. - dev_pm_opp_put(p_opp);
  65. -
  66. - if (IS_ERR(opp))
  67. - goto no_required_opp;
  68. -
  69. - *freq = dev_pm_opp_get_freq(opp);
  70. - dev_pm_opp_put(opp);
  71. -
  72. - return 0;
  73. - }
  74. + /* Get target freq via required opps */
  75. + child_freq = get_target_freq_by_required_opp(parent_devfreq->dev.parent,
  76. + parent_devfreq->opp_table,
  77. + devfreq->opp_table, freq);
  78. + if (child_freq)
  79. + goto out;
  80. -no_required_opp:
  81. - /*
  82. - * Get the OPP table's index of decided frequency by governor
  83. - * of parent device.
  84. - */
  85. + /* Use interpolation if required opps is not available */
  86. for (i = 0; i < parent_devfreq->profile->max_state; i++)
  87. if (parent_devfreq->profile->freq_table[i] == *freq)
  88. break;
  89. @@ -159,7 +110,6 @@ no_required_opp:
  90. if (i == parent_devfreq->profile->max_state)
  91. return -EINVAL;
  92. - /* Get the suitable frequency by using index of parent device. */
  93. if (i < devfreq->profile->max_state) {
  94. child_freq = devfreq->profile->freq_table[i];
  95. } else {
  96. @@ -167,7 +117,7 @@ no_required_opp:
  97. child_freq = devfreq->profile->freq_table[count - 1];
  98. }
  99. - /* Return the suitable frequency for passive device. */
  100. +out:
  101. *freq = child_freq;
  102. return 0;