27 #include <linux/module.h>
58 if (val >= min && val <= max)
61 dev_warn(dev,
"%s out of bounds: %d (%d--%d)\n", str, val, min, max);
81 dev_dbg(dev,
"op_sys_clk_freq_hz \t%d\n",
83 dev_dbg(dev,
"op_pix_clk_freq_hz \t%d\n",
100 uint32_t min_vt_div, max_vt_div, vt_div;
106 lane_op_clock_ratio = pll->
lanes;
108 lane_op_clock_ratio = 1;
109 dev_dbg(dev,
"lane_op_clock_ratio: %d\n", lane_op_clock_ratio);
116 * (pll->
lanes / lane_op_clock_ratio);
119 dev_dbg(dev,
"min / max pre_pll_clk_div: %d / %d\n",
130 dev_dbg(dev,
"pre-pll check: min / max pre_pll_clk_div: %d / %d\n",
136 dev_dbg(dev,
"mul %d / div %d\n", mul, div);
143 dev_dbg(dev,
"pll_op check: min / max pre_pll_clk_div: %d / %d\n",
147 dev_err(dev,
"unable to compute pre_pll divisor\n");
161 dev_dbg(dev,
"more_mul_max: max_pll_multiplier check: %d\n",
169 dev_dbg(dev,
"more_mul_max: max_pll_op_freq_hz check: %d\n",
172 more_mul_max =
min(more_mul_max,
175 dev_dbg(dev,
"more_mul_max: max_op_sys_clk_div check: %d\n",
178 more_mul_max =
min(more_mul_max,
180 dev_dbg(dev,
"more_mul_max: min_pll_multiplier check: %d\n",
187 dev_dbg(dev,
"more_mul_min: min_pll_op_freq_hz check: %d\n",
190 more_mul_min =
max(more_mul_min,
192 dev_dbg(dev,
"more_mul_min: min_pll_multiplier check: %d\n",
195 if (more_mul_min > more_mul_max) {
197 "unable to compute more_mul_min and more_mul_max");
202 dev_dbg(dev,
"more_mul_factor: %d\n", more_mul_factor);
204 dev_dbg(dev,
"more_mul_factor: min_op_sys_clk_div: %d\n",
206 i =
roundup(more_mul_min, more_mul_factor);
207 if (!is_one_or_even(i))
210 dev_dbg(dev,
"final more_mul: %d\n", i);
211 if (i > more_mul_max) {
212 dev_warn(dev,
"final more_mul is bad, max %d", more_mul_max);
247 vt_op_binning_div = 1;
248 dev_dbg(dev,
"vt_op_binning_div: %d\n", vt_op_binning_div);
264 lane_op_clock_ratio * vt_op_binning_div
268 dev_dbg(dev,
"min_vt_div: %d\n", min_vt_div);
269 min_vt_div =
max(min_vt_div,
272 dev_dbg(dev,
"min_vt_div: max_vt_pix_clk_freq_hz: %d\n",
277 dev_dbg(dev,
"min_vt_div: min_vt_clk_div: %d\n", min_vt_div);
280 dev_dbg(dev,
"max_vt_div: %d\n", max_vt_div);
281 max_vt_div =
min(max_vt_div,
284 dev_dbg(dev,
"max_vt_div: min_vt_pix_clk_freq_hz: %d\n",
292 dev_dbg(dev,
"min_sys_div: %d\n", min_sys_div);
293 min_sys_div =
max(min_sys_div,
296 dev_dbg(dev,
"min_sys_div: max_vt_pix_clk_div: %d\n", min_sys_div);
297 min_sys_div =
max(min_sys_div,
300 dev_dbg(dev,
"min_sys_div: max_pll_op_clk_freq_hz: %d\n", min_sys_div);
301 min_sys_div = clk_div_even_up(min_sys_div);
302 dev_dbg(dev,
"min_sys_div: one or even: %d\n", min_sys_div);
305 dev_dbg(dev,
"max_sys_div: %d\n", max_sys_div);
306 max_sys_div =
min(max_sys_div,
309 dev_dbg(dev,
"max_sys_div: min_vt_pix_clk_div: %d\n", max_sys_div);
310 max_sys_div =
min(max_sys_div,
313 dev_dbg(dev,
"max_sys_div: min_vt_pix_clk_freq_hz: %d\n", max_sys_div);
320 for (vt_div = min_vt_div; vt_div <= max_vt_div;
321 vt_div += 2 - (vt_div & 1)) {
322 for (sys_div = min_sys_div;
323 sys_div <= max_sys_div;
324 sys_div += 2 - (sys_div & 1)) {
327 if (pix_div < limits->min_vt_pix_clk_div
330 "pix_div %d too small or too big (%d--%d)\n",
338 if (pix_div * sys_div
339 <=
roundup(min_vt_div, best_pix_div))
340 best_pix_div = pix_div;
342 if (best_pix_div < INT_MAX >> 1)
366 "pll_ip_clk_freq_hz");
376 "pll_op_clk_freq_hz");
392 "op_sys_clk_freq_hz");
398 "op_pix_clk_freq_hz");
404 "vt_sys_clk_freq_hz");
410 "vt_pix_clk_freq_hz");