Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e42db1e authored by Richard Fitzgerald's avatar Richard Fitzgerald Committed by Mark Brown
Browse files

ASoC: arizona: Prefer lower FRATIO in pseudo-fractional mode



When setting up an FLL in pseudo-fractional mode it is preferred
to use a lower FRATIO if possible to give a higher reference clock
frequency. This patch swaps the two loops in arizona_calc_fratio()
so that lower FRATIOs are tried first. The decrementing loop is also
changed to start from init_ratio because the original settings might
already give a fractional value for N.K

Signed-off-by: default avatarRichard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 43b27d72
Loading
Loading
Loading
Loading
+15 −12
Original line number Original line Diff line number Diff line
@@ -2037,7 +2037,21 @@ static int arizona_calc_fratio(struct arizona_fll *fll,
			init_ratio, Fref, refdiv);
			init_ratio, Fref, refdiv);


	while (div <= ARIZONA_FLL_MAX_REFDIV) {
	while (div <= ARIZONA_FLL_MAX_REFDIV) {
		for (ratio = init_ratio; ratio <= ARIZONA_FLL_MAX_FRATIO;
		/* start from init_ratio because this may already give a
		 * fractional N.K
		 */
		for (ratio = init_ratio; ratio > 0; ratio--) {
			if (target % (ratio * Fref)) {
				cfg->refdiv = refdiv;
				cfg->fratio = ratio - 1;
				arizona_fll_dbg(fll,
					"pseudo: found fref=%u refdiv=%d(%d) ratio=%d\n",
					Fref, refdiv, div, ratio);
				return ratio;
			}
		}

		for (ratio = init_ratio + 1; ratio <= ARIZONA_FLL_MAX_FRATIO;
		     ratio++) {
		     ratio++) {
			if ((ARIZONA_FLL_VCO_CORNER / 2) /
			if ((ARIZONA_FLL_VCO_CORNER / 2) /
			    (fll->vco_mult * ratio) < Fref) {
			    (fll->vco_mult * ratio) < Fref) {
@@ -2063,17 +2077,6 @@ static int arizona_calc_fratio(struct arizona_fll *fll,
			}
			}
		}
		}


		for (ratio = init_ratio - 1; ratio > 0; ratio--) {
			if (target % (ratio * Fref)) {
				cfg->refdiv = refdiv;
				cfg->fratio = ratio - 1;
				arizona_fll_dbg(fll,
					"pseudo: found fref=%u refdiv=%d(%d) ratio=%d\n",
					Fref, refdiv, div, ratio);
				return ratio;
			}
		}

		div *= 2;
		div *= 2;
		Fref /= 2;
		Fref /= 2;
		refdiv++;
		refdiv++;