Commit 9e359c64 authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown
Browse files

ASoC: arizona: Tidy up SYNCCLK selection and cache values



This patch caches the current SYNCCLK settings in the arizona_fll struct
and uses these to simplify the code which determines which source should
be used for the REFCLK and SYNCCLK inputs.

Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 19b34bdc
Loading
Loading
Loading
Loading
+50 −51
Original line number Diff line number Diff line
@@ -1078,67 +1078,56 @@ int arizona_set_fll(struct arizona_fll *fll, int source,
		    unsigned int Fref, unsigned int Fout)
{
	struct arizona *arizona = fll->arizona;
	struct arizona_fll_cfg cfg, sync;
	struct arizona_fll_cfg ref, sync;
	unsigned int reg;
	int syncsrc;
	bool ena;
	int ret;

	if (fll->fref == Fref && fll->fout == Fout)
		return 0;

	ret = regmap_read(arizona->regmap, fll->base + 1, &reg);
	if (ret != 0) {
		arizona_fll_err(fll, "Failed to read current state: %d\n",
				ret);
	if (fll->ref_src < 0 || fll->ref_src == source) {
		if (Fout) {
			ret = arizona_calc_fll(fll, &ref, Fref, Fout);
			if (ret != 0)
				return ret;
		}
	ena = reg & ARIZONA_FLL1_ENA;

		fll->sync_src = -1;
		fll->ref_src = source;
		fll->ref_freq = Fref;
	} else {
		if (Fout) {
		syncsrc = fll->ref_src;

		if (source == syncsrc)
			syncsrc = -1;

		if (syncsrc >= 0) {
			ret = arizona_calc_fll(fll, &sync, Fref, Fout);
			ret = arizona_calc_fll(fll, &ref, fll->ref_freq, Fout);
			if (ret != 0)
				return ret;

			ret = arizona_calc_fll(fll, &cfg, fll->ref_freq, Fout);
			if (ret != 0)
				return ret;
		} else {
			ret = arizona_calc_fll(fll, &cfg, Fref, Fout);
			ret = arizona_calc_fll(fll, &sync, Fref, Fout);
			if (ret != 0)
				return ret;
		}
	} else {
		regmap_update_bits(arizona->regmap, fll->base + 1,
				   ARIZONA_FLL1_ENA, 0);
		regmap_update_bits(arizona->regmap, fll->base + 0x11,
				   ARIZONA_FLL1_SYNC_ENA, 0);

		if (ena)
			pm_runtime_put_autosuspend(arizona->dev);

		fll->fref = Fref;
		fll->fout = Fout;
		fll->sync_src = source;
		fll->sync_freq = Fref;
	}

		return 0;
	ret = regmap_read(arizona->regmap, fll->base + 1, &reg);
	if (ret != 0) {
		arizona_fll_err(fll, "Failed to read current state: %d\n",
				ret);
		return ret;
	}
	ena = reg & ARIZONA_FLL1_ENA;

	if (Fout) {
		regmap_update_bits(arizona->regmap, fll->base + 5,
				   ARIZONA_FLL1_OUTDIV_MASK,
			   cfg.outdiv << ARIZONA_FLL1_OUTDIV_SHIFT);
				   ref.outdiv << ARIZONA_FLL1_OUTDIV_SHIFT);

	if (syncsrc >= 0) {
		arizona_apply_fll(arizona, fll->base, &cfg, syncsrc);
		arizona_apply_fll(arizona, fll->base + 0x10, &sync, source);
	} else {
		arizona_apply_fll(arizona, fll->base, &cfg, source);
	}
		arizona_apply_fll(arizona, fll->base, &ref, fll->ref_src);
		if (fll->sync_src >= 0)
			arizona_apply_fll(arizona, fll->base + 0x10, &sync,
					  fll->sync_src);

		if (!ena)
			pm_runtime_get(arizona->dev);
@@ -1148,7 +1137,7 @@ int arizona_set_fll(struct arizona_fll *fll, int source,

		regmap_update_bits(arizona->regmap, fll->base + 1,
				   ARIZONA_FLL1_ENA, ARIZONA_FLL1_ENA);
	if (syncsrc >= 0)
		if (fll->sync_src >= 0)
			regmap_update_bits(arizona->regmap, fll->base + 0x11,
					   ARIZONA_FLL1_SYNC_ENA,
					   ARIZONA_FLL1_SYNC_ENA);
@@ -1157,6 +1146,15 @@ int arizona_set_fll(struct arizona_fll *fll, int source,
						  msecs_to_jiffies(250));
		if (ret == 0)
			arizona_fll_warn(fll, "Timed out waiting for lock\n");
	} else {
		regmap_update_bits(arizona->regmap, fll->base + 1,
				   ARIZONA_FLL1_ENA, 0);
		regmap_update_bits(arizona->regmap, fll->base + 0x11,
				   ARIZONA_FLL1_SYNC_ENA, 0);

		if (ena)
			pm_runtime_put_autosuspend(arizona->dev);
	}

	fll->fref = Fref;
	fll->fout = Fout;
@@ -1176,6 +1174,7 @@ int arizona_init_fll(struct arizona *arizona, int id, int base, int lock_irq,
	fll->id = id;
	fll->base = base;
	fll->arizona = arizona;
	fll->sync_src = -1;

	/* Configure default refclk to 32kHz if we have one */
	regmap_read(arizona->regmap, ARIZONA_CLOCK_32K_1, &val);
+2 −0
Original line number Diff line number Diff line
@@ -201,6 +201,8 @@ struct arizona_fll {
	unsigned int fref;
	unsigned int fout;

	int sync_src;
	unsigned int sync_freq;
	int ref_src;
	unsigned int ref_freq;