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

Unverified Commit 0d1b2881 authored by Mark Brown's avatar Mark Brown
Browse files

Merge remote-tracking branches 'asoc/topic/wm8960', 'asoc/topic/wm8961',...

Merge remote-tracking branches 'asoc/topic/wm8960', 'asoc/topic/wm8961', 'asoc/topic/wm8962', 'asoc/topic/wm8971' and 'asoc/topic/wm8974' into asoc-next
Loading
Loading
Loading
Loading
+126 −123
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@
#define WM8960_DRES_MASK 0x30

static bool is_pll_freq_available(unsigned int source, unsigned int target);
static int wm8960_set_pll(struct snd_soc_codec *codec,
static int wm8960_set_pll(struct snd_soc_component *component,
		unsigned int freq_in, unsigned int freq_out);
/*
 * wm8960 register cache
@@ -123,7 +123,7 @@ static bool wm8960_volatile(struct device *dev, unsigned int reg)
struct wm8960_priv {
	struct clk *mclk;
	struct regmap *regmap;
	int (*set_bias_level)(struct snd_soc_codec *,
	int (*set_bias_level)(struct snd_soc_component *,
			      enum snd_soc_bias_level level);
	struct snd_soc_dapm_widget *lout1;
	struct snd_soc_dapm_widget *rout1;
@@ -168,9 +168,9 @@ static const struct soc_enum wm8960_enum[] = {

static const int deemph_settings[] = { 0, 32000, 44100, 48000 };

static int wm8960_set_deemph(struct snd_soc_codec *codec)
static int wm8960_set_deemph(struct snd_soc_component *component)
{
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	int val, i, best;

	/* If we're using deemphasis select the nearest available sample
@@ -189,17 +189,17 @@ static int wm8960_set_deemph(struct snd_soc_codec *codec)
		val = 0;
	}

	dev_dbg(codec->dev, "Set deemphasis %d\n", val);
	dev_dbg(component->dev, "Set deemphasis %d\n", val);

	return snd_soc_update_bits(codec, WM8960_DACCTL1,
	return snd_soc_component_update_bits(component, WM8960_DACCTL1,
				   0x6, val);
}

static int wm8960_get_deemph(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);

	ucontrol->value.integer.value[0] = wm8960->deemph;
	return 0;
@@ -208,8 +208,8 @@ static int wm8960_get_deemph(struct snd_kcontrol *kcontrol,
static int wm8960_put_deemph(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	unsigned int deemph = ucontrol->value.integer.value[0];

	if (deemph > 1)
@@ -217,7 +217,7 @@ static int wm8960_put_deemph(struct snd_kcontrol *kcontrol,

	wm8960->deemph = deemph;

	return wm8960_set_deemph(codec);
	return wm8960_set_deemph(component);
}

static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1);
@@ -470,11 +470,11 @@ static const struct snd_soc_dapm_route audio_paths_capless[] = {
	{ "OUT3 VMID", NULL, "Right Output Mixer" },
};

static int wm8960_add_widgets(struct snd_soc_codec *codec)
static int wm8960_add_widgets(struct snd_soc_component *component)
{
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	struct wm8960_data *pdata = &wm8960->pdata;
	struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
	struct snd_soc_dapm_widget *w;

	snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets,
@@ -504,7 +504,7 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)
	 * list each time to find the desired power state do so now
	 * and save the result.
	 */
	list_for_each_entry(w, &codec->component.card->widgets, list) {
	list_for_each_entry(w, &component->card->widgets, list) {
		if (w->dapm != dapm)
			continue;
		if (strcmp(w->name, "LOUT1 PGA") == 0)
@@ -521,7 +521,7 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)
static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai,
		unsigned int fmt)
{
	struct snd_soc_codec *codec = codec_dai->codec;
	struct snd_soc_component *component = codec_dai->component;
	u16 iface = 0;

	/* set master/slave audio interface */
@@ -573,7 +573,7 @@ static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai,
	}

	/* set iface */
	snd_soc_write(codec, WM8960_IFACE1, iface);
	snd_soc_component_write(component, WM8960_IFACE1, iface);
	return 0;
}

@@ -683,7 +683,7 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk,
 * 	triplet, we relax the bclk such that bclk is chosen as the
 * 	closest available frequency greater than expected bclk.
 *
 * @codec: codec structure
 * @component: component structure
 * @freq_in: input frequency used to derive freq out via PLL
 * @sysclk_idx: sysclk_divs index for found sysclk
 * @dac_idx: dac_divs index for found lrclk
@@ -695,10 +695,10 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk,
 *      (@sysclk_idx, @dac_idx, @bclk_idx) dividers
 */
