Message ID | 20250417065354.311617-9-sakari.ailus@linux.intel.com |
---|---|
State | New |
Headers | show |
Series | CCS PLL fixes and improvements | expand |
Hi Sakari, Thank you for the patch. On Thu, Apr 17, 2025 at 09:53:51AM +0300, Sakari Ailus wrote: > Some devices (not entirely CCS compliant) only support even PLL > multipliers. Add support for this through a PLL flag. > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> > --- > drivers/media/i2c/ccs-pll.c | 11 ++++++++++- > drivers/media/i2c/ccs-pll.h | 1 + > 2 files changed, 11 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/i2c/ccs-pll.c b/drivers/media/i2c/ccs-pll.c > index ebbc5e323244..3f8153fb4af0 100644 > --- a/drivers/media/i2c/ccs-pll.c > +++ b/drivers/media/i2c/ccs-pll.c > @@ -124,9 +124,10 @@ static void print_pll(struct device *dev, const 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%s\n", > + dev_dbg(dev, "flags%s%s%s%s%s%s%s%s%s%s%s\n", > pll->flags & PLL_FL(OP_PIX_CLOCK_PER_LANE) ? " op-pix-clock-per-lane" : "", > pll->flags & PLL_FL(NO_OP_CLOCKS) ? " no-op-clocks" : "", > + pll->flags & PLL_FL(EVEN_PLL_MULTIPLIER) ? " even-pll-multiplier" : "", > pll->flags & PLL_FL(LANE_SPEED_MODEL) ? " lane-speed" : "", > pll->flags & PLL_FL(EXT_IP_PLL_DIVIDER) ? > " ext-ip-pll-divider" : "", > @@ -312,6 +313,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) Even if not mandated by the C standard, I'd write (mul & 1) && (more_mul & 1)) to make the code easier to read. > + more_mul <<= 1; I'm not sure to get the logic behind this :-/ > + > 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", > @@ -668,6 +673,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) Same here. > + 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); > diff --git a/drivers/media/i2c/ccs-pll.h b/drivers/media/i2c/ccs-pll.h > index ee206e5b287b..e8297db45460 100644 > --- a/drivers/media/i2c/ccs-pll.h > +++ b/drivers/media/i2c/ccs-pll.h > @@ -31,6 +31,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) You could reuse bit 3, as it got dropped in patch 06/11. > > /** > * struct ccs_pll_branch_fr - CCS PLL configuration (front)
diff --git a/drivers/media/i2c/ccs-pll.c b/drivers/media/i2c/ccs-pll.c index ebbc5e323244..3f8153fb4af0 100644 --- a/drivers/media/i2c/ccs-pll.c +++ b/drivers/media/i2c/ccs-pll.c @@ -124,9 +124,10 @@ static void print_pll(struct device *dev, const 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%s\n", + dev_dbg(dev, "flags%s%s%s%s%s%s%s%s%s%s%s\n", pll->flags & PLL_FL(OP_PIX_CLOCK_PER_LANE) ? " op-pix-clock-per-lane" : "", pll->flags & PLL_FL(NO_OP_CLOCKS) ? " no-op-clocks" : "", + pll->flags & PLL_FL(EVEN_PLL_MULTIPLIER) ? " even-pll-multiplier" : "", pll->flags & PLL_FL(LANE_SPEED_MODEL) ? " lane-speed" : "", pll->flags & PLL_FL(EXT_IP_PLL_DIVIDER) ? " ext-ip-pll-divider" : "", @@ -312,6 +313,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", @@ -668,6 +673,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); diff --git a/drivers/media/i2c/ccs-pll.h b/drivers/media/i2c/ccs-pll.h index ee206e5b287b..e8297db45460 100644 --- a/drivers/media/i2c/ccs-pll.h +++ b/drivers/media/i2c/ccs-pll.h @@ -31,6 +31,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)
Some devices (not entirely CCS compliant) only support even PLL multipliers. Add support for this through a PLL flag. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> --- drivers/media/i2c/ccs-pll.c | 11 ++++++++++- drivers/media/i2c/ccs-pll.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)