Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM / devfreq: passive: Reduce duplicate code when passive_devfreq case

In order to keep the consistent coding style between passive_devfreq
and passive_cpufreq, use common code for handling required opp property.
Also remove the unneed conditional statement and unify the comment
of both passive_devfreq and passive_cpufreq when getting the target frequency.

Tested-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: Johnson Wang <johnson.wang@mediatek.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>

+8 -58
+8 -58
drivers/devfreq/governor_passive.c
··· 93 93 = (struct devfreq_passive_data *)devfreq->data; 94 94 struct devfreq *parent_devfreq = (struct devfreq *)p_data->parent; 95 95 unsigned long child_freq = ULONG_MAX; 96 - struct dev_pm_opp *opp, *p_opp; 97 96 int i, count; 98 97 99 - /* 100 - * If the devfreq device with passive governor has the specific method 101 - * to determine the next frequency, should use the get_target_freq() 102 - * of struct devfreq_passive_data. 103 - */ 104 - if (p_data->get_target_freq) 105 - return p_data->get_target_freq(devfreq, freq); 98 + /* Get target freq via required opps */ 99 + child_freq = get_target_freq_by_required_opp(parent_devfreq->dev.parent, 100 + parent_devfreq->opp_table, 101 + devfreq->opp_table, freq); 102 + if (child_freq) 103 + goto out; 106 104 107 - /* 108 - * If the parent and passive devfreq device uses the OPP table, 109 - * get the next frequency by using the OPP table. 110 - */ 111 - 112 - /* 113 - * - parent devfreq device uses the governors except for passive. 114 - * - passive devfreq device uses the passive governor. 115 - * 116 - * Each devfreq has the OPP table. After deciding the new frequency 117 - * from the governor of parent devfreq device, the passive governor 118 - * need to get the index of new frequency on OPP table of parent 119 - * device. And then the index is used for getting the suitable 120 - * new frequency for passive devfreq device. 121 - */ 122 - if (!devfreq->profile || !devfreq->profile->freq_table 123 - || devfreq->profile->max_state <= 0) 124 - return -EINVAL; 125 - 126 - /* 127 - * The passive governor have to get the correct frequency from OPP 128 - * list of parent device. Because in this case, *freq is temporary 129 - * value which is decided by ondemand governor. 130 - */ 131 - if (devfreq->opp_table && parent_devfreq->opp_table) { 132 - p_opp = devfreq_recommended_opp(parent_devfreq->dev.parent, 133 - freq, 0); 134 - if (IS_ERR(p_opp)) 135 - return PTR_ERR(p_opp); 136 - 137 - opp = dev_pm_opp_xlate_required_opp(parent_devfreq->opp_table, 138 - devfreq->opp_table, p_opp); 139 - dev_pm_opp_put(p_opp); 140 - 141 - if (IS_ERR(opp)) 142 - goto no_required_opp; 143 - 144 - *freq = dev_pm_opp_get_freq(opp); 145 - dev_pm_opp_put(opp); 146 - 147 - return 0; 148 - } 149 - 150 - no_required_opp: 151 - /* 152 - * Get the OPP table's index of decided frequency by governor 153 - * of parent device. 154 - */ 105 + /* Use interpolation if required opps is not available */ 155 106 for (i = 0; i < parent_devfreq->profile->max_state; i++) 156 107 if (parent_devfreq->profile->freq_table[i] == *freq) 157 108 break; ··· 110 159 if (i == parent_devfreq->profile->max_state) 111 160 return -EINVAL; 112 161 113 - /* Get the suitable frequency by using index of parent device. */ 114 162 if (i < devfreq->profile->max_state) { 115 163 child_freq = devfreq->profile->freq_table[i]; 116 164 } else { ··· 117 167 child_freq = devfreq->profile->freq_table[count - 1]; 118 168 } 119 169 120 - /* Return the suitable frequency for passive device. */ 170 + out: 121 171 *freq = child_freq; 122 172 123 173 return 0;