static
int wm8960_configure_pll(struct snd_soc_codec *codec, int freq_in,
int wm8960_configure_pll(struct snd_soc_component *component, int freq_in,
			 int *sysclk_idx, int *dac_idx, int *bclk_idx)
{
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	int sysclk, bclk, lrclk, freq_out;
	int diff, closest, best_freq_out;
	int i, j, k;
@@ -741,22 +741,22 @@ int wm8960_configure_pll(struct snd_soc_codec *codec, int freq_in,

	return best_freq_out;
}
static int wm8960_configure_clocking(struct snd_soc_codec *codec)
static int wm8960_configure_clocking(struct snd_soc_component *component)
{
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	int freq_out, freq_in;
	u16 iface1 = snd_soc_read(codec, WM8960_IFACE1);
	u16 iface1 = snd_soc_component_read32(component, WM8960_IFACE1);
	int i, j, k;
	int ret;

	if (!(iface1 & (1<<6))) {
		dev_dbg(codec->dev,
		dev_dbg(component->dev,
			"Codec is slave mode, no need to configure clock\n");
		return 0;
	}

	if (wm8960->clk_id != WM8960_SYSCLK_MCLK && !wm8960->freq_in) {
		dev_err(codec->dev, "No MCLK configured\n");
		dev_err(component->dev, "No MCLK configured\n");
		return -EINVAL;
	}

@@ -769,12 +769,12 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec)
	 */
	if (wm8960->clk_id == WM8960_SYSCLK_AUTO) {
		/* disable the PLL and using MCLK to provide sysclk */
		wm8960_set_pll(codec, 0, 0);
		wm8960_set_pll(component, 0, 0);
		freq_out = freq_in;
	} else if (wm8960->sysclk) {
		freq_out = wm8960->sysclk;
	} else {
		dev_err(codec->dev, "No SYSCLK configured\n");
		dev_err(component->dev, "No SYSCLK configured\n");
		return -EINVAL;
	}

@@ -783,28 +783,28 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec)
		if (ret >= 0) {
			goto configure_clock;
		} else if (wm8960->clk_id != WM8960_SYSCLK_AUTO) {
			dev_err(codec->dev, "failed to configure clock\n");
			dev_err(component->dev, "failed to configure clock\n");
			return -EINVAL;
		}
	}

	freq_out = wm8960_configure_pll(codec, freq_in, &i, &j, &k);
	freq_out = wm8960_configure_pll(component, freq_in, &i, &j, &k);
	if (freq_out < 0) {
		dev_err(codec->dev, "failed to configure clock via PLL\n");
		dev_err(component->dev, "failed to configure clock via PLL\n");
		return freq_out;
	}
	wm8960_set_pll(codec, freq_in, freq_out);
	wm8960_set_pll(component, freq_in, freq_out);

configure_clock:
	/* configure sysclk clock */
	snd_soc_update_bits(codec, WM8960_CLOCK1, 3 << 1, i << 1);
	snd_soc_component_update_bits(component, WM8960_CLOCK1, 3 << 1, i << 1);

	/* configure frame clock */
	snd_soc_update_bits(codec, WM8960_CLOCK1, 0x7 << 3, j << 3);
	snd_soc_update_bits(codec, WM8960_CLOCK1, 0x7 << 6, j << 6);
	snd_soc_component_update_bits(component, WM8960_CLOCK1, 0x7 << 3, j << 3);
	snd_soc_component_update_bits(component, WM8960_CLOCK1, 0x7 << 6, j << 6);

	/* configure bit clock */
	snd_soc_update_bits(codec, WM8960_CLOCK2, 0xf, k);
	snd_soc_component_update_bits(component, WM8960_CLOCK2, 0xf, k);

	return 0;
}
@@ -813,9 +813,9 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
			    struct snd_pcm_hw_params *params,
			    struct snd_soc_dai *dai)
{
	struct snd_soc_codec *codec = dai->codec;
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3;
	struct snd_soc_component *component = dai->component;
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	u16 iface = snd_soc_component_read32(component, WM8960_IFACE1) & 0xfff3;
	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
	int i;

@@ -840,7 +840,7 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
			break;
		}
	default:
		dev_err(codec->dev, "unsupported width %d\n",
		dev_err(component->dev, "unsupported width %d\n",
			params_width(params));
		return -EINVAL;
	}
