aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/i2c/smiapp-pll.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/i2c/smiapp-pll.c')
-rw-r--r--drivers/media/i2c/smiapp-pll.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/drivers/media/i2c/smiapp-pll.c b/drivers/media/i2c/smiapp-pll.c
index cbef446180f8..61e2401c1b35 100644
--- a/drivers/media/i2c/smiapp-pll.c
+++ b/drivers/media/i2c/smiapp-pll.c
@@ -88,7 +88,7 @@ static void print_pll(struct device *dev, struct smiapp_pll *pll)
88} 88}
89 89
90static int __smiapp_pll_calculate(struct device *dev, 90static int __smiapp_pll_calculate(struct device *dev,
91 struct smiapp_pll_limits *limits, 91 const struct smiapp_pll_limits *limits,
92 struct smiapp_pll *pll, uint32_t mul, 92 struct smiapp_pll *pll, uint32_t mul,
93 uint32_t div, uint32_t lane_op_clock_ratio) 93 uint32_t div, uint32_t lane_op_clock_ratio)
94{ 94{
@@ -306,14 +306,10 @@ static int __smiapp_pll_calculate(struct device *dev,
306 pll->pixel_rate_csi = 306 pll->pixel_rate_csi =
307 pll->op_pix_clk_freq_hz * lane_op_clock_ratio; 307 pll->op_pix_clk_freq_hz * lane_op_clock_ratio;
308 308
309 rval = bounds_check(dev, pll->pre_pll_clk_div, 309 rval = bounds_check(dev, pll->pll_ip_clk_freq_hz,
310 limits->min_pre_pll_clk_div, 310 limits->min_pll_ip_freq_hz,
311 limits->max_pre_pll_clk_div, "pre_pll_clk_div"); 311 limits->max_pll_ip_freq_hz,
312 if (!rval) 312 "pll_ip_clk_freq_hz");
313 rval = bounds_check(
314 dev, pll->pll_ip_clk_freq_hz,
315 limits->min_pll_ip_freq_hz, limits->max_pll_ip_freq_hz,
316 "pll_ip_clk_freq_hz");
317 if (!rval) 313 if (!rval)
318 rval = bounds_check( 314 rval = bounds_check(
319 dev, pll->pll_multiplier, 315 dev, pll->pll_multiplier,
@@ -362,9 +358,12 @@ static int __smiapp_pll_calculate(struct device *dev,
362 return rval; 358 return rval;
363} 359}
364 360
365int smiapp_pll_calculate(struct device *dev, struct smiapp_pll_limits *limits, 361int smiapp_pll_calculate(struct device *dev,
362 const struct smiapp_pll_limits *limits,
366 struct smiapp_pll *pll) 363 struct smiapp_pll *pll)
367{ 364{
365 uint16_t min_pre_pll_clk_div;
366 uint16_t max_pre_pll_clk_div;
368 uint32_t lane_op_clock_ratio; 367 uint32_t lane_op_clock_ratio;
369 uint32_t mul, div; 368 uint32_t mul, div;
370 unsigned int i; 369 unsigned int i;
@@ -397,33 +396,33 @@ int smiapp_pll_calculate(struct device *dev, struct smiapp_pll_limits *limits,
397 /* Figure out limits for pre-pll divider based on extclk */ 396 /* Figure out limits for pre-pll divider based on extclk */
398 dev_dbg(dev, "min / max pre_pll_clk_div: %d / %d\n", 397 dev_dbg(dev, "min / max pre_pll_clk_div: %d / %d\n",
399 limits->min_pre_pll_clk_div, limits->max_pre_pll_clk_div); 398 limits->min_pre_pll_clk_div, limits->max_pre_pll_clk_div);
400 limits->max_pre_pll_clk_div = 399 max_pre_pll_clk_div =
401 min_t(uint16_t, limits->max_pre_pll_clk_div, 400 min_t(uint16_t, limits->max_pre_pll_clk_div,
402 clk_div_even(pll->ext_clk_freq_hz / 401 clk_div_even(pll->ext_clk_freq_hz /
403 limits->min_pll_ip_freq_hz)); 402 limits->min_pll_ip_freq_hz));
404 limits->min_pre_pll_clk_div = 403 min_pre_pll_clk_div =
405 max_t(uint16_t, limits->min_pre_pll_clk_div, 404 max_t(uint16_t, limits->min_pre_pll_clk_div,
406 clk_div_even_up( 405 clk_div_even_up(
407 DIV_ROUND_UP(pll->ext_clk_freq_hz, 406 DIV_ROUND_UP(pll->ext_clk_freq_hz,
408 limits->max_pll_ip_freq_hz))); 407 limits->max_pll_ip_freq_hz)));
409 dev_dbg(dev, "pre-pll check: min / max pre_pll_clk_div: %d / %d\n", 408 dev_dbg(dev, "pre-pll check: min / max pre_pll_clk_div: %d / %d\n",
410 limits->min_pre_pll_clk_div, limits->max_pre_pll_clk_div); 409 min_pre_pll_clk_div, max_pre_pll_clk_div);
411 410
412 i = gcd(pll->pll_op_clk_freq_hz, pll->ext_clk_freq_hz); 411 i = gcd(pll->pll_op_clk_freq_hz, pll->ext_clk_freq_hz);
413 mul = div_u64(pll->pll_op_clk_freq_hz, i); 412 mul = div_u64(pll->pll_op_clk_freq_hz, i);
414 div = pll->ext_clk_freq_hz / i; 413 div = pll->ext_clk_freq_hz / i;
415 dev_dbg(dev, "mul %d / div %d\n", mul, div); 414 dev_dbg(dev, "mul %d / div %d\n", mul, div);
416 415
417 limits->min_pre_pll_clk_div = 416 min_pre_pll_clk_div =
418 max_t(uint16_t, limits->min_pre_pll_clk_div, 417 max_t(uint16_t, min_pre_pll_clk_div,
419 clk_div_even_up( 418 clk_div_even_up(
420 DIV_ROUND_UP(mul * pll->ext_clk_freq_hz, 419 DIV_ROUND_UP(mul * pll->ext_clk_freq_hz,
421 limits->max_pll_op_freq_hz))); 420 limits->max_pll_op_freq_hz)));
422 dev_dbg(dev, "pll_op check: min / max pre_pll_clk_div: %d / %d\n", 421 dev_dbg(dev, "pll_op check: min / max pre_pll_clk_div: %d / %d\n",
423 limits->min_pre_pll_clk_div, limits->max_pre_pll_clk_div); 422 min_pre_pll_clk_div, max_pre_pll_clk_div);
424 423
425 for (pll->pre_pll_clk_div = limits->min_pre_pll_clk_div; 424 for (pll->pre_pll_clk_div = min_pre_pll_clk_div;
426 pll->pre_pll_clk_div <= limits->max_pre_pll_clk_div; 425 pll->pre_pll_clk_div <= max_pre_pll_clk_div;
427 pll->pre_pll_clk_div += 2 - (pll->pre_pll_clk_div & 1)) { 426 pll->pre_pll_clk_div += 2 - (pll->pre_pll_clk_div & 1)) {
428 rval = __smiapp_pll_calculate(dev, limits, pll, mul, div, 427 rval = __smiapp_pll_calculate(dev, limits, pll, mul, div,
429 lane_op_clock_ratio); 428 lane_op_clock_ratio);