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

memory: tegra: Rework update_clock_tree_delay()

Further streamline this function by moving the delay post-processing
to the callers, leaving it only with the task of returning the measured
delay values.

Signed-off-by: Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt>
Link: https://lore.kernel.org/r/20240704-tegra210_emcfreq-v4-7-3e450503c555@tecnico.ulisboa.pt
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

authored by

Diogo Ivo and committed by
Krzysztof Kozlowski
ddb869ea b109656e

+48 -74
+48 -74
drivers/memory/tegra/tegra210-emc-cc-r21021.c
··· 105 105 next->ptfv_list[w])) / \ 106 106 (next->ptfv_list[w] + 1); \ 107 107 \ 108 - emc_dbg(emc, EMA_UPDATES, "%s: (s=%lu) EMA: %u\n", \ 108 + emc_dbg(emc, EMA_UPDATES, "%s: (s=%u) EMA: %u\n", \ 109 109 __stringify(dev), nval, next->ptfv_list[dqs]); \ 110 110 } while (0) 111 111 ··· 130 130 return false; 131 131 } 132 132 133 - static bool update_clock_tree_delay(struct tegra210_emc *emc, int type) 133 + static void tegra210_emc_get_clktree_delay(struct tegra210_emc *emc, 134 + u32 delay[DRAM_CLKTREE_NUM]) 134 135 { 135 - bool periodic_training_update = type == PERIODIC_TRAINING_UPDATE; 136 - struct tegra210_emc_timing *last = emc->last; 137 - struct tegra210_emc_timing *next = emc->next; 138 - u32 last_timing_rate_mhz = last->rate / 1000; 139 - bool dvfs_update = type == DVFS_UPDATE; 140 - bool dvfs_pt1 = type == DVFS_PT1; 141 - u32 temp[2][2], value, delay_us; 142 - unsigned long cval = 0; 136 + struct tegra210_emc_timing *curr = emc->last; 137 + u32 rate_mhz = curr->rate / 1000; 138 + u32 msb, lsb, dqsosc, delay_us; 143 139 unsigned int c, d, idx; 144 - bool over = false; 140 + unsigned long clocks; 145 141 146 - if (dvfs_pt1 || periodic_training_update) { 147 - delay_us = tegra210_emc_actual_osc_clocks(last->run_clocks); 148 - delay_us *= 1000; 149 - delay_us = 2 + (delay_us / last->rate); 142 + clocks = tegra210_emc_actual_osc_clocks(curr->run_clocks); 143 + delay_us = 2 + (clocks / rate_mhz); 150 144 151 - tegra210_emc_start_periodic_compensation(emc); 152 - udelay(delay_us); 153 - } 145 + tegra210_emc_start_periodic_compensation(emc); 146 + udelay(delay_us); 154 147 155 148 for (d = 0; d < emc->num_devices; d++) { 156 - if (dvfs_pt1 || periodic_training_update) { 157 - /* Dev[d] MSB */ 158 - value = tegra210_emc_mrr_read(emc, 2 - d, 19); 159 - 160 - for (c = 0; c < emc->num_channels; c++) { 161 - temp[c][0] = (value & 0x00ff) << 8; 162 - temp[c][1] = (value & 0xff00) << 0; 163 - value >>= 16; 164 - } 165 - 166 - /* Dev[d] LSB */ 167 - value = tegra210_emc_mrr_read(emc, 2 - d, 18); 168 - 169 - for (c = 0; c < emc->num_channels; c++) { 170 - temp[c][0] |= (value & 0x00ff) >> 0; 171 - temp[c][1] |= (value & 0xff00) >> 8; 172 - value >>= 16; 173 - } 174 - } 149 + /* Read DQSOSC from MRR18/19 */ 150 + msb = tegra210_emc_mrr_read(emc, 2 - d, 19); 151 + lsb = tegra210_emc_mrr_read(emc, 2 - d, 18); 175 152 176 153 for (c = 0; c < emc->num_channels; c++) { 177 154 /* C[c]D[d]U[0] */ 178 155 idx = c * 4 + d * 2; 179 156 180 - if (dvfs_pt1 || periodic_training_update) { 181 - cval = tegra210_emc_actual_osc_clocks(last->run_clocks); 182 - cval *= 1000000; 183 - cval /= last_timing_rate_mhz * 2 * temp[c][0]; 184 - } 157 + dqsosc = (msb & 0x00ff) << 8; 158 + dqsosc |= (lsb & 0x00ff) >> 0; 185 159 186 - if (dvfs_pt1) 187 - __INCREMENT_PTFV(idx, cval); 188 - else if (dvfs_update) 189 - __AVERAGE_PTFV(idx); 190 - else if (periodic_training_update) 191 - __WEIGHTED_UPDATE_PTFV(idx, cval); 192 - 193 - if (dvfs_update || periodic_training_update) 194 - over |= tegra210_emc_compare_update_delay(next, 195 - __MOVAVG_AC(next, idx), idx); 160 + /* Check for unpopulated channels */ 161 + if (dqsosc) 162 + delay[idx] = (clocks * 1000000) / 163 + (rate_mhz * 2 * dqsosc); 196 164 197 165 /* C[c]D[d]U[1] */ 198 166 idx++; 199 167 200 - if (dvfs_pt1 || periodic_training_update) { 201 - cval = tegra210_emc_actual_osc_clocks(last->run_clocks); 202 - cval *= 1000000; 203 - cval /= last_timing_rate_mhz * 2 * temp[c][1]; 204 - } 168 + dqsosc = (msb & 0xff00) << 0; 169 + dqsosc |= (lsb & 0xff00) >> 8; 205 170 206 - if (dvfs_pt1) 207 - __INCREMENT_PTFV(idx, cval); 208 - else if (dvfs_update) 209 - __AVERAGE_PTFV(idx); 210 - else if (periodic_training_update) 211 - __WEIGHTED_UPDATE_PTFV(idx, cval); 171 + /* Check for unpopulated channels */ 172 + if (dqsosc) 173 + delay[idx] = (clocks * 1000000) / 174 + (rate_mhz * 2 * dqsosc); 212 175 213 - if (dvfs_update || periodic_training_update) 214 - over |= tegra210_emc_compare_update_delay(next, 215 - __MOVAVG_AC(next, idx), idx); 176 + msb >>= 16; 177 + lsb >>= 16; 216 178 } 217 179 } 218 - 219 - return over; 220 180 } 221 181 222 182 static bool periodic_compensation_handler(struct tegra210_emc *emc, u32 type, ··· 188 228 (nt)->ptfv_list[PTFV_DVFS_SAMPLES_INDEX]; }) 189 229 190 230 u32 i, samples = next->ptfv_list[PTFV_DVFS_SAMPLES_INDEX]; 231 + u32 delay[DRAM_CLKTREE_NUM], idx; 191 232 bool over = false; 192 - u32 idx; 193 233 194 234 if (!next->periodic_training) 195 235 return 0; ··· 212 252 213 253 for (i = 0; i < samples; i++) { 214 254 /* Generate next sample of data. */ 215 - update_clock_tree_delay(emc, DVFS_PT1); 255 + tegra210_emc_get_clktree_delay(emc, delay); 256 + 257 + for (idx = 0; idx < DRAM_CLKTREE_NUM; idx++) 258 + __INCREMENT_PTFV(idx, delay[idx]); 216 259 } 217 260 } 218 261 219 - /* Do the division part of the moving average */ 220 - over = update_clock_tree_delay(emc, DVFS_UPDATE); 262 + for (idx = 0; idx < DRAM_CLKTREE_NUM; idx++) { 263 + /* Do the division part of the moving average */ 264 + __AVERAGE_PTFV(idx); 265 + over |= tegra210_emc_compare_update_delay(next, 266 + __MOVAVG_AC(next, idx), idx); 267 + } 221 268 } 222 269 223 - if (type == PERIODIC_TRAINING_SEQUENCE) 224 - over = update_clock_tree_delay(emc, PERIODIC_TRAINING_UPDATE); 270 + if (type == PERIODIC_TRAINING_SEQUENCE) { 271 + tegra210_emc_get_clktree_delay(emc, delay); 272 + 273 + for (idx = 0; idx < DRAM_CLKTREE_NUM; idx++) { 274 + __WEIGHTED_UPDATE_PTFV(idx, delay[idx]); 275 + over |= tegra210_emc_compare_update_delay(next, 276 + __MOVAVG_AC(next, idx), idx); 277 + } 278 + } 225 279 226 280 return over; 227 281 }