@@ -848,23 +848,23 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
	wm8960->lrclk = params_rate(params);
	/* Update filters for the new rate */
	if (tx) {
		wm8960_set_deemph(codec);
		wm8960_set_deemph(component);
	} else {
		for (i = 0; i < ARRAY_SIZE(alc_rates); i++)
			if (alc_rates[i].rate == params_rate(params))
				snd_soc_update_bits(codec,
				snd_soc_component_update_bits(component,
						    WM8960_ADDCTL3, 0x7,
						    alc_rates[i].val);
	}

	/* set iface */
	snd_soc_write(codec, WM8960_IFACE1, iface);
	snd_soc_component_write(component, WM8960_IFACE1, iface);

	wm8960->is_stream_in_use[tx] = true;

	if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON &&
	if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON &&
	    !wm8960->is_stream_in_use[!tx])
		return wm8960_configure_clocking(codec);
		return wm8960_configure_clocking(component);

	return 0;
}
@@ -872,8 +872,8 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
static int wm8960_hw_free(struct snd_pcm_substream *substream,
		struct snd_soc_dai *dai)
{
	struct snd_soc_codec *codec = dai->codec;
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct snd_soc_component *component = dai->component;
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;

	wm8960->is_stream_in_use[tx] = false;
@@ -883,20 +883,20 @@ static int wm8960_hw_free(struct snd_pcm_substream *substream,

static int wm8960_mute(struct snd_soc_dai *dai, int mute)
{
	struct snd_soc_codec *codec = dai->codec;
	struct snd_soc_component *component = dai->component;

	if (mute)
		snd_soc_update_bits(codec, WM8960_DACCTL1, 0x8, 0x8);
		snd_soc_component_update_bits(component, WM8960_DACCTL1, 0x8, 0x8);
	else
		snd_soc_update_bits(codec, WM8960_DACCTL1, 0x8, 0);
		snd_soc_component_update_bits(component, WM8960_DACCTL1, 0x8, 0);
	return 0;
}

static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
static int wm8960_set_bias_level_out3(struct snd_soc_component *component,
				      enum snd_soc_bias_level level)
{
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	u16 pm2 = snd_soc_read(codec, WM8960_POWER2);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	u16 pm2 = snd_soc_component_read32(component, WM8960_POWER2);
	int ret;

	switch (level) {
@@ -904,24 +904,24 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
		break;

	case SND_SOC_BIAS_PREPARE:
		switch (snd_soc_codec_get_bias_level(codec)) {
		switch (snd_soc_component_get_bias_level(component)) {
		case SND_SOC_BIAS_STANDBY:
			if (!IS_ERR(wm8960->mclk)) {
				ret = clk_prepare_enable(wm8960->mclk);
				if (ret) {
					dev_err(codec->dev,
					dev_err(component->dev,
						"Failed to enable MCLK: %d\n",
						ret);
					return ret;
				}
			}

			ret = wm8960_configure_clocking(codec);
			ret = wm8960_configure_clocking(component);
			if (ret)
				return ret;

			/* Set VMID to 2x50k */
			snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80);
			snd_soc_component_update_bits(component, WM8960_POWER1, 0x180, 0x80);
			break;

		case SND_SOC_BIAS_ON:
@@ -930,7 +930,7 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
			 * disable the pll
			 */
			if (wm8960->clk_id == WM8960_SYSCLK_AUTO && (pm2 & 0x1))
				wm8960_set_pll(codec, 0, 0);
				wm8960_set_pll(component, 0, 0);

			if (!IS_ERR(wm8960->mclk))
				clk_disable_unprepare(wm8960->mclk);
@@ -943,38 +943,38 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
		break;

	case SND_SOC_BIAS_STANDBY:
		if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
			regcache_sync(wm8960->regmap);

			/* Enable anti-pop features */
			snd_soc_write(codec, WM8960_APOP1,
			snd_soc_component_write(component, WM8960_APOP1,
				      WM8960_POBCTRL | WM8960_SOFT_ST |
				      WM8960_BUFDCOPEN | WM8960_BUFIOEN);

			/* Enable & ramp VMID at 2x50k */
			snd_soc_update_bits(codec, WM8960_POWER1, 0x80, 0x80);
			snd_soc_component_update_bits(component, WM8960_POWER1, 0x80, 0x80);
			msleep(100);

			/* Enable VREF */
			snd_soc_update_bits(codec, WM8960_POWER1, WM8960_VREF,
			snd_soc_component_update_bits(component, WM8960_POWER1, WM8960_VREF,
					    WM8960_VREF);

			/* Disable anti-pop features */
			snd_soc_write(codec, WM8960_APOP1, WM8960_BUFIOEN);
			snd_soc_component_write(component, WM8960_APOP1, WM8960_BUFIOEN);
		}

		/* Set VMID to 2x250k */
		snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x100);
		snd_soc_component_update_bits(component, WM8960_POWER1, 0x180, 0x100);
		break;

	case SND_SOC_BIAS_OFF:
		/* Enable anti-pop features */
		snd_soc_write(codec, WM8960_APOP1,
		snd_soc_component_write(component, WM8960_APOP1,
			     WM8960_POBCTRL | WM8960_SOFT_ST |
			     WM8960_BUFDCOPEN | WM8960_BUFIOEN);

		/* Disable VMID and VREF, let them discharge */
		snd_soc_write(codec, WM8960_POWER1, 0);
		snd_soc_component_write(component, WM8960_POWER1, 0);
		msleep(600);
		break;
	}
@@ -982,11 +982,11 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
	return 0;
}

static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
static int wm8960_set_bias_level_capless(struct snd_soc_component *component,
					 enum snd_soc_bias_level level)
{
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	u16 pm2 = snd_soc_read(codec, WM8960_POWER2);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	u16 pm2 = snd_soc_component_read32(component, WM8960_POWER2);
	int reg, ret;

	switch (level) {
@@ -994,10 +994,10 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
		break;

	case SND_SOC_BIAS_PREPARE:
		switch (snd_soc_codec_get_bias_level(codec)) {
		switch (snd_soc_component_get_bias_level(component)) {
		case SND_SOC_BIAS_STANDBY:
			/* Enable anti pop mode */
			snd_soc_update_bits(codec, WM8960_APOP1,
			snd_soc_component_update_bits(component, WM8960_APOP1,
					    WM8960_POBCTRL | WM8960_SOFT_ST |
					    WM8960_BUFDCOPEN,
					    WM8960_POBCTRL | WM8960_SOFT_ST |
@@ -1011,20 +1011,20 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
				reg |= WM8960_PWR2_ROUT1;
			if (wm8960->out3 && wm8960->out3->power)
				reg |= WM8960_PWR2_OUT3;
			snd_soc_update_bits(codec, WM8960_POWER2,
			snd_soc_component_update_bits(component, WM8960_POWER2,
					    WM8960_PWR2_LOUT1 |
					    WM8960_PWR2_ROUT1 |
					    WM8960_PWR2_OUT3, reg);

			/* Enable VMID at 2*50k */
			snd_soc_update_bits(codec, WM8960_POWER1,
			snd_soc_component_update_bits(component, WM8960_POWER1,
					    WM8960_VMID_MASK, 0x80);

			/* Ramp */
			msleep(100);

			/* Enable VREF */
			snd_soc_update_bits(codec, WM8960_POWER1,
			snd_soc_component_update_bits(component, WM8960_POWER1,
					    WM8960_VREF, WM8960_VREF);

			msleep(100);
@@ -1032,14 +1032,14 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
			if (!IS_ERR(wm8960->mclk)) {
				ret = clk_prepare_enable(wm8960->mclk);
				if (ret) {
					dev_err(codec->dev,
					dev_err(component->dev,
						"Failed to enable MCLK: %d\n",
						ret);
					return ret;
				}
			}

			ret = wm8960_configure_clocking(codec);
			ret = wm8960_configure_clocking(component);
			if (ret)
				return ret;

@@ -1051,20 +1051,20 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
			 * disable the pll
			 */
			if (wm8960->clk_id == WM8960_SYSCLK_AUTO && (pm2 & 0x1))
				wm8960_set_pll(codec, 0, 0);
				wm8960_set_pll(component, 0, 0);

			if (!IS_ERR(wm8960->mclk))
				clk_disable_unprepare(wm8960->mclk);

			/* Enable anti-pop mode */
			snd_soc_update_bits(codec, WM8960_APOP1,
			snd_soc_component_update_bits(component, WM8960_APOP1,
					    WM8960_POBCTRL | WM8960_SOFT_ST |
					    WM8960_BUFDCOPEN,
					    WM8960_POBCTRL | WM8960_SOFT_ST |
					    WM8960_BUFDCOPEN);

			/* Disable VMID and VREF */
			snd_soc_update_bits(codec, WM8960_POWER1,
			snd_soc_component_update_bits(component, WM8960_POWER1,
					    WM8960_VREF | WM8960_VMID_MASK, 0);
			break;

@@ -1077,15 +1077,15 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
		break;

	case SND_SOC_BIAS_STANDBY:
		switch (snd_soc_codec_get_bias_level(codec)) {
		switch (snd_soc_component_get_bias_level(component)) {
		case SND_SOC_BIAS_PREPARE:
			/* Disable HP discharge */
			snd_soc_update_bits(codec, WM8960_APOP2,
			snd_soc_component_update_bits(component, WM8960_APOP2,
					    WM8960_DISOP | WM8960_DRES_MASK,
					    0);

			/* Disable anti-pop features */
			snd_soc_update_bits(codec, WM8960_APOP1,
			snd_soc_component_update_bits(component, WM8960_APOP1,
					    WM8960_POBCTRL | WM8960_SOFT_ST |
					    WM8960_BUFDCOPEN,
					    WM8960_POBCTRL | WM8960_SOFT_ST |
@@ -1184,7 +1184,7 @@ static int pll_factors(unsigned int source, unsigned int target,
	return 0;
}

static int wm8960_set_pll(struct snd_soc_codec *codec,
static int wm8960_set_pll(struct snd_soc_component *component,
		unsigned int freq_in, unsigned int freq_out)
{
	u16 reg;
@@ -1199,29 +1199,29 @@ static int wm8960_set_pll(struct snd_soc_codec *codec,

	/* Disable the PLL: even if we are changing the frequency the
	 * PLL needs to be disabled while we do so. */
	snd_soc_update_bits(codec, WM8960_CLOCK1, 0x1, 0);
	snd_soc_update_bits(codec, WM8960_POWER2, 0x1, 0);
	snd_soc_component_update_bits(component, WM8960_CLOCK1, 0x1, 0);
	snd_soc_component_update_bits(component, WM8960_POWER2, 0x1, 0);

	if (!freq_in || !freq_out)
		return 0;

	reg = snd_soc_read(codec, WM8960_PLL1) & ~0x3f;
	reg = snd_soc_component_read32(component, WM8960_PLL1) & ~0x3f;
	reg |= pll_div.pre_div << 4;
	reg |= pll_div.n;

	if (pll_div.k) {
		reg |= 0x20;

		snd_soc_write(codec, WM8960_PLL2, (pll_div.k >> 16) & 0xff);
		snd_soc_write(codec, WM8960_PLL3, (pll_div.k >> 8) & 0xff);
		snd_soc_write(codec, WM8960_PLL4, pll_div.k & 0xff);
		snd_soc_component_write(component, WM8960_PLL2, (pll_div.k >> 16) & 0xff);
		snd_soc_component_write(component, WM8960_PLL3, (pll_div.k >> 8) & 0xff);
		snd_soc_component_write(component, WM8960_PLL4, pll_div.k & 0xff);
	}
	snd_soc_write(codec, WM8960_PLL1, reg);
	snd_soc_component_write(component, WM8960_PLL1, reg);

	/* Turn it on */
	snd_soc_update_bits(codec, WM8960_POWER2, 0x1, 0x1);
	snd_soc_component_update_bits(component, WM8960_POWER2, 0x1, 0x1);
	msleep(250);
	snd_soc_update_bits(codec, WM8960_CLOCK1, 0x1, 0x1);
	snd_soc_component_update_bits(component, WM8960_CLOCK1, 0x1, 0x1);

	return 0;
}
@@ -1229,43 +1229,43 @@ static int wm8960_set_pll(struct snd_soc_codec *codec,
static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
		int source, unsigned int freq_in, unsigned int freq_out)
{
	struct snd_soc_codec *codec = codec_dai->codec;
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct snd_soc_component *component = codec_dai->component;
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);

	wm8960->freq_in = freq_in;

	if (pll_id == WM8960_SYSCLK_AUTO)
		return 0;

	return wm8960_set_pll(codec, freq_in, freq_out);
	return wm8960_set_pll(component, freq_in, freq_out);
}

static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
		int div_id, int div)
{
	struct snd_soc_codec *codec = codec_dai->codec;
	struct snd_soc_component *component = codec_dai->component;
	u16 reg;

	switch (div_id) {
	case WM8960_SYSCLKDIV:
		reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1f9;
		snd_soc_write(codec, WM8960_CLOCK1, reg | div);
		reg = snd_soc_component_read32(component, WM8960_CLOCK1) & 0x1f9;
		snd_soc_component_write(component, WM8960_CLOCK1, reg | div);
		break;
	case WM8960_DACDIV:
		reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1c7;
		snd_soc_write(codec, WM8960_CLOCK1, reg | div);
		reg = snd_soc_component_read32(component, WM8960_CLOCK1) & 0x1c7;
		snd_soc_component_write(component, WM8960_CLOCK1, reg | div);
		break;
	case WM8960_OPCLKDIV:
		reg = snd_soc_read(codec, WM8960_PLL1) & 0x03f;
		snd_soc_write(codec, WM8960_PLL1, reg | div);
		reg = snd_soc_component_read32(component, WM8960_PLL1) & 0x03f;
		snd_soc_component_write(component, WM8960_PLL1, reg | div);
		break;
	case WM8960_DCLKDIV:
		reg = snd_soc_read(codec, WM8960_CLOCK2) & 0x03f;
		snd_soc_write(codec, WM8960_CLOCK2, reg | div);
		reg = snd_soc_component_read32(component, WM8960_CLOCK2) & 0x03f;
		snd_soc_component_write(component, WM8960_CLOCK2, reg | div);
		break;
	case WM8960_TOCLKSEL:
		reg = snd_soc_read(codec, WM8960_ADDCTL1) & 0x1fd;
		snd_soc_write(codec, WM8960_ADDCTL1, reg | div);
		reg = snd_soc_component_read32(component, WM8960_ADDCTL1) & 0x1fd;
		snd_soc_component_write(component, WM8960_ADDCTL1, reg | div);
		break;
	default:
		return -EINVAL;
@@ -1274,27 +1274,27 @@ static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
	return 0;
}

static int wm8960_set_bias_level(struct snd_soc_codec *codec,
static int wm8960_set_bias_level(struct snd_soc_component *component,
				 enum snd_soc_bias_level level)
{
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);

	return wm8960->set_bias_level(codec, level);
	return wm8960->set_bias_level(component, level);
}

static int wm8960_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
					unsigned int freq, int dir)
{
	struct snd_soc_codec *codec = dai->codec;
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct snd_soc_component *component = dai->component;
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);

	switch (clk_id) {
	case WM8960_SYSCLK_MCLK:
		snd_soc_update_bits(codec, WM8960_CLOCK1,
		snd_soc_component_update_bits(component, WM8960_CLOCK1,
					0x1, WM8960_SYSCLK_MCLK);
		break;
	case WM8960_SYSCLK_PLL:
		snd_soc_update_bits(codec, WM8960_CLOCK1,
		snd_soc_component_update_bits(component, WM8960_CLOCK1,
					0x1, WM8960_SYSCLK_PLL);
		break;
	case WM8960_SYSCLK_AUTO:
@@ -1343,9 +1343,9 @@ static struct snd_soc_dai_driver wm8960_dai = {
	.symmetric_rates = 1,
};

static int wm8960_probe(struct snd_soc_codec *codec)
static int wm8960_probe(struct snd_soc_component *component)
{
	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
	struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
	struct wm8960_data *pdata = &wm8960->pdata;

	if (pdata->capless)
@@ -1353,17 +1353,21 @@ static int wm8960_probe(struct snd_soc_codec *codec)
	else
		wm8960->set_bias_level = wm8960_set_bias_level_out3;

	snd_soc_add_codec_controls(codec, wm8960_snd_controls,
	snd_soc_add_component_controls(component, wm8960_snd_controls,
				     ARRAY_SIZE(wm8960_snd_controls));
	wm8960_add_widgets(codec);
	wm8960_add_widgets(component);

	return 0;
}

static const struct snd_soc_codec_driver soc_codec_dev_wm8960 = {
static const struct snd_soc_component_driver soc_component_dev_wm8960 = {
	.probe			= wm8960_probe,
	.set_bias_level		= wm8960_set_bias_level,
	.suspend_bias_off = true,
	.suspend_bias_off	= 1,
	.idle_bias_on		= 1,
	.use_pmdown_time	= 1,
	.endianness		= 1,
	.non_legacy_dai_naming	= 1,
};

static const struct regmap_config wm8960_regmap = {
@@ -1447,15 +1451,14 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,

	i2c_set_clientdata(i2c, wm8960);

	ret = snd_soc_register_codec(&i2c->dev,
			&soc_codec_dev_wm8960, &wm8960_dai, 1);
	ret = devm_snd_soc_register_component(&i2c->dev,
			&soc_component_dev_wm8960, &wm8960_dai, 1);

	return ret;
}

static int wm8960_i2c_remove(struct i2c_client *client)
{
	snd_soc_unregister_codec(&client->dev);
	return 0;
}

+117 −124

File changed.

Preview size limit exceeded, changes collapsed.

+198 −199

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -3779,6 +3779,6 @@
#define WM8962_VSS_ENA_SHIFT                         0  /* VSS_ENA */
#define WM8962_VSS_ENA_WIDTH                         1  /* VSS_ENA */

int wm8962_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack);
int wm8962_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack);

#endif
+51 −57
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ static const struct reg_default wm8971_reg_defaults[] = {
	{ 42, 0x0079 },
};

#define wm8971_reset(c)	snd_soc_write(c, WM8971_RESET, 0)
#define wm8971_reset(c)	snd_soc_component_write(c, WM8971_RESET, 0)

/* WM8971 Controls */
static const char *wm8971_bass[] = { "Linear Control", "Adaptive Boost" };
@@ -433,8 +433,8 @@ static int get_coeff(int mclk, int rate)
static int wm8971_set_dai_sysclk(struct snd_soc_dai *codec_dai,
		int clk_id, unsigned int freq, int dir)
{
	struct snd_soc_codec *codec = codec_dai->codec;
	struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
	struct snd_soc_component *component = codec_dai->component;
	struct wm8971_priv *wm8971 = snd_soc_component_get_drvdata(component);

	switch (freq) {
	case 11289600:
@@ -451,7 +451,7 @@ static int wm8971_set_dai_sysclk(struct snd_soc_dai *codec_dai,
static int wm8971_set_dai_fmt(struct snd_soc_dai *codec_dai,
		unsigned int fmt)
{
	struct snd_soc_codec *codec = codec_dai->codec;
	struct snd_soc_component *component = codec_dai->component;
	u16 iface = 0;

	/* set master/slave audio interface */
@@ -502,7 +502,7 @@ static int wm8971_set_dai_fmt(struct snd_soc_dai *codec_dai,
		return -EINVAL;
	}

	snd_soc_write(codec, WM8971_IFACE, iface);
	snd_soc_component_write(component, WM8971_IFACE, iface);
	return 0;
}

@@ -510,10 +510,10 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream,
	struct snd_pcm_hw_params *params,
	struct snd_soc_dai *dai)
{
	struct snd_soc_codec *codec = dai->codec;
	struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
	u16 iface = snd_soc_read(codec, WM8971_IFACE) & 0x1f3;
	u16 srate = snd_soc_read(codec, WM8971_SRATE) & 0x1c0;
	struct snd_soc_component *component = dai->component;
	struct wm8971_priv *wm8971 = snd_soc_component_get_drvdata(component);
	u16 iface = snd_soc_component_read32(component, WM8971_IFACE) & 0x1f3;
	u16 srate = snd_soc_component_read32(component, WM8971_SRATE) & 0x1c0;
	int coeff = get_coeff(wm8971->sysclk, params_rate(params));

	/* bit size */
@@ -532,9 +532,9 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream,
	}

	/* set iface & srate */
	snd_soc_write(codec, WM8971_IFACE, iface);
	snd_soc_component_write(component, WM8971_IFACE, iface);
	if (coeff >= 0)
		snd_soc_write(codec, WM8971_SRATE, srate |
		snd_soc_component_write(component, WM8971_SRATE, srate |
			(coeff_div[coeff].sr << 1) | coeff_div[coeff].usb);

	return 0;
@@ -542,13 +542,13 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream,

static int wm8971_mute(struct snd_soc_dai *dai, int mute)
{
	struct snd_soc_codec *codec = dai->codec;
	u16 mute_reg = snd_soc_read(codec, WM8971_ADCDAC) & 0xfff7;
	struct snd_soc_component *component = dai->component;
	u16 mute_reg = snd_soc_component_read32(component, WM8971_ADCDAC) & 0xfff7;

	if (mute)
		snd_soc_write(codec, WM8971_ADCDAC, mute_reg | 0x8);
		snd_soc_component_write(component, WM8971_ADCDAC, mute_reg | 0x8);
	else
		snd_soc_write(codec, WM8971_ADCDAC, mute_reg);
		snd_soc_component_write(component, WM8971_ADCDAC, mute_reg);
	return 0;
}

@@ -561,37 +561,37 @@ static void wm8971_charge_work(struct work_struct *work)
	regmap_update_bits(wm8971->regmap, WM8971_PWR1, 0x0180, 0x0100);
}

static int wm8971_set_bias_level(struct snd_soc_codec *codec,
static int wm8971_set_bias_level(struct snd_soc_component *component,
	enum snd_soc_bias_level level)
{
	struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
	u16 pwr_reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e;
	struct wm8971_priv *wm8971 = snd_soc_component_get_drvdata(component);
	u16 pwr_reg = snd_soc_component_read32(component, WM8971_PWR1) & 0xfe3e;

	switch (level) {
	case SND_SOC_BIAS_ON:
		/* set vmid to 50k and unmute dac */
		snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x00c1);
		snd_soc_component_write(component, WM8971_PWR1, pwr_reg | 0x00c1);
		break;
	case SND_SOC_BIAS_PREPARE:
		/* Wait until fully charged */
		flush_delayed_work(&wm8971->charge_work);
		break;
	case SND_SOC_BIAS_STANDBY:
		if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
			snd_soc_cache_sync(codec);
		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
			snd_soc_component_cache_sync(component);
			/* charge output caps - set vmid to 5k for quick power up */
			snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x01c0);
			snd_soc_component_write(component, WM8971_PWR1, pwr_reg | 0x01c0);
			queue_delayed_work(system_power_efficient_wq,
				&wm8971->charge_work, msecs_to_jiffies(1000));
		} else {
			/* mute dac and set vmid to 500k, enable VREF */
			snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x0140);
			snd_soc_component_write(component, WM8971_PWR1, pwr_reg | 0x0140);
		}

		break;
	case SND_SOC_BIAS_OFF:
		cancel_delayed_work_sync(&wm8971->charge_work);
		snd_soc_write(codec, WM8971_PWR1, 0x0001);
		snd_soc_component_write(component, WM8971_PWR1, 0x0001);
		break;
	}
	return 0;
@@ -628,40 +628,41 @@ static struct snd_soc_dai_driver wm8971_dai = {
	.ops = &wm8971_dai_ops,
};

static int wm8971_probe(struct snd_soc_codec *codec)
static int wm8971_probe(struct snd_soc_component *component)
{
	struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
	struct wm8971_priv *wm8971 = snd_soc_component_get_drvdata(component);

	INIT_DELAYED_WORK(&wm8971->charge_work, wm8971_charge_work);

	wm8971_reset(codec);
	wm8971_reset(component);

	/* set the update bits */
	snd_soc_update_bits(codec, WM8971_LDAC, 0x0100, 0x0100);
	snd_soc_update_bits(codec, WM8971_RDAC, 0x0100, 0x0100);
	snd_soc_update_bits(codec, WM8971_LOUT1V, 0x0100, 0x0100);
	snd_soc_update_bits(codec, WM8971_ROUT1V, 0x0100, 0x0100);
	snd_soc_update_bits(codec, WM8971_LOUT2V, 0x0100, 0x0100);
	snd_soc_update_bits(codec, WM8971_ROUT2V, 0x0100, 0x0100);
	snd_soc_update_bits(codec, WM8971_LINVOL, 0x0100, 0x0100);
	snd_soc_update_bits(codec, WM8971_RINVOL, 0x0100, 0x0100);
	snd_soc_component_update_bits(component, WM8971_LDAC, 0x0100, 0x0100);
	snd_soc_component_update_bits(component, WM8971_RDAC, 0x0100, 0x0100);
	snd_soc_component_update_bits(component, WM8971_LOUT1V, 0x0100, 0x0100);
	snd_soc_component_update_bits(component, WM8971_ROUT1V, 0x0100, 0x0100);
	snd_soc_component_update_bits(component, WM8971_LOUT2V, 0x0100, 0x0100);
	snd_soc_component_update_bits(component, WM8971_ROUT2V, 0x0100, 0x0100);
	snd_soc_component_update_bits(component, WM8971_LINVOL, 0x0100, 0x0100);
	snd_soc_component_update_bits(component, WM8971_RINVOL, 0x0100, 0x0100);

	return 0;
}

static const struct snd_soc_codec_driver soc_codec_dev_wm8971 = {
static const struct snd_soc_component_driver soc_component_dev_wm8971 = {
	.probe			= wm8971_probe,
	.set_bias_level		= wm8971_set_bias_level,
	.suspend_bias_off = true,

	.component_driver = {
	.controls		= wm8971_snd_controls,
	.num_controls		= ARRAY_SIZE(wm8971_snd_controls),
	.dapm_widgets		= wm8971_dapm_widgets,
	.num_dapm_widgets	= ARRAY_SIZE(wm8971_dapm_widgets),
	.dapm_routes		= wm8971_dapm_routes,
	.num_dapm_routes	= ARRAY_SIZE(wm8971_dapm_routes),
	},
	.suspend_bias_off	= 1,
	.idle_bias_on		= 1,
	.use_pmdown_time	= 1,
	.endianness		= 1,
	.non_legacy_dai_naming	= 1,
};

static const struct regmap_config wm8971_regmap = {
@@ -691,18 +692,12 @@ static int wm8971_i2c_probe(struct i2c_client *i2c,

	i2c_set_clientdata(i2c, wm8971);

	ret = snd_soc_register_codec(&i2c->dev,
			&soc_codec_dev_wm8971, &wm8971_dai, 1);
	ret = devm_snd_soc_register_component(&i2c->dev,
			&soc_component_dev_wm8971, &wm8971_dai, 1);

	return ret;
}

static int wm8971_i2c_remove(struct i2c_client *client)
{
	snd_soc_unregister_codec(&client->dev);
	return 0;
}

static const struct i2c_device_id wm8971_i2c_id[] = {
	{ "wm8971", 0 },
	{ }
@@ -714,7 +709,6 @@ static struct i2c_driver wm8971_i2c_driver = {
		.name = "wm8971",
	},
	.probe =    wm8971_i2c_probe,
	.remove =   wm8971_i2c_remove,
	.id_table = wm8971_i2c_id,
};

Loading