diff options
Diffstat (limited to 'sound/soc/codecs/tlv320aic31xx.c')
-rw-r--r-- | sound/soc/codecs/tlv320aic31xx.c | 339 |
1 files changed, 207 insertions, 132 deletions
diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c index 858cb8b..bf92d36 100644 --- a/sound/soc/codecs/tlv320aic31xx.c +++ b/sound/soc/codecs/tlv320aic31xx.c @@ -153,7 +153,7 @@ struct aic31xx_disable_nb { }; struct aic31xx_priv { - struct snd_soc_codec *codec; + struct snd_soc_component *component; u8 i2c_regs_status; struct device *dev; struct regmap *regmap; @@ -166,6 +166,7 @@ struct aic31xx_priv { unsigned int sysclk; u8 p_div; int rate_div_line; + bool master_dapm_route_applied; }; struct aic31xx_rate_divs { @@ -348,8 +349,8 @@ static int aic31xx_wait_bits(struct aic31xx_priv *aic31xx, unsigned int reg, static int aic31xx_dapm_power_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); unsigned int reg = AIC31XX_DACFLAG1; unsigned int mask; @@ -377,7 +378,7 @@ static int aic31xx_dapm_power_event(struct snd_soc_dapm_widget *w, reg = AIC31XX_ADCFLAG; break; default: - dev_err(codec->dev, "Unknown widget '%s' calling %s\n", + dev_err(component->dev, "Unknown widget '%s' calling %s\n", w->name, __func__); return -EINVAL; } @@ -388,7 +389,7 @@ static int aic31xx_dapm_power_event(struct snd_soc_dapm_widget *w, case SND_SOC_DAPM_POST_PMD: return aic31xx_wait_bits(aic31xx, reg, mask, 0, 5000, 100); default: - dev_dbg(codec->dev, + dev_dbg(component->dev, "Unhandled dapm widget event %d from %s\n", event, w->name); } @@ -444,30 +445,30 @@ static const struct snd_kcontrol_new aic31xx_dapm_spr_switch = static int mic_bias_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_POST_PMU: /* change mic bias voltage to user defined */ - snd_soc_update_bits(codec, AIC31XX_MICBIAS, + snd_soc_component_update_bits(component, AIC31XX_MICBIAS, AIC31XX_MICBIAS_MASK, aic31xx->micbias_vg << AIC31XX_MICBIAS_SHIFT); - dev_dbg(codec->dev, "%s: turned on\n", __func__); + dev_dbg(component->dev, "%s: turned on\n", __func__); break; case SND_SOC_DAPM_PRE_PMD: /* turn mic bias off */ - snd_soc_update_bits(codec, AIC31XX_MICBIAS, + snd_soc_component_update_bits(component, AIC31XX_MICBIAS, AIC31XX_MICBIAS_MASK, 0); - dev_dbg(codec->dev, "%s: turned off\n", __func__); + dev_dbg(component->dev, "%s: turned off\n", __func__); break; } return 0; } static const struct snd_soc_dapm_widget common31xx_dapm_widgets[] = { - SND_SOC_DAPM_AIF_IN("DAC IN", "DAC Playback", 0, SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_AIF_IN("AIF IN", "Playback", 0, SND_SOC_NOPM, 0, 0), SND_SOC_DAPM_MUX("DAC Left Input", SND_SOC_NOPM, 0, 0, &ldac_in_control), @@ -500,6 +501,10 @@ static const struct snd_soc_dapm_widget common31xx_dapm_widgets[] = { SND_SOC_DAPM_SUPPLY("MICBIAS", SND_SOC_NOPM, 0, 0, mic_bias_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), + /* Keep BCLK/WCLK enabled even if DAC/ADC is powered down */ + SND_SOC_DAPM_SUPPLY("Activate I2S clocks", AIC31XX_IFACE2, 2, 0, + NULL, 0), + /* Outputs */ SND_SOC_DAPM_OUTPUT("HPL"), SND_SOC_DAPM_OUTPUT("HPR"), @@ -552,6 +557,8 @@ static const struct snd_soc_dapm_widget aic31xx_dapm_widgets[] = { SND_SOC_DAPM_MIXER("Output Right", SND_SOC_NOPM, 0, 0, aic31xx_right_output_switches, ARRAY_SIZE(aic31xx_right_output_switches)), + + SND_SOC_DAPM_AIF_OUT("AIF OUT", "Capture", 0, SND_SOC_NOPM, 0, 0), }; static const struct snd_soc_dapm_widget aic311x_dapm_widgets[] = { @@ -583,12 +590,12 @@ static const struct snd_soc_dapm_widget aic310x_dapm_widgets[] = { static const struct snd_soc_dapm_route common31xx_audio_map[] = { /* DAC Input Routing */ - {"DAC Left Input", "Left Data", "DAC IN"}, - {"DAC Left Input", "Right Data", "DAC IN"}, - {"DAC Left Input", "Mono", "DAC IN"}, - {"DAC Right Input", "Left Data", "DAC IN"}, - {"DAC Right Input", "Right Data", "DAC IN"}, - {"DAC Right Input", "Mono", "DAC IN"}, + {"DAC Left Input", "Left Data", "AIF IN"}, + {"DAC Left Input", "Right Data", "AIF IN"}, + {"DAC Left Input", "Mono", "AIF IN"}, + {"DAC Right Input", "Left Data", "AIF IN"}, + {"DAC Right Input", "Right Data", "AIF IN"}, + {"DAC Right Input", "Mono", "AIF IN"}, {"DAC Left", NULL, "DAC Left Input"}, {"DAC Right", NULL, "DAC Right Input"}, @@ -639,6 +646,8 @@ aic31xx_audio_map[] = { {"ADC", NULL, "MIC_GAIN_CTL"}, + {"AIF OUT", NULL, "ADC"}, + /* Left Output */ {"Output Left", "From Left DAC", "DAC Left"}, {"Output Left", "From MIC1LP", "MIC1LP"}, @@ -670,34 +679,61 @@ aic310x_audio_map[] = { {"SPK", NULL, "SPK ClassD"}, }; -static int aic31xx_add_controls(struct snd_soc_codec *codec) +/* + * Always connected DAPM routes for codec clock master modes. + * If the codec is the master on the I2S bus, we need to power up components + * to have valid DAC_CLK. + * + * In order to have the I2S clocks on the bus either the DACs/ADC need to be + * enabled, or the P0/R29/D2 (Keep bclk/wclk in power down) need to be set. + * + * Otherwise the codec will not generate clocks on the bus. + */ +static const struct snd_soc_dapm_route +common31xx_cm_audio_map[] = { + {"HPL", NULL, "AIF IN"}, + {"HPR", NULL, "AIF IN"}, + + {"AIF IN", NULL, "Activate I2S clocks"}, +}; + +static const struct snd_soc_dapm_route +aic31xx_cm_audio_map[] = { + {"AIF OUT", NULL, "MIC1LP"}, + {"AIF OUT", NULL, "MIC1RP"}, + {"AIF OUT", NULL, "MIC1LM"}, + + {"AIF OUT", NULL, "Activate I2S clocks"}, +}; + +static int aic31xx_add_controls(struct snd_soc_component *component) { int ret = 0; - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); if (!(aic31xx->codec_type & DAC31XX_BIT)) - ret = snd_soc_add_codec_controls( - codec, aic31xx_snd_controls, + ret = snd_soc_add_component_controls( + component, aic31xx_snd_controls, ARRAY_SIZE(aic31xx_snd_controls)); if (ret) return ret; if (aic31xx->codec_type & AIC31XX_STEREO_CLASS_D_BIT) - ret = snd_soc_add_codec_controls( - codec, aic311x_snd_controls, + ret = snd_soc_add_component_controls( + component, aic311x_snd_controls, ARRAY_SIZE(aic311x_snd_controls)); else - ret = snd_soc_add_codec_controls( - codec, aic310x_snd_controls, + ret = snd_soc_add_component_controls( + component, aic310x_snd_controls, ARRAY_SIZE(aic310x_snd_controls)); return ret; } -static int aic31xx_add_widgets(struct snd_soc_codec *codec) +static int aic31xx_add_widgets(struct snd_soc_component *component) { - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); int ret = 0; if (aic31xx->codec_type & DAC31XX_BIT) { @@ -751,10 +787,10 @@ static int aic31xx_add_widgets(struct snd_soc_codec *codec) return 0; } -static int aic31xx_setup_pll(struct snd_soc_codec *codec, +static int aic31xx_setup_pll(struct snd_soc_component *component, struct snd_pcm_hw_params *params) { - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); int bclk_score = snd_soc_params_to_frame_size(params); int mclk_p; int bclk_n = 0; @@ -762,15 +798,15 @@ static int aic31xx_setup_pll(struct snd_soc_codec *codec, int i; if (!aic31xx->sysclk || !aic31xx->p_div) { - dev_err(codec->dev, "Master clock not supplied\n"); + dev_err(component->dev, "Master clock not supplied\n"); return -EINVAL; } mclk_p = aic31xx->sysclk / aic31xx->p_div; /* Use PLL as CODEC_CLKIN and DAC_CLK as BDIV_CLKIN */ - snd_soc_update_bits(codec, AIC31XX_CLKMUX, + snd_soc_component_update_bits(component, AIC31XX_CLKMUX, AIC31XX_CODEC_CLKIN_MASK, AIC31XX_CODEC_CLKIN_PLL); - snd_soc_update_bits(codec, AIC31XX_IFACE2, + snd_soc_component_update_bits(component, AIC31XX_IFACE2, AIC31XX_BDIVCLK_MASK, AIC31XX_DAC2BCLK); for (i = 0; i < ARRAY_SIZE(aic31xx_divs); i++) { @@ -789,14 +825,14 @@ static int aic31xx_setup_pll(struct snd_soc_codec *codec, } if (match == -1) { - dev_err(codec->dev, + dev_err(component->dev, "%s: Sample rate (%u) and format not supported\n", __func__, params_rate(params)); /* See bellow for details how fix this. */ return -EINVAL; } if (bclk_score != 0) { - dev_warn(codec->dev, "Can not produce exact bitclock"); + dev_warn(component->dev, "Can not produce exact bitclock"); /* This is fine if using dsp format, but if using i2s there may be trouble. To fix the issue edit the aic31xx_divs table for your mclk and sample @@ -808,39 +844,39 @@ static int aic31xx_setup_pll(struct snd_soc_codec *codec, i = match; /* PLL configuration */ - snd_soc_update_bits(codec, AIC31XX_PLLPR, AIC31XX_PLL_MASK, + snd_soc_component_update_bits(component, AIC31XX_PLLPR, AIC31XX_PLL_MASK, (aic31xx->p_div << 4) | 0x01); - snd_soc_write(codec, AIC31XX_PLLJ, aic31xx_divs[i].pll_j); + snd_soc_component_write(component, AIC31XX_PLLJ, aic31xx_divs[i].pll_j); - snd_soc_write(codec, AIC31XX_PLLDMSB, + snd_soc_component_write(component, AIC31XX_PLLDMSB, aic31xx_divs[i].pll_d >> 8); - snd_soc_write(codec, AIC31XX_PLLDLSB, + snd_soc_component_write(component, AIC31XX_PLLDLSB, aic31xx_divs[i].pll_d & 0xff); /* DAC dividers configuration */ - snd_soc_update_bits(codec, AIC31XX_NDAC, AIC31XX_PLL_MASK, + snd_soc_component_update_bits(component, AIC31XX_NDAC, AIC31XX_PLL_MASK, aic31xx_divs[i].ndac); - snd_soc_update_bits(codec, AIC31XX_MDAC, AIC31XX_PLL_MASK, + snd_soc_component_update_bits(component, AIC31XX_MDAC, AIC31XX_PLL_MASK, aic31xx_divs[i].mdac); - snd_soc_write(codec, AIC31XX_DOSRMSB, aic31xx_divs[i].dosr >> 8); - snd_soc_write(codec, AIC31XX_DOSRLSB, aic31xx_divs[i].dosr & 0xff); + snd_soc_component_write(component, AIC31XX_DOSRMSB, aic31xx_divs[i].dosr >> 8); + snd_soc_component_write(component, AIC31XX_DOSRLSB, aic31xx_divs[i].dosr & 0xff); /* ADC dividers configuration. Write reset value 1 if not used. */ - snd_soc_update_bits(codec, AIC31XX_NADC, AIC31XX_PLL_MASK, + snd_soc_component_update_bits(component, AIC31XX_NADC, AIC31XX_PLL_MASK, aic31xx_divs[i].nadc ? aic31xx_divs[i].nadc : 1); - snd_soc_update_bits(codec, AIC31XX_MADC, AIC31XX_PLL_MASK, + snd_soc_component_update_bits(component, AIC31XX_MADC, AIC31XX_PLL_MASK, aic31xx_divs[i].madc ? aic31xx_divs[i].madc : 1); - snd_soc_write(codec, AIC31XX_AOSR, aic31xx_divs[i].aosr); + snd_soc_component_write(component, AIC31XX_AOSR, aic31xx_divs[i].aosr); /* Bit clock divider configuration. */ - snd_soc_update_bits(codec, AIC31XX_BCLKN, + snd_soc_component_update_bits(component, AIC31XX_BCLKN, AIC31XX_PLL_MASK, bclk_n); aic31xx->rate_div_line = i; - dev_dbg(codec->dev, + dev_dbg(component->dev, "pll %d.%04d/%d dosr %d n %d m %d aosr %d n %d m %d bclk_n %d\n", aic31xx_divs[i].pll_j, aic31xx_divs[i].pll_d, @@ -861,10 +897,10 @@ static int aic31xx_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 snd_soc_component *component = dai->component; u8 data = 0; - dev_dbg(codec->dev, "## %s: width %d rate %d\n", + dev_dbg(component->dev, "## %s: width %d rate %d\n", __func__, params_width(params), params_rate(params)); @@ -884,43 +920,90 @@ static int aic31xx_hw_params(struct snd_pcm_substream *substream, AIC31XX_IFACE1_DATALEN_SHIFT); break; default: - dev_err(codec->dev, "%s: Unsupported width %d\n", + dev_err(component->dev, "%s: Unsupported width %d\n", __func__, params_width(params)); return -EINVAL; } - snd_soc_update_bits(codec, AIC31XX_IFACE1, + snd_soc_component_update_bits(component, AIC31XX_IFACE1, AIC31XX_IFACE1_DATALEN_MASK, data); - return aic31xx_setup_pll(codec, params); + return aic31xx_setup_pll(component, params); } static int aic31xx_dac_mute(struct snd_soc_dai *codec_dai, int mute) { - struct snd_soc_codec *codec = codec_dai->codec; + struct snd_soc_component *component = codec_dai->component; if (mute) { - snd_soc_update_bits(codec, AIC31XX_DACMUTE, + snd_soc_component_update_bits(component, AIC31XX_DACMUTE, AIC31XX_DACMUTE_MASK, AIC31XX_DACMUTE_MASK); } else { - snd_soc_update_bits(codec, AIC31XX_DACMUTE, + snd_soc_component_update_bits(component, AIC31XX_DACMUTE, AIC31XX_DACMUTE_MASK, 0x0); } return 0; } +static int aic31xx_clock_master_routes(struct snd_soc_component *component, + unsigned int fmt) +{ + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); + int ret; + + fmt &= SND_SOC_DAIFMT_MASTER_MASK; + if (fmt == SND_SOC_DAIFMT_CBS_CFS && + aic31xx->master_dapm_route_applied) { + /* + * Remove the DAPM route(s) for codec clock master modes, + * if applied + */ + ret = snd_soc_dapm_del_routes(dapm, common31xx_cm_audio_map, + ARRAY_SIZE(common31xx_cm_audio_map)); + if (!ret && !(aic31xx->codec_type & DAC31XX_BIT)) + ret = snd_soc_dapm_del_routes(dapm, + aic31xx_cm_audio_map, + ARRAY_SIZE(aic31xx_cm_audio_map)); + + if (ret) + return ret; + + aic31xx->master_dapm_route_applied = false; + } else if (fmt != SND_SOC_DAIFMT_CBS_CFS && + !aic31xx->master_dapm_route_applied) { + /* + * Add the needed DAPM route(s) for codec clock master modes, + * if it is not done already + */ + ret = snd_soc_dapm_add_routes(dapm, common31xx_cm_audio_map, + ARRAY_SIZE(common31xx_cm_audio_map)); + if (!ret && !(aic31xx->codec_type & DAC31XX_BIT)) + ret = snd_soc_dapm_add_routes(dapm, + aic31xx_cm_audio_map, + ARRAY_SIZE(aic31xx_cm_audio_map)); + + if (ret) + return ret; + + aic31xx->master_dapm_route_applied = true; + } + + return 0; +} + static int aic31xx_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; u8 iface_reg1 = 0; u8 iface_reg2 = 0; u8 dsp_a_val = 0; - dev_dbg(codec->dev, "## %s: fmt = 0x%x\n", __func__, fmt); + dev_dbg(component->dev, "## %s: fmt = 0x%x\n", __func__, fmt); /* set master/slave audio interface */ switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { @@ -936,7 +1019,7 @@ static int aic31xx_set_dai_fmt(struct snd_soc_dai *codec_dai, case SND_SOC_DAIFMT_CBS_CFS: break; default: - dev_err(codec->dev, "Invalid DAI master/slave interface\n"); + dev_err(component->dev, "Invalid DAI master/slave interface\n"); return -EINVAL; } @@ -948,7 +1031,7 @@ static int aic31xx_set_dai_fmt(struct snd_soc_dai *codec_dai, iface_reg2 |= AIC31XX_BCLKINV_MASK; break; default: - dev_err(codec->dev, "Invalid DAI clock signal polarity\n"); + dev_err(component->dev, "Invalid DAI clock signal polarity\n"); return -EINVAL; } @@ -977,32 +1060,32 @@ static int aic31xx_set_dai_fmt(struct snd_soc_dai *codec_dai, AIC31XX_IFACE1_DATATYPE_SHIFT); break; default: - dev_err(codec->dev, "Invalid DAI interface format\n"); + dev_err(component->dev, "Invalid DAI interface format\n"); return -EINVAL; } - snd_soc_update_bits(codec, AIC31XX_IFACE1, + snd_soc_component_update_bits(component, AIC31XX_IFACE1, AIC31XX_IFACE1_DATATYPE_MASK | AIC31XX_IFACE1_MASTER_MASK, iface_reg1); - snd_soc_update_bits(codec, AIC31XX_DATA_OFFSET, + snd_soc_component_update_bits(component, AIC31XX_DATA_OFFSET, AIC31XX_DATA_OFFSET_MASK, dsp_a_val); - snd_soc_update_bits(codec, AIC31XX_IFACE2, + snd_soc_component_update_bits(component, AIC31XX_IFACE2, AIC31XX_BCLKINV_MASK, iface_reg2); - return 0; + return aic31xx_clock_master_routes(component, fmt); } static int aic31xx_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 aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); int i; - dev_dbg(codec->dev, "## %s: clk_id = %d, freq = %d, dir = %d\n", + dev_dbg(component->dev, "## %s: clk_id = %d, freq = %d, dir = %d\n", __func__, clk_id, freq, dir); for (i = 1; i < 8; i++) @@ -1025,7 +1108,7 @@ static int aic31xx_set_dai_sysclk(struct snd_soc_dai *codec_dai, } /* set clock on MCLK, BCLK, or GPIO1 as PLL input */ - snd_soc_update_bits(codec, AIC31XX_CLKMUX, AIC31XX_PLL_CLKIN_MASK, + snd_soc_component_update_bits(component, AIC31XX_CLKMUX, AIC31XX_PLL_CLKIN_MASK, clk_id << AIC31XX_PLL_CLKIN_SHIFT); aic31xx->sysclk = freq; @@ -1071,42 +1154,42 @@ static int aic31xx_reset(struct aic31xx_priv *aic31xx) return ret; } -static void aic31xx_clk_on(struct snd_soc_codec *codec) +static void aic31xx_clk_on(struct snd_soc_component *component) { - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); u8 mask = AIC31XX_PM_MASK; u8 on = AIC31XX_PM_MASK; - dev_dbg(codec->dev, "codec clock -> on (rate %d)\n", + dev_dbg(component->dev, "codec clock -> on (rate %d)\n", aic31xx_divs[aic31xx->rate_div_line].rate); - snd_soc_update_bits(codec, AIC31XX_PLLPR, mask, on); + snd_soc_component_update_bits(component, AIC31XX_PLLPR, mask, on); mdelay(10); - snd_soc_update_bits(codec, AIC31XX_NDAC, mask, on); - snd_soc_update_bits(codec, AIC31XX_MDAC, mask, on); + snd_soc_component_update_bits(component, AIC31XX_NDAC, mask, on); + snd_soc_component_update_bits(component, AIC31XX_MDAC, mask, on); if (aic31xx_divs[aic31xx->rate_div_line].nadc) - snd_soc_update_bits(codec, AIC31XX_NADC, mask, on); + snd_soc_component_update_bits(component, AIC31XX_NADC, mask, on); if (aic31xx_divs[aic31xx->rate_div_line].madc) - snd_soc_update_bits(codec, AIC31XX_MADC, mask, on); - snd_soc_update_bits(codec, AIC31XX_BCLKN, mask, on); + snd_soc_component_update_bits(component, AIC31XX_MADC, mask, on); + snd_soc_component_update_bits(component, AIC31XX_BCLKN, mask, on); } -static void aic31xx_clk_off(struct snd_soc_codec *codec) +static void aic31xx_clk_off(struct snd_soc_component *component) { u8 mask = AIC31XX_PM_MASK; u8 off = 0; - dev_dbg(codec->dev, "codec clock -> off\n"); - snd_soc_update_bits(codec, AIC31XX_BCLKN, mask, off); - snd_soc_update_bits(codec, AIC31XX_MADC, mask, off); - snd_soc_update_bits(codec, AIC31XX_NADC, mask, off); - snd_soc_update_bits(codec, AIC31XX_MDAC, mask, off); - snd_soc_update_bits(codec, AIC31XX_NDAC, mask, off); - snd_soc_update_bits(codec, AIC31XX_PLLPR, mask, off); + dev_dbg(component->dev, "codec clock -> off\n"); + snd_soc_component_update_bits(component, AIC31XX_BCLKN, mask, off); + snd_soc_component_update_bits(component, AIC31XX_MADC, mask, off); + snd_soc_component_update_bits(component, AIC31XX_NADC, mask, off); + snd_soc_component_update_bits(component, AIC31XX_MDAC, mask, off); + snd_soc_component_update_bits(component, AIC31XX_NDAC, mask, off); + snd_soc_component_update_bits(component, AIC31XX_PLLPR, mask, off); } -static int aic31xx_power_on(struct snd_soc_codec *codec) +static int aic31xx_power_on(struct snd_soc_component *component) { - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); int ret; ret = regulator_bulk_enable(ARRAY_SIZE(aic31xx->supplies), @@ -1123,7 +1206,7 @@ static int aic31xx_power_on(struct snd_soc_codec *codec) ret = regcache_sync(aic31xx->regmap); if (ret) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to restore cache: %d\n", ret); regcache_cache_only(aic31xx->regmap, true); regulator_bulk_disable(ARRAY_SIZE(aic31xx->supplies), @@ -1134,57 +1217,57 @@ static int aic31xx_power_on(struct snd_soc_codec *codec) return 0; } -static void aic31xx_power_off(struct snd_soc_codec *codec) +static void aic31xx_power_off(struct snd_soc_component *component) { - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); regcache_cache_only(aic31xx->regmap, true); regulator_bulk_disable(ARRAY_SIZE(aic31xx->supplies), aic31xx->supplies); } -static int aic31xx_set_bias_level(struct snd_soc_codec *codec, +static int aic31xx_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - dev_dbg(codec->dev, "## %s: %d -> %d\n", __func__, - snd_soc_codec_get_bias_level(codec), level); + dev_dbg(component->dev, "## %s: %d -> %d\n", __func__, + snd_soc_component_get_bias_level(component), level); switch (level) { case SND_SOC_BIAS_ON: break; case SND_SOC_BIAS_PREPARE: - if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY) - aic31xx_clk_on(codec); + if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY) + aic31xx_clk_on(component); 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_OFF: - aic31xx_power_on(codec); + aic31xx_power_on(component); break; case SND_SOC_BIAS_PREPARE: - aic31xx_clk_off(codec); + aic31xx_clk_off(component); break; default: BUG(); } break; case SND_SOC_BIAS_OFF: - if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY) - aic31xx_power_off(codec); + if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY) + aic31xx_power_off(component); break; } return 0; } -static int aic31xx_codec_probe(struct snd_soc_codec *codec) +static int aic31xx_codec_probe(struct snd_soc_component *component) { - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); int i, ret; dev_dbg(aic31xx->dev, "## %s\n", __func__); - aic31xx->codec = codec; + aic31xx->component = component; for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++) { aic31xx->disable_nb[i].nb.notifier_call = @@ -1193,7 +1276,7 @@ static int aic31xx_codec_probe(struct snd_soc_codec *codec) ret = regulator_register_notifier(aic31xx->supplies[i].consumer, &aic31xx->disable_nb[i].nb); if (ret) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to request regulator notifier: %d\n", ret); return ret; @@ -1203,43 +1286,42 @@ static int aic31xx_codec_probe(struct snd_soc_codec *codec) regcache_cache_only(aic31xx->regmap, true); regcache_mark_dirty(aic31xx->regmap); - ret = aic31xx_add_controls(codec); + ret = aic31xx_add_controls(component); if (ret) return ret; - ret = aic31xx_add_widgets(codec); + ret = aic31xx_add_widgets(component); if (ret) return ret; return 0; } -static int aic31xx_codec_remove(struct snd_soc_codec *codec) +static void aic31xx_codec_remove(struct snd_soc_component *component) { - struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); + struct aic31xx_priv *aic31xx = snd_soc_component_get_drvdata(component); int i; for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++) regulator_unregister_notifier(aic31xx->supplies[i].consumer, &aic31xx->disable_nb[i].nb); - - return 0; } -static const struct snd_soc_codec_driver soc_codec_driver_aic31xx = { +static const struct snd_soc_component_driver soc_codec_driver_aic31xx = { .probe = aic31xx_codec_probe, .remove = aic31xx_codec_remove, .set_bias_level = aic31xx_set_bias_level, - .suspend_bias_off = true, - - .component_driver = { - .controls = common31xx_snd_controls, - .num_controls = ARRAY_SIZE(common31xx_snd_controls), - .dapm_widgets = common31xx_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(common31xx_dapm_widgets), - .dapm_routes = common31xx_audio_map, - .num_dapm_routes = ARRAY_SIZE(common31xx_audio_map), - }, + .controls = common31xx_snd_controls, + .num_controls = ARRAY_SIZE(common31xx_snd_controls), + .dapm_widgets = common31xx_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(common31xx_dapm_widgets), + .dapm_routes = common31xx_audio_map, + .num_dapm_routes = ARRAY_SIZE(common31xx_audio_map), + .suspend_bias_off = 1, + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static const struct snd_soc_dai_ops aic31xx_dai_ops = { @@ -1375,23 +1457,17 @@ static int aic31xx_i2c_probe(struct i2c_client *i2c, } if (aic31xx->codec_type & DAC31XX_BIT) - return snd_soc_register_codec(&i2c->dev, + return devm_snd_soc_register_component(&i2c->dev, &soc_codec_driver_aic31xx, dac31xx_dai_driver, ARRAY_SIZE(dac31xx_dai_driver)); else - return snd_soc_register_codec(&i2c->dev, + return devm_snd_soc_register_component(&i2c->dev, &soc_codec_driver_aic31xx, aic31xx_dai_driver, ARRAY_SIZE(aic31xx_dai_driver)); } -static int aic31xx_i2c_remove(struct i2c_client *i2c) -{ - snd_soc_unregister_codec(&i2c->dev); - return 0; -} - static const struct i2c_device_id aic31xx_i2c_id[] = { { "tlv320aic310x", AIC3100 }, { "tlv320aic311x", AIC3110 }, @@ -1412,7 +1488,6 @@ static struct i2c_driver aic31xx_i2c_driver = { .acpi_match_table = ACPI_PTR(aic31xx_acpi_match), }, .probe = aic31xx_i2c_probe, - .remove = aic31xx_i2c_remove, .id_table = aic31xx_i2c_id, }; module_i2c_driver(aic31xx_i2c_driver); |