CCS PLL fixes and improvements
Subsystems (2)
Sakari Ailus
maintainercover CCS PLL fixes and improvements
Hi folks,
Here are a few fixes and improvements to the CCS PLL calculator.
Sakari Ailus (7):
media: ccs-pll: Start OP pre-PLL multiplier search from correct value
media: ccs-pll: Start VT pre-PLL multiplier search from correct value
media: ccs-pll: Check for too high VT PLL multiplier in dual PLL case
media: ccs-pll: Correctly the upper limit of maximum
op_pre_pll_clk_div
media: ccs-pll: Print a debug message on too high VT PLL OP clock
media: ccs-pll: Add a flag for even PLL multipliers
media: ccs-pll: Better validate VT PLL branch
drivers/media/i2c/ccs-pll.c | 43 +++++++++++++++++++++++++++++-------- drivers/media/i2c/ccs-pll.h | 1 + 2 files changed, 35 insertions(+), 9 deletions(-)
Signature · 1 line
2.39.5
Sakari Ailus
maintainerPATCH 1/7 media: ccs-pll: Start OP pre-PLL multiplier search from correct value
The ccs_pll_calculate() function does a search over possible PLL configurations to find the "best" one. If the sensor did not support odd pre-PLL divisors and the minimum value (with constraints) wasn't 1, other even values could have errorneously searched (and selected) for the pre-PLL divisor. Fix this.
--- drivers/media/i2c/ccs-pll.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/i2c/ccs-pll.c +2 -0
@@ -815,6 +815,8 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,one_or_more (DIV_ROUND_UP (op_lim_fr->max_pll_op_clk_freq_hz, pll->ext_clk_freq_hz)))); +if (!(pll->flags &CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER )) + min_op_pre_pll_clk_div =clk_div_even (min_op_pre_pll_clk_div);dev_dbg (dev,"pll_op check: min / max op_pre_pll_clk_div: %u / %u\n" , min_op_pre_pll_clk_div, max_op_pre_pll_clk_div);
Signature · 1 line
2.39.5
Sakari Ailus
maintainerPATCH 2/7 media: ccs-pll: Start VT pre-PLL multiplier search from correct value
In reply to Sakari AilusThe ccs_pll_calculate_vt_tree() function does a search over possible VT PLL configurations to find the "best" one. If the sensor did not support odd pre-PLL divisors and the minimum value (with constraints) wasn't 1, other even values could have errorneously searched (and selected) for the pre-PLL divisor. Fix this.
--- drivers/media/i2c/ccs-pll.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/i2c/ccs-pll.c +2 -0
@@ -397,6 +397,8 @@ static int ccs_pll_calculate_vt_tree(struct device *dev, min_pre_pll_clk_div =max_t (u16, min_pre_pll_clk_div, pll->ext_clk_freq_hz / lim_fr->max_pll_ip_clk_freq_hz); +if (!(pll->flags &CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER )) + min_pre_pll_clk_div =clk_div_even (min_pre_pll_clk_div);dev_dbg (dev,"vt min/max_pre_pll_clk_div: %u,%u\n" , min_pre_pll_clk_div, max_pre_pll_clk_div);
Signature · 1 line
2.39.5
Sakari Ailus
maintainerPATCH 3/7 media: ccs-pll: Check for too high VT PLL multiplier in dual PLL case
In reply to Sakari AilusThe check for VT PLL upper limit in dual PLL case was missing. Add it now.
--- drivers/media/i2c/ccs-pll.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/i2c/ccs-pll.c +5 -0
@@ -312,6 +312,11 @@ __ccs_pll_calculate_vt_tree(struct device *dev,dev_dbg (dev,"more_mul2: %u\n" , more_mul); pll_fr->pll_multiplier = mul * more_mul; +if (pll_fr->pll_multiplier > lim_fr->max_pll_multiplier) { +dev_dbg (dev,"pll multiplier %u too high\n" , + pll_fr->pll_multiplier); +return -EINVAL ; + }if (pll_fr->pll_multiplier * pll_fr->pll_ip_clk_freq_hz > lim_fr->max_pll_op_clk_freq_hz)
Signature · 1 line
2.39.5
Sakari Ailus
maintainerPATCH 4/7 media: ccs-pll: Correctly the upper limit of maximum op_pre_pll_clk_div
In reply to Sakari AilusThe PLL calculator does a search of the PLL configuration space for all valid OP pre-PLL clock dividers. The maximum did not take into account CCS PLL flag CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER in which case also odd PLL dividers (other than 1) are valid. Do that now.
--- drivers/media/i2c/ccs-pll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ccs-pll.c +1 -1
@@ -799,7 +799,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, op_lim_fr->min_pre_pll_clk_div, op_lim_fr->max_pre_pll_clk_div); max_op_pre_pll_clk_div =min_t (u16, op_lim_fr->max_pre_pll_clk_div, -clk_div_even (pll->ext_clk_freq_hz / +DIV_ROUND_UP (pll->ext_clk_freq_hz, op_lim_fr->min_pll_ip_clk_freq_hz)); min_op_pre_pll_clk_div = max_t(u16, op_lim_fr->min_pre_pll_clk_div,
Signature · 1 line
2.39.5
Sakari Ailus
maintainerPATCH 5/7 media: ccs-pll: Print a debug message on too high VT PLL OP clock
In reply to Sakari AilusIn general the CCS PLL calculator prints debugging information on the process to ease debugging. This case was not annotated, do that now.
Remove an extra multiplication while at it.
--- drivers/media/i2c/ccs-pll.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/i2c/ccs-pll.c +5 -4
@@ -318,12 +318,13 @@ __ccs_pll_calculate_vt_tree(struct device *dev,return -EINVAL ; } -if (pll_fr->pll_multiplier * pll_fr->pll_ip_clk_freq_hz > - lim_fr->max_pll_op_clk_freq_hz) -return -EINVAL ; - pll_fr->pll_op_clk_freq_hz = pll_fr->pll_ip_clk_freq_hz * pll_fr->pll_multiplier; +if (pll_fr->pll_op_clk_freq_hz > lim_fr->max_pll_op_clk_freq_hz) { +dev_dbg (dev,"too high OP clock %u\n" , + pll_fr->pll_op_clk_freq_hz); +return -EINVAL ; + } vt_div = div * more_mul;
Signature · 1 line
2.39.5
Sakari Ailus
maintainerPATCH 6/7 media: ccs-pll: Add a flag for even PLL multipliers
In reply to Sakari AilusSome devices (not entirely CCS compliant) only support even PLL multipliers. Add support for this through a PLL flag.
--- drivers/media/i2c/ccs-pll.c | 13 +++++++++++-- drivers/media/i2c/ccs-pll.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs-pll.c +11 -2
@@ -124,7 +124,7 @@ static void print_pll(struct device *dev, struct ccs_pll *pll)dev_dbg (dev,"pixel rate on CSI-2 bus:\t%u\n" , pll->pixel_rate_csi); - dev_dbg(dev, "flags%s%s%s%s%s%s%s%s%s\n", + dev_dbg(dev, "flags%s%s%s%s%s%s%s%s%s%s\n", pll->flags & PLL_FL(LANE_SPEED_MODEL) ? " lane-speed" : "", pll->flags & PLL_FL(LINK_DECOUPLED) ? " link-decoupled" : "", pll->flags & PLL_FL(EXT_IP_PLL_DIVIDER) ?
@@ -135,7 +135,8 @@ static void print_pll(struct device *dev, struct ccs_pll *pll) pll->flags &PLL_FL (FIFO_OVERRATING ) ?" fifo-overrating" :"" , pll->flags &PLL_FL (DUAL_PLL ) ?" dual-pll" :"" , pll->flags &PLL_FL (OP_SYS_DDR ) ?" op-sys-ddr" :"" , - pll->flags & PLL_FL(OP_PIX_DDR) ? " op-pix-ddr" : ""); + pll->flags &PLL_FL (OP_PIX_DDR ) ?" op-pix-ddr" :"" , + pll->flags & PLL_FL(EVEN_PLL_MULTIPLIER) ? " even-pll-multiplier" : ""); }static u32 op_sys_ddr (u32 flags)
@@ -311,6 +312,10 @@ __ccs_pll_calculate_vt_tree(struct device *dev, more_mul *=DIV_ROUND_UP (lim_fr->min_pll_multiplier, mul * more_mul);dev_dbg (dev,"more_mul2: %u\n" , more_mul); +if (pll->flags &CCS_PLL_FLAG_EVEN_PLL_MULTIPLIER && + mul &1 && more_mul &1 ) + more_mul <<=1 ; + pll_fr->pll_multiplier = mul * more_mul;if (pll_fr->pll_multiplier > lim_fr->max_pll_multiplier) { dev_dbg(dev, "pll multiplier %u too high\n",
@@ -667,6 +672,10 @@ ccs_pll_calculate_op(struct device *dev, const struct ccs_pll_limits *lim,if (!is_one_or_even (i)) i <<=1 ; +if (pll->flags &CCS_PLL_FLAG_EVEN_PLL_MULTIPLIER && + mul &1 && i &1 ) + i <<=1 ; +dev_dbg (dev,"final more_mul: %u\n" , i);if (i > more_mul_max) {dev_dbg (dev,"final more_mul is bad, max %u\n" , more_mul_max);
drivers/media/i2c/ccs-pll.h +1 -0
@@ -32,6 +32,7 @@#define CCS_PLL_FLAG_DUAL_PLL BIT(8)#define CCS_PLL_FLAG_OP_SYS_DDR BIT(9)#define CCS_PLL_FLAG_OP_PIX_DDR BIT(10) +#define CCS_PLL_FLAG_EVEN_PLL_MULTIPLIER BIT(11)/** * struct ccs_pll_branch_fr - CCS PLL configuration (front)
Signature · 1 line
2.39.5
Sakari Ailus
maintainerPATCH 7/7 media: ccs-pll: Better validate VT PLL branch
In reply to Sakari AilusCheck that the VT PLL dividers are actually found, don't trust they always are even though they should be.
--- drivers/media/i2c/ccs-pll.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/media/i2c/ccs-pll.c +9 -3
@@ -448,7 +448,7 @@ static int ccs_pll_calculate_vt_tree(struct device *dev,return -EINVAL ; } -static void +static int ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim, const struct ccs_pll_branch_limits_bk *op_lim_bk, struct ccs_pll *pll, struct ccs_pll_branch_fr *pll_fr,
@@ -571,6 +571,8 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,if (best_pix_div <SHRT_MAX >>1 )break ; } +if (best_pix_div ==SHRT_MAX >>1 ) +return -EINVAL ; pll->vt_bk.sys_clk_div =DIV_ROUND_UP (vt_div, best_pix_div); pll->vt_bk.pix_clk_div = best_pix_div;
@@ -583,6 +585,8 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim, out_calc_pixel_rate: pll->pixel_rate_pixel_array = pll->vt_bk.pix_clk_freq_hz * pll->vt_lanes; + +return 0 ; }/*
@@ -862,8 +866,10 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,if (pll->flags &CCS_PLL_FLAG_DUAL_PLL )break ; -ccs_pll_calculate_vt (dev, lim, op_lim_bk, pll, op_pll_fr, - op_pll_bk, cphy, phy_const); + rval =ccs_pll_calculate_vt (dev, lim, op_lim_bk, pll, op_pll_fr, + op_pll_bk, cphy, phy_const); +if (rval) +continue ; rval =check_bk_bounds (dev, lim, pll,PLL_VT );if (rval)
Signature · 1 line
2.39.5