diff options
Diffstat (limited to 'sound/soc/codecs')
44 files changed, 2024 insertions, 1643 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 2b331f7266ab..c2480c3c8b98 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -108,6 +108,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_NAU8825 if I2C select SND_SOC_HDMI_CODEC select SND_SOC_PCM1681 if I2C + select SND_SOC_PCM1789_I2C if I2C select SND_SOC_PCM179X_I2C if I2C select SND_SOC_PCM179X_SPI if SPI_MASTER select SND_SOC_PCM186X_I2C if I2C @@ -650,6 +651,17 @@ config SND_SOC_PCM1681 tristate "Texas Instruments PCM1681 CODEC" depends on I2C +config SND_SOC_PCM1789 + tristate + +config SND_SOC_PCM1789_I2C + tristate "Texas Instruments PCM1789 CODEC (I2C)" + depends on I2C + select SND_SOC_PCM1789 + help + Enable support for Texas Instruments PCM1789 CODEC. + Select this if your PCM1789 is connected via an I2C bus. + config SND_SOC_PCM179X tristate diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index da1571336f1e..e59c93512314 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -103,6 +103,8 @@ snd-soc-nau8824-objs := nau8824.o snd-soc-nau8825-objs := nau8825.o snd-soc-hdmi-codec-objs := hdmi-codec.o snd-soc-pcm1681-objs := pcm1681.o +snd-soc-pcm1789-codec-objs := pcm1789.o +snd-soc-pcm1789-i2c-objs := pcm1789-i2c.o snd-soc-pcm179x-codec-objs := pcm179x.o snd-soc-pcm179x-i2c-objs := pcm179x-i2c.o snd-soc-pcm179x-spi-objs := pcm179x-spi.o @@ -349,6 +351,8 @@ obj-$(CONFIG_SND_SOC_NAU8825) += snd-soc-nau8825.o obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o obj-$(CONFIG_SND_SOC_PCM179X) += snd-soc-pcm179x-codec.o +obj-$(CONFIG_SND_SOC_PCM1789_I2C) += snd-soc-pcm1789-i2c.o +obj-$(CONFIG_SND_SOC_PCM1789) += snd-soc-pcm1789-codec.o obj-$(CONFIG_SND_SOC_PCM179X_I2C) += snd-soc-pcm179x-i2c.o obj-$(CONFIG_SND_SOC_PCM179X_SPI) += snd-soc-pcm179x-spi.o obj-$(CONFIG_SND_SOC_PCM186X) += snd-soc-pcm186x.o diff --git a/sound/soc/codecs/cs47l24.c b/sound/soc/codecs/cs47l24.c index be2750680838..3f34de5f800e 100644 --- a/sound/soc/codecs/cs47l24.c +++ b/sound/soc/codecs/cs47l24.c @@ -33,6 +33,8 @@ #include "wm_adsp.h" #include "cs47l24.h" +#define DRV_NAME "cs47l24-codec" + struct cs47l24_priv { struct arizona_priv core; struct arizona_fll fll[2]; @@ -1069,7 +1071,8 @@ static struct snd_soc_dai_driver cs47l24_dai[] = { static int cs47l24_open(struct snd_compr_stream *stream) { struct snd_soc_pcm_runtime *rtd = stream->private_data; - struct cs47l24_priv *priv = snd_soc_platform_get_drvdata(rtd->platform); + struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); + struct cs47l24_priv *priv = snd_soc_component_get_drvdata(component); struct arizona *arizona = priv->core.arizona; int n_adsp; @@ -1177,6 +1180,16 @@ static unsigned int cs47l24_digital_vu[] = { ARIZONA_DAC_DIGITAL_VOLUME_4L, }; +static struct snd_compr_ops cs47l24_compr_ops = { + .open = cs47l24_open, + .free = wm_adsp_compr_free, + .set_params = wm_adsp_compr_set_params, + .get_caps = wm_adsp_compr_get_caps, + .trigger = wm_adsp_compr_trigger, + .pointer = wm_adsp_compr_pointer, + .copy = wm_adsp_compr_copy, +}; + static const struct snd_soc_codec_driver soc_codec_dev_cs47l24 = { .probe = cs47l24_codec_probe, .remove = cs47l24_codec_remove, @@ -1187,6 +1200,8 @@ static const struct snd_soc_codec_driver soc_codec_dev_cs47l24 = { .set_pll = cs47l24_set_fll, .component_driver = { + .name = DRV_NAME, + .compr_ops = &cs47l24_compr_ops, .controls = cs47l24_snd_controls, .num_controls = ARRAY_SIZE(cs47l24_snd_controls), .dapm_widgets = cs47l24_dapm_widgets, @@ -1196,20 +1211,6 @@ static const struct snd_soc_codec_driver soc_codec_dev_cs47l24 = { }, }; -static const struct snd_compr_ops cs47l24_compr_ops = { - .open = cs47l24_open, - .free = wm_adsp_compr_free, - .set_params = wm_adsp_compr_set_params, - .get_caps = wm_adsp_compr_get_caps, - .trigger = wm_adsp_compr_trigger, - .pointer = wm_adsp_compr_pointer, - .copy = wm_adsp_compr_copy, -}; - -static const struct snd_soc_platform_driver cs47l24_compr_platform = { - .compr_ops = &cs47l24_compr_ops, -}; - static int cs47l24_probe(struct platform_device *pdev) { struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); @@ -1298,23 +1299,15 @@ static int cs47l24_probe(struct platform_device *pdev) if (ret < 0) goto err_dsp_irq; - ret = snd_soc_register_platform(&pdev->dev, &cs47l24_compr_platform); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to register platform: %d\n", ret); - goto err_spk_irqs; - } - ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_cs47l24, cs47l24_dai, ARRAY_SIZE(cs47l24_dai)); if (ret < 0) { dev_err(&pdev->dev, "Failed to register codec: %d\n", ret); - goto err_platform; + goto err_spk_irqs; } return ret; -err_platform: - snd_soc_unregister_platform(&pdev->dev); err_spk_irqs: arizona_free_spk_irqs(arizona); err_dsp_irq: @@ -1328,7 +1321,6 @@ static int cs47l24_remove(struct platform_device *pdev) struct cs47l24_priv *cs47l24 = platform_get_drvdata(pdev); struct arizona *arizona = cs47l24->core.arizona; - snd_soc_unregister_platform(&pdev->dev); snd_soc_unregister_codec(&pdev->dev); pm_runtime_disable(&pdev->dev); diff --git a/sound/soc/codecs/da7219-aad.c b/sound/soc/codecs/da7219-aad.c index 1d1d10dd92ae..a49ab751a036 100644 --- a/sound/soc/codecs/da7219-aad.c +++ b/sound/soc/codecs/da7219-aad.c @@ -32,9 +32,9 @@ * Detection control */ -void da7219_aad_jack_det(struct snd_soc_codec *codec, struct snd_soc_jack *jack) +void da7219_aad_jack_det(struct snd_soc_component *component, struct snd_soc_jack *jack) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); da7219->aad->jack = jack; da7219->aad->jack_inserted = false; @@ -43,7 +43,7 @@ void da7219_aad_jack_det(struct snd_soc_codec *codec, struct snd_soc_jack *jack) snd_soc_jack_report(jack, 0, DA7219_AAD_REPORT_ALL_MASK); /* Enable/Disable jack detection */ - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_1, + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_1, DA7219_ACCDET_EN_MASK, (jack ? DA7219_ACCDET_EN_MASK : 0)); } @@ -57,17 +57,17 @@ static void da7219_aad_btn_det_work(struct work_struct *work) { struct da7219_aad_priv *da7219_aad = container_of(work, struct da7219_aad_priv, btn_det_work); - struct snd_soc_codec *codec = da7219_aad->codec; - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); + struct snd_soc_component *component = da7219_aad->component; + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); u8 statusa, micbias_ctrl; bool micbias_up = false; int retries = 0; /* Drive headphones/lineout */ - snd_soc_update_bits(codec, DA7219_HP_L_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_L_CTRL, DA7219_HP_L_AMP_OE_MASK, DA7219_HP_L_AMP_OE_MASK); - snd_soc_update_bits(codec, DA7219_HP_R_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_OE_MASK, DA7219_HP_R_AMP_OE_MASK); @@ -76,7 +76,7 @@ static void da7219_aad_btn_det_work(struct work_struct *work) snd_soc_dapm_sync(dapm); do { - statusa = snd_soc_read(codec, DA7219_ACCDET_STATUS_A); + statusa = snd_soc_component_read32(component, DA7219_ACCDET_STATUS_A); if (statusa & DA7219_MICBIAS_UP_STS_MASK) micbias_up = true; else if (retries++ < DA7219_AAD_MICBIAS_CHK_RETRIES) @@ -84,7 +84,7 @@ static void da7219_aad_btn_det_work(struct work_struct *work) } while ((!micbias_up) && (retries < DA7219_AAD_MICBIAS_CHK_RETRIES)); if (retries >= DA7219_AAD_MICBIAS_CHK_RETRIES) - dev_warn(codec->dev, "Mic bias status check timed out"); + dev_warn(component->dev, "Mic bias status check timed out"); /* * Mic bias pulse required to enable mic, must be done before enabling @@ -92,16 +92,16 @@ static void da7219_aad_btn_det_work(struct work_struct *work) */ if (da7219_aad->micbias_pulse_lvl && da7219_aad->micbias_pulse_time) { /* Pulse higher level voltage */ - micbias_ctrl = snd_soc_read(codec, DA7219_MICBIAS_CTRL); - snd_soc_update_bits(codec, DA7219_MICBIAS_CTRL, + micbias_ctrl = snd_soc_component_read32(component, DA7219_MICBIAS_CTRL); + snd_soc_component_update_bits(component, DA7219_MICBIAS_CTRL, DA7219_MICBIAS1_LEVEL_MASK, da7219_aad->micbias_pulse_lvl); msleep(da7219_aad->micbias_pulse_time); - snd_soc_write(codec, DA7219_MICBIAS_CTRL, micbias_ctrl); + snd_soc_component_write(component, DA7219_MICBIAS_CTRL, micbias_ctrl); } - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_1, + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_1, DA7219_BUTTON_CONFIG_MASK, da7219_aad->btn_cfg); } @@ -110,9 +110,9 @@ static void da7219_aad_hptest_work(struct work_struct *work) { struct da7219_aad_priv *da7219_aad = container_of(work, struct da7219_aad_priv, hptest_work); - struct snd_soc_codec *codec = da7219_aad->codec; - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = da7219_aad->component; + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); u16 tonegen_freq_hptest; u8 pll_srm_sts, pll_ctrl, gain_ramp_ctrl, accdet_cfg8; @@ -127,7 +127,7 @@ static void da7219_aad_hptest_work(struct work_struct *work) if (da7219->mclk) { ret = clk_prepare_enable(da7219->mclk); if (ret) { - dev_err(codec->dev, "Failed to enable mclk - %d\n", ret); + dev_err(component->dev, "Failed to enable mclk - %d\n", ret); mutex_unlock(&da7219->pll_lock); mutex_unlock(&da7219->ctrl_lock); snd_soc_dapm_mutex_unlock(dapm); @@ -142,90 +142,90 @@ static void da7219_aad_hptest_work(struct work_struct *work) * If MCLK is present, but PLL is not enabled then we enable it here to * ensure a consistent detection procedure. */ - pll_srm_sts = snd_soc_read(codec, DA7219_PLL_SRM_STS); + pll_srm_sts = snd_soc_component_read32(component, DA7219_PLL_SRM_STS); if (pll_srm_sts & DA7219_PLL_SRM_STS_MCLK) { tonegen_freq_hptest = cpu_to_le16(DA7219_AAD_HPTEST_RAMP_FREQ); - pll_ctrl = snd_soc_read(codec, DA7219_PLL_CTRL); + pll_ctrl = snd_soc_component_read32(component, DA7219_PLL_CTRL); if ((pll_ctrl & DA7219_PLL_MODE_MASK) == DA7219_PLL_MODE_BYPASS) - da7219_set_pll(codec, DA7219_SYSCLK_PLL, + da7219_set_pll(component, DA7219_SYSCLK_PLL, DA7219_PLL_FREQ_OUT_98304); } else { tonegen_freq_hptest = cpu_to_le16(DA7219_AAD_HPTEST_RAMP_FREQ_INT_OSC); } /* Ensure gain ramping at fastest rate */ - gain_ramp_ctrl = snd_soc_read(codec, DA7219_GAIN_RAMP_CTRL); - snd_soc_write(codec, DA7219_GAIN_RAMP_CTRL, DA7219_GAIN_RAMP_RATE_X8); + gain_ramp_ctrl = snd_soc_component_read32(component, DA7219_GAIN_RAMP_CTRL); + snd_soc_component_write(component, DA7219_GAIN_RAMP_CTRL, DA7219_GAIN_RAMP_RATE_X8); /* Bypass cache so it saves current settings */ regcache_cache_bypass(da7219->regmap, true); /* Make sure Tone Generator is disabled */ - snd_soc_write(codec, DA7219_TONE_GEN_CFG1, 0); + snd_soc_component_write(component, DA7219_TONE_GEN_CFG1, 0); /* Enable HPTest block, 1KOhms check */ - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_8, + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_8, DA7219_HPTEST_EN_MASK | DA7219_HPTEST_RES_SEL_MASK, DA7219_HPTEST_EN_MASK | DA7219_HPTEST_RES_SEL_1KOHMS); /* Set gains to 0db */ - snd_soc_write(codec, DA7219_DAC_L_GAIN, DA7219_DAC_DIGITAL_GAIN_0DB); - snd_soc_write(codec, DA7219_DAC_R_GAIN, DA7219_DAC_DIGITAL_GAIN_0DB); - snd_soc_write(codec, DA7219_HP_L_GAIN, DA7219_HP_AMP_GAIN_0DB); - snd_soc_write(codec, DA7219_HP_R_GAIN, DA7219_HP_AMP_GAIN_0DB); + snd_soc_component_write(component, DA7219_DAC_L_GAIN, DA7219_DAC_DIGITAL_GAIN_0DB); + snd_soc_component_write(component, DA7219_DAC_R_GAIN, DA7219_DAC_DIGITAL_GAIN_0DB); + snd_soc_component_write(component, DA7219_HP_L_GAIN, DA7219_HP_AMP_GAIN_0DB); + snd_soc_component_write(component, DA7219_HP_R_GAIN, DA7219_HP_AMP_GAIN_0DB); /* Disable DAC filters, EQs and soft mute */ - snd_soc_update_bits(codec, DA7219_DAC_FILTERS1, DA7219_HPF_MODE_MASK, + snd_soc_component_update_bits(component, DA7219_DAC_FILTERS1, DA7219_HPF_MODE_MASK, 0); - snd_soc_update_bits(codec, DA7219_DAC_FILTERS4, DA7219_DAC_EQ_EN_MASK, + snd_soc_component_update_bits(component, DA7219_DAC_FILTERS4, DA7219_DAC_EQ_EN_MASK, 0); - snd_soc_update_bits(codec, DA7219_DAC_FILTERS5, + snd_soc_component_update_bits(component, DA7219_DAC_FILTERS5, DA7219_DAC_SOFTMUTE_EN_MASK, 0); /* Enable HP left & right paths */ - snd_soc_update_bits(codec, DA7219_CP_CTRL, DA7219_CP_EN_MASK, + snd_soc_component_update_bits(component, DA7219_CP_CTRL, DA7219_CP_EN_MASK, DA7219_CP_EN_MASK); - snd_soc_update_bits(codec, DA7219_DIG_ROUTING_DAC, + snd_soc_component_update_bits(component, DA7219_DIG_ROUTING_DAC, DA7219_DAC_L_SRC_MASK | DA7219_DAC_R_SRC_MASK, DA7219_DAC_L_SRC_TONEGEN | DA7219_DAC_R_SRC_TONEGEN); - snd_soc_update_bits(codec, DA7219_DAC_L_CTRL, + snd_soc_component_update_bits(component, DA7219_DAC_L_CTRL, DA7219_DAC_L_EN_MASK | DA7219_DAC_L_MUTE_EN_MASK, DA7219_DAC_L_EN_MASK); - snd_soc_update_bits(codec, DA7219_DAC_R_CTRL, + snd_soc_component_update_bits(component, DA7219_DAC_R_CTRL, DA7219_DAC_R_EN_MASK | DA7219_DAC_R_MUTE_EN_MASK, DA7219_DAC_R_EN_MASK); - snd_soc_update_bits(codec, DA7219_MIXOUT_L_SELECT, + snd_soc_component_update_bits(component, DA7219_MIXOUT_L_SELECT, DA7219_MIXOUT_L_MIX_SELECT_MASK, DA7219_MIXOUT_L_MIX_SELECT_MASK); - snd_soc_update_bits(codec, DA7219_MIXOUT_R_SELECT, + snd_soc_component_update_bits(component, DA7219_MIXOUT_R_SELECT, DA7219_MIXOUT_R_MIX_SELECT_MASK, DA7219_MIXOUT_R_MIX_SELECT_MASK); - snd_soc_update_bits(codec, DA7219_DROUTING_ST_OUTFILT_1L, + snd_soc_component_update_bits(component, DA7219_DROUTING_ST_OUTFILT_1L, DA7219_OUTFILT_ST_1L_SRC_MASK, DA7219_DMIX_ST_SRC_OUTFILT1L); - snd_soc_update_bits(codec, DA7219_DROUTING_ST_OUTFILT_1R, + snd_soc_component_update_bits(component, DA7219_DROUTING_ST_OUTFILT_1R, DA7219_OUTFILT_ST_1R_SRC_MASK, DA7219_DMIX_ST_SRC_OUTFILT1R); - snd_soc_update_bits(codec, DA7219_MIXOUT_L_CTRL, + snd_soc_component_update_bits(component, DA7219_MIXOUT_L_CTRL, DA7219_MIXOUT_L_AMP_EN_MASK, DA7219_MIXOUT_L_AMP_EN_MASK); - snd_soc_update_bits(codec, DA7219_MIXOUT_R_CTRL, + snd_soc_component_update_bits(component, DA7219_MIXOUT_R_CTRL, DA7219_MIXOUT_R_AMP_EN_MASK, DA7219_MIXOUT_R_AMP_EN_MASK); - snd_soc_update_bits(codec, DA7219_HP_L_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_L_CTRL, DA7219_HP_L_AMP_OE_MASK | DA7219_HP_L_AMP_EN_MASK, DA7219_HP_L_AMP_OE_MASK | DA7219_HP_L_AMP_EN_MASK); - snd_soc_update_bits(codec, DA7219_HP_R_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_OE_MASK | DA7219_HP_R_AMP_EN_MASK, DA7219_HP_R_AMP_OE_MASK | DA7219_HP_R_AMP_EN_MASK); msleep(DA7219_SETTLING_DELAY); - snd_soc_update_bits(codec, DA7219_HP_L_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_L_CTRL, DA7219_HP_L_AMP_MUTE_EN_MASK | DA7219_HP_L_AMP_MIN_GAIN_EN_MASK, 0); - snd_soc_update_bits(codec, DA7219_HP_R_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_MUTE_EN_MASK | DA7219_HP_R_AMP_MIN_GAIN_EN_MASK, 0); @@ -237,26 +237,26 @@ static void da7219_aad_hptest_work(struct work_struct *work) msleep(DA7219_AAD_HPTEST_INT_OSC_PATH_DELAY); /* Configure & start Tone Generator */ - snd_soc_write(codec, DA7219_TONE_GEN_ON_PER, DA7219_BEEP_ON_PER_MASK); + snd_soc_component_write(component, DA7219_TONE_GEN_ON_PER, DA7219_BEEP_ON_PER_MASK); regmap_raw_write(da7219->regmap, DA7219_TONE_GEN_FREQ1_L, &tonegen_freq_hptest, sizeof(tonegen_freq_hptest)); - snd_soc_update_bits(codec, DA7219_TONE_GEN_CFG2, + snd_soc_component_update_bits(component, DA7219_TONE_GEN_CFG2, DA7219_SWG_SEL_MASK | DA7219_TONE_GEN_GAIN_MASK, DA7219_SWG_SEL_SRAMP | DA7219_TONE_GEN_GAIN_MINUS_15DB); - snd_soc_write(codec, DA7219_TONE_GEN_CFG1, DA7219_START_STOPN_MASK); + snd_soc_component_write(component, DA7219_TONE_GEN_CFG1, DA7219_START_STOPN_MASK); msleep(DA7219_AAD_HPTEST_PERIOD); /* Grab comparator reading */ - accdet_cfg8 = snd_soc_read(codec, DA7219_ACCDET_CONFIG_8); + accdet_cfg8 = snd_soc_component_read32(component, DA7219_ACCDET_CONFIG_8); if (accdet_cfg8 & DA7219_HPTEST_COMP_MASK) report |= SND_JACK_HEADPHONE; else report |= SND_JACK_LINEOUT; /* Stop tone generator */ - snd_soc_write(codec, DA7219_TONE_GEN_CFG1, 0); + snd_soc_component_write(component, DA7219_TONE_GEN_CFG1, 0); msleep(DA7219_AAD_HPTEST_PERIOD); @@ -294,7 +294,7 @@ static void da7219_aad_hptest_work(struct work_struct *work) regcache_cache_bypass(da7219->regmap, false); /* Disable HPTest block */ - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_8, + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_8, DA7219_HPTEST_EN_MASK, 0); /* @@ -305,18 +305,18 @@ static void da7219_aad_hptest_work(struct work_struct *work) msleep(DA7219_AAD_HPTEST_INT_OSC_PATH_DELAY); /* Restore gain ramping rate */ - snd_soc_write(codec, DA7219_GAIN_RAMP_CTRL, gain_ramp_ctrl); + snd_soc_component_write(component, DA7219_GAIN_RAMP_CTRL, gain_ramp_ctrl); /* Drive Headphones/lineout */ - snd_soc_update_bits(codec, DA7219_HP_L_CTRL, DA7219_HP_L_AMP_OE_MASK, + snd_soc_component_update_bits(component, DA7219_HP_L_CTRL, DA7219_HP_L_AMP_OE_MASK, DA7219_HP_L_AMP_OE_MASK); - snd_soc_update_bits(codec, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_OE_MASK, + snd_soc_component_update_bits(component, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_OE_MASK, DA7219_HP_R_AMP_OE_MASK); /* Restore PLL to previous configuration, if re-configured */ if ((pll_srm_sts & DA7219_PLL_SRM_STS_MCLK) && ((pll_ctrl & DA7219_PLL_MODE_MASK) == DA7219_PLL_MODE_BYPASS)) - da7219_set_pll(codec, DA7219_SYSCLK_MCLK, 0); + da7219_set_pll(component, DA7219_SYSCLK_MCLK, 0); /* Remove MCLK, if previously enabled */ if (da7219->mclk) @@ -343,9 +343,9 @@ static void da7219_aad_hptest_work(struct work_struct *work) static irqreturn_t da7219_aad_irq_thread(int irq, void *data) { struct da7219_aad_priv *da7219_aad = data; - struct snd_soc_codec *codec = da7219_aad->codec; - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = da7219_aad->component; + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); u8 events[DA7219_AAD_IRQ_REG_MAX]; u8 statusa; int i, report = 0, mask = 0; @@ -358,13 +358,13 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data) return IRQ_NONE; /* Read status register for jack insertion & type status */ - statusa = snd_soc_read(codec, DA7219_ACCDET_STATUS_A); + statusa = snd_soc_component_read32(component, DA7219_ACCDET_STATUS_A); /* Clear events */ regmap_bulk_write(da7219->regmap, DA7219_ACCDET_IRQ_EVENT_A, events, DA7219_AAD_IRQ_REG_MAX); - dev_dbg(codec->dev, "IRQ events = 0x%x|0x%x, status = 0x%x\n", + dev_dbg(component->dev, "IRQ events = 0x%x|0x%x, status = 0x%x\n", events[DA7219_AAD_IRQ_REG_A], events[DA7219_AAD_IRQ_REG_B], statusa); @@ -430,13 +430,13 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data) da7219_aad->jack_inserted = false; /* Un-drive headphones/lineout */ - snd_soc_update_bits(codec, DA7219_HP_R_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_OE_MASK, 0); - snd_soc_update_bits(codec, DA7219_HP_L_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_L_CTRL, DA7219_HP_L_AMP_OE_MASK, 0); /* Ensure button detection disabled */ - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_1, + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_1, DA7219_BUTTON_CONFIG_MASK, 0); /* Disable mic bias */ @@ -459,7 +459,7 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data) */ static enum da7219_aad_micbias_pulse_lvl - da7219_aad_fw_micbias_pulse_lvl(struct snd_soc_codec *codec, u32 val) + da7219_aad_fw_micbias_pulse_lvl(struct snd_soc_component *component, u32 val) { switch (val) { case 2800: @@ -467,13 +467,13 @@ static enum da7219_aad_micbias_pulse_lvl case 2900: return DA7219_AAD_MICBIAS_PULSE_LVL_2_9V; default: - dev_warn(codec->dev, "Invalid micbias pulse level"); + dev_warn(component->dev, "Invalid micbias pulse level"); return DA7219_AAD_MICBIAS_PULSE_LVL_OFF; } } static enum da7219_aad_btn_cfg - da7219_aad_fw_btn_cfg(struct snd_soc_codec *codec, u32 val) + da7219_aad_fw_btn_cfg(struct snd_soc_component *component, u32 val) { switch (val) { case 2: @@ -491,13 +491,13 @@ static enum da7219_aad_btn_cfg case 500: return DA7219_AAD_BTN_CFG_500MS; default: - dev_warn(codec->dev, "Invalid button config"); + dev_warn(component->dev, "Invalid button config"); return DA7219_AAD_BTN_CFG_10MS; } } static enum da7219_aad_mic_det_thr - da7219_aad_fw_mic_det_thr(struct snd_soc_codec *codec, u32 val) + da7219_aad_fw_mic_det_thr(struct snd_soc_component *component, u32 val) { switch (val) { case 200: @@ -509,13 +509,13 @@ static enum da7219_aad_mic_det_thr case 1000: return DA7219_AAD_MIC_DET_THR_1000_OHMS; default: - dev_warn(codec->dev, "Invalid mic detect threshold"); + dev_warn(component->dev, "Invalid mic detect threshold"); return DA7219_AAD_MIC_DET_THR_500_OHMS; } } static enum da7219_aad_jack_ins_deb - da7219_aad_fw_jack_ins_deb(struct snd_soc_codec *codec, u32 val) + da7219_aad_fw_jack_ins_deb(struct snd_soc_component *component, u32 val) { switch (val) { case 5: @@ -535,13 +535,13 @@ static enum da7219_aad_jack_ins_deb case 1000: return DA7219_AAD_JACK_INS_DEB_1S; default: - dev_warn(codec->dev, "Invalid jack insert debounce"); + dev_warn(component->dev, "Invalid jack insert debounce"); return DA7219_AAD_JACK_INS_DEB_20MS; } } static enum da7219_aad_jack_det_rate - da7219_aad_fw_jack_det_rate(struct snd_soc_codec *codec, const char *str) + da7219_aad_fw_jack_det_rate(struct snd_soc_component *component, const char *str) { if (!strcmp(str, "32ms_64ms")) { return DA7219_AAD_JACK_DET_RATE_32_64MS; @@ -552,13 +552,13 @@ static enum da7219_aad_jack_det_rate } else if (!strcmp(str, "256ms_512ms")) { return DA7219_AAD_JACK_DET_RATE_256_512MS; } else { - dev_warn(codec->dev, "Invalid jack detect rate"); + dev_warn(component->dev, "Invalid jack detect rate"); return DA7219_AAD_JACK_DET_RATE_256_512MS; } } static enum da7219_aad_jack_rem_deb - da7219_aad_fw_jack_rem_deb(struct snd_soc_codec *codec, u32 val) + da7219_aad_fw_jack_rem_deb(struct snd_soc_component *component, u32 val) { switch (val) { case 1: @@ -570,13 +570,13 @@ static enum da7219_aad_jack_rem_deb case 20: return DA7219_AAD_JACK_REM_DEB_20MS; default: - dev_warn(codec->dev, "Invalid jack removal debounce"); + dev_warn(component->dev, "Invalid jack removal debounce"); return DA7219_AAD_JACK_REM_DEB_1MS; } } static enum da7219_aad_btn_avg - da7219_aad_fw_btn_avg(struct snd_soc_codec *codec, u32 val) + da7219_aad_fw_btn_avg(struct snd_soc_component *component, u32 val) { switch (val) { case 1: @@ -588,13 +588,13 @@ static enum da7219_aad_btn_avg case 8: return DA7219_AAD_BTN_AVG_8; default: - dev_warn(codec->dev, "Invalid button average value"); + dev_warn(component->dev, "Invalid button average value"); return DA7219_AAD_BTN_AVG_2; } } static enum da7219_aad_adc_1bit_rpt - da7219_aad_fw_adc_1bit_rpt(struct snd_soc_codec *codec, u32 val) + da7219_aad_fw_adc_1bit_rpt(struct snd_soc_component *component, u32 val) { switch (val) { case 1: @@ -606,14 +606,14 @@ static enum da7219_aad_adc_1bit_rpt case 8: return DA7219_AAD_ADC_1BIT_RPT_8; default: - dev_warn(codec->dev, "Invalid ADC 1-bit repeat value"); + dev_warn(component->dev, "Invalid ADC 1-bit repeat value"); return DA7219_AAD_ADC_1BIT_RPT_1; } } -static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_codec *codec) +static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_component *component) { - struct device *dev = codec->dev; + struct device *dev = component->dev; struct i2c_client *i2c = to_i2c_client(dev); struct fwnode_handle *aad_np; struct da7219_aad_pdata *aad_pdata; @@ -624,7 +624,7 @@ static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_codec *cod if (!aad_np) return NULL; - aad_pdata = devm_kzalloc(codec->dev, sizeof(*aad_pdata), GFP_KERNEL); + aad_pdata = devm_kzalloc(dev, sizeof(*aad_pdata), GFP_KERNEL); if (!aad_pdata) return NULL; @@ -633,7 +633,7 @@ static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_codec *cod if (fwnode_property_read_u32(aad_np, "dlg,micbias-pulse-lvl", &fw_val32) >= 0) aad_pdata->micbias_pulse_lvl = - da7219_aad_fw_micbias_pulse_lvl(codec, fw_val32); + da7219_aad_fw_micbias_pulse_lvl(component, fw_val32); else aad_pdata->micbias_pulse_lvl = DA7219_AAD_MICBIAS_PULSE_LVL_OFF; @@ -642,31 +642,31 @@ static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_codec *cod aad_pdata->micbias_pulse_time = fw_val32; if (fwnode_property_read_u32(aad_np, "dlg,btn-cfg", &fw_val32) >= 0) - aad_pdata->btn_cfg = da7219_aad_fw_btn_cfg(codec, fw_val32); + aad_pdata->btn_cfg = da7219_aad_fw_btn_cfg(component, fw_val32); else aad_pdata->btn_cfg = DA7219_AAD_BTN_CFG_10MS; if (fwnode_property_read_u32(aad_np, "dlg,mic-det-thr", &fw_val32) >= 0) aad_pdata->mic_det_thr = - da7219_aad_fw_mic_det_thr(codec, fw_val32); + da7219_aad_fw_mic_det_thr(component, fw_val32); else aad_pdata->mic_det_thr = DA7219_AAD_MIC_DET_THR_500_OHMS; if (fwnode_property_read_u32(aad_np, "dlg,jack-ins-deb", &fw_val32) >= 0) aad_pdata->jack_ins_deb = - da7219_aad_fw_jack_ins_deb(codec, fw_val32); + da7219_aad_fw_jack_ins_deb(component, fw_val32); else aad_pdata->jack_ins_deb = DA7219_AAD_JACK_INS_DEB_20MS; if (!fwnode_property_read_string(aad_np, "dlg,jack-det-rate", &fw_str)) aad_pdata->jack_det_rate = - da7219_aad_fw_jack_det_rate(codec, fw_str); + da7219_aad_fw_jack_det_rate(component, fw_str); else aad_pdata->jack_det_rate = DA7219_AAD_JACK_DET_RATE_256_512MS; if (fwnode_property_read_u32(aad_np, "dlg,jack-rem-deb", &fw_val32) >= 0) aad_pdata->jack_rem_deb = - da7219_aad_fw_jack_rem_deb(codec, fw_val32); + da7219_aad_fw_jack_rem_deb(component, fw_val32); else aad_pdata->jack_rem_deb = DA7219_AAD_JACK_REM_DEB_1MS; @@ -691,22 +691,22 @@ static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_codec *cod aad_pdata->c_mic_btn_thr = 0x3E; if (fwnode_property_read_u32(aad_np, "dlg,btn-avg", &fw_val32) >= 0) - aad_pdata->btn_avg = da7219_aad_fw_btn_avg(codec, fw_val32); + aad_pdata->btn_avg = da7219_aad_fw_btn_avg(component, fw_val32); else aad_pdata->btn_avg = DA7219_AAD_BTN_AVG_2; if (fwnode_property_read_u32(aad_np, "dlg,adc-1bit-rpt", &fw_val32) >= 0) aad_pdata->adc_1bit_rpt = - da7219_aad_fw_adc_1bit_rpt(codec, fw_val32); + da7219_aad_fw_adc_1bit_rpt(component, fw_val32); else aad_pdata->adc_1bit_rpt = DA7219_AAD_ADC_1BIT_RPT_1; return aad_pdata; } -static void da7219_aad_handle_pdata(struct snd_soc_codec *codec) +static void da7219_aad_handle_pdata(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_aad_priv *da7219_aad = da7219->aad; struct da7219_pdata *pdata = da7219->pdata; @@ -752,7 +752,7 @@ static void da7219_aad_handle_pdata(struct snd_soc_codec *codec) DA7219_MIC_DET_THRESH_SHIFT); mask |= DA7219_MIC_DET_THRESH_MASK; } - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_1, mask, cfg); + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_1, mask, cfg); cfg = 0; mask = 0; @@ -787,15 +787,15 @@ static void da7219_aad_handle_pdata(struct snd_soc_codec *codec) DA7219_JACKDET_REM_DEB_SHIFT); mask |= DA7219_JACKDET_REM_DEB_MASK; } - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_2, mask, cfg); + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_2, mask, cfg); - snd_soc_write(codec, DA7219_ACCDET_CONFIG_3, + snd_soc_component_write(component, DA7219_ACCDET_CONFIG_3, aad_pdata->a_d_btn_thr); - snd_soc_write(codec, DA7219_ACCDET_CONFIG_4, + snd_soc_component_write(component, DA7219_ACCDET_CONFIG_4, aad_pdata->d_b_btn_thr); - snd_soc_write(codec, DA7219_ACCDET_CONFIG_5, + snd_soc_component_write(component, DA7219_ACCDET_CONFIG_5, aad_pdata->b_c_btn_thr); - snd_soc_write(codec, DA7219_ACCDET_CONFIG_6, + snd_soc_component_write(component, DA7219_ACCDET_CONFIG_6, aad_pdata->c_mic_btn_thr); cfg = 0; @@ -818,7 +818,7 @@ static void da7219_aad_handle_pdata(struct snd_soc_codec *codec) DA7219_ADC_1_BIT_REPEAT_SHIFT); mask |= DA7219_ADC_1_BIT_REPEAT_MASK; } - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_7, mask, cfg); + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_7, mask, cfg); } } @@ -827,16 +827,16 @@ static void da7219_aad_handle_pdata(struct snd_soc_codec *codec) * Suspend/Resume */ -void da7219_aad_suspend(struct snd_soc_codec *codec) +void da7219_aad_suspend(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_aad_priv *da7219_aad = da7219->aad; - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); u8 micbias_ctrl; if (da7219_aad->jack) { /* Disable jack detection during suspend */ - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_1, + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_1, DA7219_ACCDET_EN_MASK, 0); /* @@ -846,7 +846,7 @@ void da7219_aad_suspend(struct snd_soc_codec *codec) * suspend then this will be dealt with through the IRQ handler. */ if (da7219_aad->jack_inserted) { - micbias_ctrl = snd_soc_read(codec, DA7219_MICBIAS_CTRL); + micbias_ctrl = snd_soc_component_read32(component, DA7219_MICBIAS_CTRL); if (micbias_ctrl & DA7219_MICBIAS1_EN_MASK) { snd_soc_dapm_disable_pin(dapm, "Mic Bias"); snd_soc_dapm_sync(dapm); @@ -856,11 +856,11 @@ void da7219_aad_suspend(struct snd_soc_codec *codec) } } -void da7219_aad_resume(struct snd_soc_codec *codec) +void da7219_aad_resume(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_aad_priv *da7219_aad = da7219->aad; - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); if (da7219_aad->jack) { /* Re-enable micbias if previously enabled for 4-pole jack */ @@ -872,7 +872,7 @@ void da7219_aad_resume(struct snd_soc_codec *codec) } /* Re-enable jack detection */ - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_1, + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_1, DA7219_ACCDET_EN_MASK, DA7219_ACCDET_EN_MASK); } @@ -883,28 +883,28 @@ void da7219_aad_resume(struct snd_soc_codec *codec) * Init/Exit */ -int da7219_aad_init(struct snd_soc_codec *codec) +int da7219_aad_init(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_aad_priv *da7219_aad; u8 mask[DA7219_AAD_IRQ_REG_MAX]; int ret; - da7219_aad = devm_kzalloc(codec->dev, sizeof(*da7219_aad), GFP_KERNEL); + da7219_aad = devm_kzalloc(component->dev, sizeof(*da7219_aad), GFP_KERNEL); if (!da7219_aad) return -ENOMEM; da7219->aad = da7219_aad; - da7219_aad->codec = codec; + da7219_aad->component = component; /* Handle any DT/ACPI/platform data */ if (da7219->pdata && !da7219->pdata->aad_pdata) - da7219->pdata->aad_pdata = da7219_aad_fw_to_pdata(codec); + da7219->pdata->aad_pdata = da7219_aad_fw_to_pdata(component); - da7219_aad_handle_pdata(codec); + da7219_aad_handle_pdata(component); /* Disable button detection */ - snd_soc_update_bits(codec, DA7219_ACCDET_CONFIG_1, + snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_1, DA7219_BUTTON_CONFIG_MASK, 0); INIT_WORK(&da7219_aad->btn_det_work, da7219_aad_btn_det_work); @@ -915,7 +915,7 @@ int da7219_aad_init(struct snd_soc_codec *codec) IRQF_TRIGGER_LOW | IRQF_ONESHOT, "da7219-aad", da7219_aad); if (ret) { - dev_err(codec->dev, "Failed to request IRQ: %d\n", ret); + dev_err(component->dev, "Failed to request IRQ: %d\n", ret); return ret; } @@ -928,9 +928,9 @@ int da7219_aad_init(struct snd_soc_codec *codec) } EXPORT_SYMBOL_GPL(da7219_aad_init); -void da7219_aad_exit(struct snd_soc_codec *codec) +void da7219_aad_exit(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_aad_priv *da7219_aad = da7219->aad; u8 mask[DA7219_AAD_IRQ_REG_MAX]; diff --git a/sound/soc/codecs/da7219-aad.h b/sound/soc/codecs/da7219-aad.h index 117a3d7ccd31..b9c4a27e8e61 100644 --- a/sound/soc/codecs/da7219-aad.h +++ b/sound/soc/codecs/da7219-aad.h @@ -189,7 +189,7 @@ enum da7219_aad_event_regs { /* Private data */ struct da7219_aad_priv { - struct snd_soc_codec *codec; + struct snd_soc_component *component; int irq; u8 micbias_pulse_lvl; @@ -206,14 +206,14 @@ struct da7219_aad_priv { }; /* AAD control */ -void da7219_aad_jack_det(struct snd_soc_codec *codec, struct snd_soc_jack *jack); +void da7219_aad_jack_det(struct snd_soc_component *component, struct snd_soc_jack *jack); /* Suspend/Resume */ -void da7219_aad_suspend(struct snd_soc_codec *codec); -void da7219_aad_resume(struct snd_soc_codec *codec); +void da7219_aad_suspend(struct snd_soc_component *component); +void da7219_aad_resume(struct snd_soc_component *component); /* Init/Exit */ -int da7219_aad_init(struct snd_soc_codec *codec); -void da7219_aad_exit(struct snd_soc_codec *codec); +int da7219_aad_init(struct snd_soc_component *component); +void da7219_aad_exit(struct snd_soc_component *component); #endif /* __DA7219_AAD_H */ diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c index 6f088536df32..5e043d082f4b 100644 --- a/sound/soc/codecs/da7219.c +++ b/sound/soc/codecs/da7219.c @@ -256,8 +256,8 @@ static const struct soc_enum da7219_cp_track_mode = static int da7219_volsw_locked_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); int ret; mutex_lock(&da7219->ctrl_lock); @@ -270,8 +270,8 @@ static int da7219_volsw_locked_get(struct snd_kcontrol *kcontrol, static int da7219_volsw_locked_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); int ret; mutex_lock(&da7219->ctrl_lock); @@ -284,8 +284,8 @@ static int da7219_volsw_locked_put(struct snd_kcontrol *kcontrol, static int da7219_enum_locked_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); int ret; mutex_lock(&da7219->ctrl_lock); @@ -298,8 +298,8 @@ static int da7219_enum_locked_get(struct snd_kcontrol *kcontrol, static int da7219_enum_locked_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); int ret; mutex_lock(&da7219->ctrl_lock); @@ -310,55 +310,55 @@ static int da7219_enum_locked_put(struct snd_kcontrol *kcontrol, } /* ALC */ -static void da7219_alc_calib(struct snd_soc_codec *codec) +static void da7219_alc_calib(struct snd_soc_component *component) { u8 mic_ctrl, mixin_ctrl, adc_ctrl, calib_ctrl; /* Save current state of mic control register */ - mic_ctrl = snd_soc_read(codec, DA7219_MIC_1_CTRL); + mic_ctrl = snd_soc_component_read32(component, DA7219_MIC_1_CTRL); /* Save current state of input mixer control register */ - mixin_ctrl = snd_soc_read(codec, DA7219_MIXIN_L_CTRL); + mixin_ctrl = snd_soc_component_read32(component, DA7219_MIXIN_L_CTRL); /* Save current state of input ADC control register */ - adc_ctrl = snd_soc_read(codec, DA7219_ADC_L_CTRL); + adc_ctrl = snd_soc_component_read32(component, DA7219_ADC_L_CTRL); /* Enable then Mute MIC PGAs */ - snd_soc_update_bits(codec, DA7219_MIC_1_CTRL, DA7219_MIC_1_AMP_EN_MASK, + snd_soc_component_update_bits(component, DA7219_MIC_1_CTRL, DA7219_MIC_1_AMP_EN_MASK, DA7219_MIC_1_AMP_EN_MASK); - snd_soc_update_bits(codec, DA7219_MIC_1_CTRL, + snd_soc_component_update_bits(component, DA7219_MIC_1_CTRL, DA7219_MIC_1_AMP_MUTE_EN_MASK, DA7219_MIC_1_AMP_MUTE_EN_MASK); /* Enable input mixers unmuted */ - snd_soc_update_bits(codec, DA7219_MIXIN_L_CTRL, + snd_soc_component_update_bits(component, DA7219_MIXIN_L_CTRL, DA7219_MIXIN_L_AMP_EN_MASK | DA7219_MIXIN_L_AMP_MUTE_EN_MASK, DA7219_MIXIN_L_AMP_EN_MASK); /* Enable input filters unmuted */ - snd_soc_update_bits(codec, DA7219_ADC_L_CTRL, + snd_soc_component_update_bits(component, DA7219_ADC_L_CTRL, DA7219_ADC_L_MUTE_EN_MASK | DA7219_ADC_L_EN_MASK, DA7219_ADC_L_EN_MASK); /* Perform auto calibration */ - snd_soc_update_bits(codec, DA7219_ALC_CTRL1, + snd_soc_component_update_bits(component, DA7219_ALC_CTRL1, DA7219_ALC_AUTO_CALIB_EN_MASK, DA7219_ALC_AUTO_CALIB_EN_MASK); do { - calib_ctrl = snd_soc_read(codec, DA7219_ALC_CTRL1); + calib_ctrl = snd_soc_component_read32(component, DA7219_ALC_CTRL1); } while (calib_ctrl & DA7219_ALC_AUTO_CALIB_EN_MASK); /* If auto calibration fails, disable DC offset, hybrid ALC */ if (calib_ctrl & DA7219_ALC_CALIB_OVERFLOW_MASK) { - dev_warn(codec->dev, + dev_warn(component->dev, "ALC auto calibration failed with overflow\n"); - snd_soc_update_bits(codec, DA7219_ALC_CTRL1, + snd_soc_component_update_bits(component, DA7219_ALC_CTRL1, DA7219_ALC_OFFSET_EN_MASK | DA7219_ALC_SYNC_MODE_MASK, 0); } else { /* Enable DC offset cancellation, hybrid mode */ - snd_soc_update_bits(codec, DA7219_ALC_CTRL1, + snd_soc_component_update_bits(component, DA7219_ALC_CTRL1, DA7219_ALC_OFFSET_EN_MASK | DA7219_ALC_SYNC_MODE_MASK, DA7219_ALC_OFFSET_EN_MASK | @@ -366,20 +366,20 @@ static void da7219_alc_calib(struct snd_soc_codec *codec) } /* Restore input filter control register to original state */ - snd_soc_write(codec, DA7219_ADC_L_CTRL, adc_ctrl); + snd_soc_component_write(component, DA7219_ADC_L_CTRL, adc_ctrl); /* Restore input mixer control registers to original state */ - snd_soc_write(codec, DA7219_MIXIN_L_CTRL, mixin_ctrl); + snd_soc_component_write(component, DA7219_MIXIN_L_CTRL, mixin_ctrl); /* Restore MIC control registers to original states */ - snd_soc_write(codec, DA7219_MIC_1_CTRL, mic_ctrl); + snd_soc_component_write(component, DA7219_MIC_1_CTRL, mic_ctrl); } static int da7219_mixin_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); int ret; ret = snd_soc_put_volsw(kcontrol, ucontrol); @@ -389,7 +389,7 @@ static int da7219_mixin_gain_put(struct snd_kcontrol *kcontrol, * make sure calibrated offsets are updated. */ if ((ret == 1) && (da7219->alc_en)) - da7219_alc_calib(codec); + da7219_alc_calib(component); return ret; } @@ -397,13 +397,13 @@ static int da7219_mixin_gain_put(struct snd_kcontrol *kcontrol, static int da7219_alc_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); /* Force ALC offset calibration if enabling ALC */ if ((ucontrol->value.integer.value[0]) && (!da7219->alc_en)) { - da7219_alc_calib(codec); + da7219_alc_calib(component); da7219->alc_en = true; } else { da7219->alc_en = false; @@ -416,8 +416,8 @@ static int da7219_alc_sw_put(struct snd_kcontrol *kcontrol, static int da7219_tonegen_freq_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct soc_mixer_control *mixer_ctrl = (struct soc_mixer_control *) kcontrol->private_value; unsigned int reg = mixer_ctrl->reg; @@ -443,8 +443,8 @@ static int da7219_tonegen_freq_get(struct snd_kcontrol *kcontrol, static int da7219_tonegen_freq_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct soc_mixer_control *mixer_ctrl = (struct soc_mixer_control *) kcontrol->private_value; unsigned int reg = mixer_ctrl->reg; @@ -769,8 +769,8 @@ static const struct snd_kcontrol_new da7219_st_out_filtr_mix_controls[] = { static int da7219_dai_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 da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); u8 pll_ctrl, pll_status; int i = 0; bool srm_lock = false; @@ -779,22 +779,22 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w, case SND_SOC_DAPM_PRE_PMU: if (da7219->master) /* Enable DAI clks for master mode */ - snd_soc_update_bits(codec, DA7219_DAI_CLK_MODE, + snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE, DA7219_DAI_CLK_EN_MASK, DA7219_DAI_CLK_EN_MASK); /* PC synchronised to DAI */ - snd_soc_update_bits(codec, DA7219_PC_COUNT, + snd_soc_component_update_bits(component, DA7219_PC_COUNT, DA7219_PC_FREERUN_MASK, 0); /* Slave mode, if SRM not enabled no need for status checks */ - pll_ctrl = snd_soc_read(codec, DA7219_PLL_CTRL); + pll_ctrl = snd_soc_component_read32(component, DA7219_PLL_CTRL); if ((pll_ctrl & DA7219_PLL_MODE_MASK) != DA7219_PLL_MODE_SRM) return 0; /* Check SRM has locked */ do { - pll_status = snd_soc_read(codec, DA7219_PLL_SRM_STS); + pll_status = snd_soc_component_read32(component, DA7219_PLL_SRM_STS); if (pll_status & DA7219_PLL_SRM_STS_SRM_LOCK) { srm_lock = true; } else { @@ -804,18 +804,18 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w, } while ((i < DA7219_SRM_CHECK_RETRIES) & (!srm_lock)); if (!srm_lock) - dev_warn(codec->dev, "SRM failed to lock\n"); + dev_warn(component->dev, "SRM failed to lock\n"); return 0; case SND_SOC_DAPM_POST_PMD: /* PC free-running */ - snd_soc_update_bits(codec, DA7219_PC_COUNT, + snd_soc_component_update_bits(component, DA7219_PC_COUNT, DA7219_PC_FREERUN_MASK, DA7219_PC_FREERUN_MASK); /* Disable DAI clks if in master mode */ if (da7219->master) - snd_soc_update_bits(codec, DA7219_DAI_CLK_MODE, + snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE, DA7219_DAI_CLK_EN_MASK, 0); return 0; default: @@ -841,7 +841,7 @@ static int da7219_settling_event(struct snd_soc_dapm_widget *w, static int da7219_mixout_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); u8 hp_ctrl, min_gain_mask; switch (w->reg) { @@ -860,7 +860,7 @@ static int da7219_mixout_event(struct snd_soc_dapm_widget *w, switch (event) { case SND_SOC_DAPM_PRE_PMD: /* Enable minimum gain on HP to avoid pops */ - snd_soc_update_bits(codec, hp_ctrl, min_gain_mask, + snd_soc_component_update_bits(component, hp_ctrl, min_gain_mask, min_gain_mask); msleep(DA7219_MIN_GAIN_DELAY); @@ -868,7 +868,7 @@ static int da7219_mixout_event(struct snd_soc_dapm_widget *w, break; case SND_SOC_DAPM_POST_PMU: /* Remove minimum gain on HP */ - snd_soc_update_bits(codec, hp_ctrl, min_gain_mask, 0); + snd_soc_component_update_bits(component, hp_ctrl, min_gain_mask, 0); break; } @@ -879,22 +879,22 @@ static int da7219_mixout_event(struct snd_soc_dapm_widget *w, static int da7219_gain_ramp_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 da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_PRE_PMU: case SND_SOC_DAPM_PRE_PMD: /* Ensure nominal gain ramping for DAPM sequence */ da7219->gain_ramp_ctrl = - snd_soc_read(codec, DA7219_GAIN_RAMP_CTRL); - snd_soc_write(codec, DA7219_GAIN_RAMP_CTRL, + snd_soc_component_read32(component, DA7219_GAIN_RAMP_CTRL); + snd_soc_component_write(component, DA7219_GAIN_RAMP_CTRL, DA7219_GAIN_RAMP_RATE_NOMINAL); break; case SND_SOC_DAPM_POST_PMU: case SND_SOC_DAPM_POST_PMD: /* Restore previous gain ramp settings */ - snd_soc_write(codec, DA7219_GAIN_RAMP_CTRL, + snd_soc_component_write(component, DA7219_GAIN_RAMP_CTRL, da7219->gain_ramp_ctrl); break; } @@ -1116,8 +1116,8 @@ static const struct snd_soc_dapm_route da7219_audio_map[] = { static int da7219_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 da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); int ret = 0; if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) @@ -1133,12 +1133,12 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai, switch (clk_id) { case DA7219_CLKSRC_MCLK_SQR: - snd_soc_update_bits(codec, DA7219_PLL_CTRL, + snd_soc_component_update_bits(component, DA7219_PLL_CTRL, DA7219_PLL_MCLK_SQR_EN_MASK, DA7219_PLL_MCLK_SQR_EN_MASK); break; case DA7219_CLKSRC_MCLK: - snd_soc_update_bits(codec, DA7219_PLL_CTRL, + snd_soc_component_update_bits(component, DA7219_PLL_CTRL, DA7219_PLL_MCLK_SQR_EN_MASK, 0); break; default: @@ -1167,9 +1167,9 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai, return 0; } -int da7219_set_pll(struct snd_soc_codec *codec, int source, unsigned int fout) +int da7219_set_pll(struct snd_soc_component *component, int source, unsigned int fout) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); u8 pll_ctrl, indiv_bits, indiv; u8 pll_frac_top, pll_frac_bot, pll_integer; @@ -1178,7 +1178,7 @@ int da7219_set_pll(struct snd_soc_codec *codec, int source, unsigned int fout) /* Verify 2MHz - 54MHz MCLK provided, and set input divider */ if (da7219->mclk_rate < 2000000) { - dev_err(codec->dev, "PLL input clock %d below valid range\n", + dev_err(component->dev, "PLL input clock %d below valid range\n", da7219->mclk_rate); return -EINVAL; } else if (da7219->mclk_rate <= 4500000) { @@ -1197,7 +1197,7 @@ int da7219_set_pll(struct snd_soc_codec *codec, int source, unsigned int fout) indiv_bits = DA7219_PLL_INDIV_36_TO_54_MHZ; indiv = DA7219_PLL_INDIV_36_TO_54_MHZ_VAL; } else { - dev_err(codec->dev, "PLL input clock %d above valid range\n", + dev_err(component->dev, "PLL input clock %d above valid range\n", da7219->mclk_rate); return -EINVAL; } @@ -1208,7 +1208,7 @@ int da7219_set_pll(struct snd_soc_codec *codec, int source, unsigned int fout) switch (source) { case DA7219_SYSCLK_MCLK: pll_ctrl |= DA7219_PLL_MODE_BYPASS; - snd_soc_update_bits(codec, DA7219_PLL_CTRL, + snd_soc_component_update_bits(component, DA7219_PLL_CTRL, DA7219_PLL_INDIV_MASK | DA7219_PLL_MODE_MASK, pll_ctrl); return 0; @@ -1219,7 +1219,7 @@ int da7219_set_pll(struct snd_soc_codec *codec, int source, unsigned int fout) pll_ctrl |= DA7219_PLL_MODE_SRM; break; default: - dev_err(codec->dev, "Invalid PLL config\n"); + dev_err(component->dev, "Invalid PLL config\n"); return -EINVAL; } @@ -1231,10 +1231,10 @@ int da7219_set_pll(struct snd_soc_codec *codec, int source, unsigned int fout) pll_frac_bot = (frac_div) & DA7219_BYTE_MASK; /* Write PLL config & dividers */ - snd_soc_write(codec, DA7219_PLL_FRAC_TOP, pll_frac_top); - snd_soc_write(codec, DA7219_PLL_FRAC_BOT, pll_frac_bot); - snd_soc_write(codec, DA7219_PLL_INTEGER, pll_integer); - snd_soc_update_bits(codec, DA7219_PLL_CTRL, + snd_soc_component_write(component, DA7219_PLL_FRAC_TOP, pll_frac_top); + snd_soc_component_write(component, DA7219_PLL_FRAC_BOT, pll_frac_bot); + snd_soc_component_write(component, DA7219_PLL_INTEGER, pll_integer); + snd_soc_component_update_bits(component, DA7219_PLL_CTRL, DA7219_PLL_INDIV_MASK | DA7219_PLL_MODE_MASK, pll_ctrl); @@ -1244,12 +1244,12 @@ int da7219_set_pll(struct snd_soc_codec *codec, int source, unsigned int fout) static int da7219_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, int source, unsigned int fref, unsigned int fout) { - struct snd_soc_codec *codec = codec_dai->codec; - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); int ret; mutex_lock(&da7219->pll_lock); - ret = da7219_set_pll(codec, source, fout); + ret = da7219_set_pll(component, source, fout); mutex_unlock(&da7219->pll_lock); return ret; @@ -1257,8 +1257,8 @@ static int da7219_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, static int da7219_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { - struct snd_soc_codec *codec = codec_dai->codec; - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); u8 dai_clk_mode = 0, dai_ctrl = 0; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { @@ -1335,11 +1335,11 @@ static int da7219_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) /* By default 64 BCLKs per WCLK is supported */ dai_clk_mode |= DA7219_DAI_BCLKS_PER_WCLK_64; - snd_soc_update_bits(codec, DA7219_DAI_CLK_MODE, + snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE, DA7219_DAI_BCLKS_PER_WCLK_MASK | DA7219_DAI_CLK_POL_MASK | DA7219_DAI_WCLK_POL_MASK, dai_clk_mode); - snd_soc_update_bits(codec, DA7219_DAI_CTRL, DA7219_DAI_FORMAT_MASK, + snd_soc_component_update_bits(component, DA7219_DAI_CTRL, DA7219_DAI_FORMAT_MASK, dai_ctrl); return 0; @@ -1349,18 +1349,18 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) { - struct snd_soc_codec *codec = dai->codec; - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); u8 dai_bclks_per_wclk; u16 offset; u32 frame_size; /* No channels enabled so disable TDM, revert to 64-bit frames */ if (!tx_mask) { - snd_soc_update_bits(codec, DA7219_DAI_TDM_CTRL, + snd_soc_component_update_bits(component, DA7219_DAI_TDM_CTRL, DA7219_DAI_TDM_CH_EN_MASK | DA7219_DAI_TDM_MODE_EN_MASK, 0); - snd_soc_update_bits(codec, DA7219_DAI_CLK_MODE, + snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE, DA7219_DAI_BCLKS_PER_WCLK_MASK, DA7219_DAI_BCLKS_PER_WCLK_64); return 0; @@ -1368,14 +1368,14 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai, /* Check we have valid slots */ if (fls(tx_mask) > DA7219_DAI_TDM_MAX_SLOTS) { - dev_err(codec->dev, "Invalid number of slots, max = %d\n", + dev_err(component->dev, "Invalid number of slots, max = %d\n", DA7219_DAI_TDM_MAX_SLOTS); return -EINVAL; } /* Check we have a valid offset given */ if (rx_mask > DA7219_DAI_OFFSET_MAX) { - dev_err(codec->dev, "Invalid slot offset, max = %d\n", + dev_err(component->dev, "Invalid slot offset, max = %d\n", DA7219_DAI_OFFSET_MAX); return -EINVAL; } @@ -1396,11 +1396,11 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai, dai_bclks_per_wclk = DA7219_DAI_BCLKS_PER_WCLK_256; break; default: - dev_err(codec->dev, "Invalid frame size %d\n", frame_size); + dev_err(component->dev, "Invalid frame size %d\n", frame_size); return -EINVAL; } - snd_soc_update_bits(codec, DA7219_DAI_CLK_MODE, + snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE, DA7219_DAI_BCLKS_PER_WCLK_MASK, dai_bclks_per_wclk); @@ -1408,7 +1408,7 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai, regmap_bulk_write(da7219->regmap, DA7219_DAI_OFFSET_LOWER, &offset, sizeof(offset)); - snd_soc_update_bits(codec, DA7219_DAI_TDM_CTRL, + snd_soc_component_update_bits(component, DA7219_DAI_TDM_CTRL, DA7219_DAI_TDM_CH_EN_MASK | DA7219_DAI_TDM_MODE_EN_MASK, (tx_mask << DA7219_DAI_TDM_CH_EN_SHIFT) | @@ -1421,7 +1421,7 @@ static int da7219_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 dai_ctrl = 0, fs; unsigned int channels; @@ -1444,7 +1444,7 @@ static int da7219_hw_params(struct snd_pcm_substream *substream, channels = params_channels(params); if ((channels < 1) || (channels > DA7219_DAI_CH_NUM_MAX)) { - dev_err(codec->dev, + dev_err(component->dev, "Invalid number of channels, only 1 to %d supported\n", DA7219_DAI_CH_NUM_MAX); return -EINVAL; @@ -1489,11 +1489,11 @@ static int da7219_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - snd_soc_update_bits(codec, DA7219_DAI_CTRL, + snd_soc_component_update_bits(component, DA7219_DAI_CTRL, DA7219_DAI_WORD_LENGTH_MASK | DA7219_DAI_CH_NUM_MASK, dai_ctrl); - snd_soc_write(codec, DA7219_SR, fs); + snd_soc_component_write(component, DA7219_SR, fs); return 0; } @@ -1585,9 +1585,9 @@ static enum da7219_mic_amp_in_sel } } -static struct da7219_pdata *da7219_fw_to_pdata(struct snd_soc_codec *codec) +static struct da7219_pdata *da7219_fw_to_pdata(struct snd_soc_component *component) { - struct device *dev = codec->dev; + struct device *dev = component->dev; struct da7219_pdata *pdata; const char *of_str; u32 of_val32; @@ -1616,10 +1616,10 @@ static struct da7219_pdata *da7219_fw_to_pdata(struct snd_soc_codec *codec) * Codec driver functions */ -static int da7219_set_bias_level(struct snd_soc_codec *codec, +static int da7219_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); int ret; switch (level) { @@ -1627,11 +1627,11 @@ static int da7219_set_bias_level(struct snd_soc_codec *codec, break; case SND_SOC_BIAS_PREPARE: /* Enable MCLK for transition to ON state */ - if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY) { + if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY) { if (da7219->mclk) { ret = clk_prepare_enable(da7219->mclk); if (ret) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to enable mclk\n"); return ret; } @@ -1640,13 +1640,13 @@ static int da7219_set_bias_level(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) /* Master bias */ - snd_soc_update_bits(codec, DA7219_REFERENCES, + snd_soc_component_update_bits(component, DA7219_REFERENCES, DA7219_BIAS_EN_MASK, DA7219_BIAS_EN_MASK); - if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_PREPARE) { + if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_PREPARE) { /* Remove MCLK */ if (da7219->mclk) clk_disable_unprepare(da7219->mclk); @@ -1655,7 +1655,7 @@ static int da7219_set_bias_level(struct snd_soc_codec *codec, case SND_SOC_BIAS_OFF: /* Only disable master bias if we're not a wake-up source */ if (!da7219->wakeup_source) - snd_soc_update_bits(codec, DA7219_REFERENCES, + snd_soc_component_update_bits(component, DA7219_REFERENCES, DA7219_BIAS_EN_MASK, 0); break; @@ -1670,9 +1670,9 @@ static const char *da7219_supply_names[DA7219_NUM_SUPPLIES] = { [DA7219_SUPPLY_VDDIO] = "VDDIO", }; -static int da7219_handle_supplies(struct snd_soc_codec *codec) +static int da7219_handle_supplies(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct regulator *vddio; u8 io_voltage_lvl = DA7219_IO_VOLTAGE_LEVEL_2_5V_3_6V; int i, ret; @@ -1681,10 +1681,10 @@ static int da7219_handle_supplies(struct snd_soc_codec *codec) for (i = 0; i < DA7219_NUM_SUPPLIES; ++i) da7219->supplies[i].supply = da7219_supply_names[i]; - ret = devm_regulator_bulk_get(codec->dev, DA7219_NUM_SUPPLIES, + ret = devm_regulator_bulk_get(component->dev, DA7219_NUM_SUPPLIES, da7219->supplies); if (ret) { - dev_err(codec->dev, "Failed to get supplies"); + dev_err(component->dev, "Failed to get supplies"); return ret; } @@ -1692,29 +1692,29 @@ static int da7219_handle_supplies(struct snd_soc_codec *codec) vddio = da7219->supplies[DA7219_SUPPLY_VDDIO].consumer; ret = regulator_get_voltage(vddio); if (ret < 1200000) - dev_warn(codec->dev, "Invalid VDDIO voltage\n"); + dev_warn(component->dev, "Invalid VDDIO voltage\n"); else if (ret < 2800000) io_voltage_lvl = DA7219_IO_VOLTAGE_LEVEL_1_2V_2_8V; /* Enable main supplies */ ret = regulator_bulk_enable(DA7219_NUM_SUPPLIES, da7219->supplies); if (ret) { - dev_err(codec->dev, "Failed to enable supplies"); + dev_err(component->dev, "Failed to enable supplies"); return ret; } /* Ensure device in active mode */ - snd_soc_write(codec, DA7219_SYSTEM_ACTIVE, DA7219_SYSTEM_ACTIVE_MASK); + snd_soc_component_write(component, DA7219_SYSTEM_ACTIVE, DA7219_SYSTEM_ACTIVE_MASK); /* Update IO voltage level range */ - snd_soc_write(codec, DA7219_IO_CTRL, io_voltage_lvl); + snd_soc_component_write(component, DA7219_IO_CTRL, io_voltage_lvl); return 0; } -static void da7219_handle_pdata(struct snd_soc_codec *codec) +static void da7219_handle_pdata(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_pdata *pdata = da7219->pdata; if (pdata) { @@ -1735,14 +1735,14 @@ static void da7219_handle_pdata(struct snd_soc_codec *codec) break; } - snd_soc_write(codec, DA7219_MICBIAS_CTRL, micbias_lvl); + snd_soc_component_write(component, DA7219_MICBIAS_CTRL, micbias_lvl); /* Mic */ switch (pdata->mic_amp_in_sel) { case DA7219_MIC_AMP_IN_SEL_DIFF: case DA7219_MIC_AMP_IN_SEL_SE_P: case DA7219_MIC_AMP_IN_SEL_SE_N: - snd_soc_write(codec, DA7219_MIC_1_SELECT, + snd_soc_component_write(component, DA7219_MIC_1_SELECT, pdata->mic_amp_in_sel); break; } @@ -1753,9 +1753,9 @@ static struct reg_sequence da7219_rev_aa_patch[] = { { DA7219_REFERENCES, 0x08 }, }; -static int da7219_probe(struct snd_soc_codec *codec) +static int da7219_probe(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); unsigned int rev; int ret; @@ -1763,13 +1763,13 @@ static int da7219_probe(struct snd_soc_codec *codec) mutex_init(&da7219->pll_lock); /* Regulator configuration */ - ret = da7219_handle_supplies(codec); + ret = da7219_handle_supplies(component); if (ret) return ret; ret = regmap_read(da7219->regmap, DA7219_CHIP_REVISION, &rev); if (ret) { - dev_err(codec->dev, "Failed to read chip revision: %d\n", ret); + dev_err(component->dev, "Failed to read chip revision: %d\n", ret); goto err_disable_reg; } @@ -1778,7 +1778,7 @@ static int da7219_probe(struct snd_soc_codec *codec) ret = regmap_register_patch(da7219->regmap, da7219_rev_aa_patch, ARRAY_SIZE(da7219_rev_aa_patch)); if (ret) { - dev_err(codec->dev, "Failed to register AA patch: %d\n", + dev_err(component->dev, "Failed to register AA patch: %d\n", ret); goto err_disable_reg; } @@ -1788,14 +1788,14 @@ static int da7219_probe(struct snd_soc_codec *codec) } /* Handle DT/ACPI/Platform data */ - da7219->pdata = dev_get_platdata(codec->dev); + da7219->pdata = dev_get_platdata(component->dev); if (!da7219->pdata) - da7219->pdata = da7219_fw_to_pdata(codec); + da7219->pdata = da7219_fw_to_pdata(component); - da7219_handle_pdata(codec); + da7219_handle_pdata(component); /* Check if MCLK provided */ - da7219->mclk = devm_clk_get(codec->dev, "mclk"); + da7219->mclk = devm_clk_get(component->dev, "mclk"); if (IS_ERR(da7219->mclk)) { if (PTR_ERR(da7219->mclk) != -ENOENT) { ret = PTR_ERR(da7219->mclk); @@ -1806,39 +1806,39 @@ static int da7219_probe(struct snd_soc_codec *codec) } /* Default PC counter to free-running */ - snd_soc_update_bits(codec, DA7219_PC_COUNT, DA7219_PC_FREERUN_MASK, + snd_soc_component_update_bits(component, DA7219_PC_COUNT, DA7219_PC_FREERUN_MASK, DA7219_PC_FREERUN_MASK); /* Default gain ramping */ - snd_soc_update_bits(codec, DA7219_MIXIN_L_CTRL, + snd_soc_component_update_bits(component, DA7219_MIXIN_L_CTRL, DA7219_MIXIN_L_AMP_RAMP_EN_MASK, DA7219_MIXIN_L_AMP_RAMP_EN_MASK); - snd_soc_update_bits(codec, DA7219_ADC_L_CTRL, DA7219_ADC_L_RAMP_EN_MASK, + snd_soc_component_update_bits(component, DA7219_ADC_L_CTRL, DA7219_ADC_L_RAMP_EN_MASK, DA7219_ADC_L_RAMP_EN_MASK); - snd_soc_update_bits(codec, DA7219_DAC_L_CTRL, DA7219_DAC_L_RAMP_EN_MASK, + snd_soc_component_update_bits(component, DA7219_DAC_L_CTRL, DA7219_DAC_L_RAMP_EN_MASK, DA7219_DAC_L_RAMP_EN_MASK); - snd_soc_update_bits(codec, DA7219_DAC_R_CTRL, DA7219_DAC_R_RAMP_EN_MASK, + snd_soc_component_update_bits(component, DA7219_DAC_R_CTRL, DA7219_DAC_R_RAMP_EN_MASK, DA7219_DAC_R_RAMP_EN_MASK); - snd_soc_update_bits(codec, DA7219_HP_L_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_L_CTRL, DA7219_HP_L_AMP_RAMP_EN_MASK, DA7219_HP_L_AMP_RAMP_EN_MASK); - snd_soc_update_bits(codec, DA7219_HP_R_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_RAMP_EN_MASK, DA7219_HP_R_AMP_RAMP_EN_MASK); /* Default minimum gain on HP to avoid pops during DAPM sequencing */ - snd_soc_update_bits(codec, DA7219_HP_L_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_L_CTRL, DA7219_HP_L_AMP_MIN_GAIN_EN_MASK, DA7219_HP_L_AMP_MIN_GAIN_EN_MASK); - snd_soc_update_bits(codec, DA7219_HP_R_CTRL, + snd_soc_component_update_bits(component, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_MIN_GAIN_EN_MASK, DA7219_HP_R_AMP_MIN_GAIN_EN_MASK); /* Default infinite tone gen, start/stop by Kcontrol */ - snd_soc_write(codec, DA7219_TONE_GEN_CYCLES, DA7219_BEEP_CYCLES_MASK); + snd_soc_component_write(component, DA7219_TONE_GEN_CYCLES, DA7219_BEEP_CYCLES_MASK); /* Initialise AAD block */ - ret = da7219_aad_init(codec); + ret = da7219_aad_init(component); if (ret) goto err_disable_reg; @@ -1850,39 +1850,39 @@ err_disable_reg: return ret; } -static int da7219_remove(struct snd_soc_codec *codec) +static void da7219_remove(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); - da7219_aad_exit(codec); + da7219_aad_exit(component); /* Supplies */ - return regulator_bulk_disable(DA7219_NUM_SUPPLIES, da7219->supplies); + regulator_bulk_disable(DA7219_NUM_SUPPLIES, da7219->supplies); } #ifdef CONFIG_PM -static int da7219_suspend(struct snd_soc_codec *codec) +static int da7219_suspend(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); /* Suspend AAD if we're not a wake-up source */ if (!da7219->wakeup_source) - da7219_aad_suspend(codec); + da7219_aad_suspend(component); - snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF); + snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF); return 0; } -static int da7219_resume(struct snd_soc_codec *codec) +static int da7219_resume(struct snd_soc_component *component) { - struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec); + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); - snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY); + snd_soc_component_force_bias_level(component, SND_SOC_BIAS_STANDBY); /* Resume AAD if previously suspended */ if (!da7219->wakeup_source) - da7219_aad_resume(codec); + da7219_aad_resume(component); return 0; } @@ -1891,21 +1891,22 @@ static int da7219_resume(struct snd_soc_codec *codec) #define da7219_resume NULL #endif -static const struct snd_soc_codec_driver soc_codec_dev_da7219 = { +static const struct snd_soc_component_driver soc_component_dev_da7219 = { .probe = da7219_probe, .remove = da7219_remove, .suspend = da7219_suspend, .resume = da7219_resume, .set_bias_level = da7219_set_bias_level, - - .component_driver = { - .controls = da7219_snd_controls, - .num_controls = ARRAY_SIZE(da7219_snd_controls), - .dapm_widgets = da7219_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(da7219_dapm_widgets), - .dapm_routes = da7219_audio_map, - .num_dapm_routes = ARRAY_SIZE(da7219_audio_map), - }, + .controls = da7219_snd_controls, + .num_controls = ARRAY_SIZE(da7219_snd_controls), + .dapm_widgets = da7219_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(da7219_dapm_widgets), + .dapm_routes = da7219_audio_map, + .num_dapm_routes = ARRAY_SIZE(da7219_audio_map), + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; @@ -2090,7 +2091,7 @@ static int da7219_i2c_probe(struct i2c_client *i2c, } } - /* Soft reset codec */ + /* Soft reset component */ regmap_write_bits(da7219->regmap, DA7219_ACCDET_CONFIG_1, DA7219_ACCDET_EN_MASK, 0); regmap_write_bits(da7219->regmap, DA7219_CIF_CTRL, @@ -2101,10 +2102,11 @@ static int da7219_i2c_probe(struct i2c_client *i2c, regcache_cache_bypass(da7219->regmap, false); - ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_da7219, + ret = devm_snd_soc_register_component(&i2c->dev, + &soc_component_dev_da7219, &da7219_dai, 1); if (ret < 0) { - dev_err(&i2c->dev, "Failed to register da7219 codec: %d\n", + dev_err(&i2c->dev, "Failed to register da7219 component: %d\n", ret); } return ret; @@ -2112,7 +2114,6 @@ static int da7219_i2c_probe(struct i2c_client *i2c, static int da7219_i2c_remove(struct i2c_client *client) { - snd_soc_unregister_codec(&client->dev); return 0; } diff --git a/sound/soc/codecs/da7219.h b/sound/soc/codecs/da7219.h index 8d6c3c8c8026..1acb34cd12ad 100644 --- a/sound/soc/codecs/da7219.h +++ b/sound/soc/codecs/da7219.h @@ -822,6 +822,6 @@ struct da7219_priv { u8 gain_ramp_ctrl; }; -int da7219_set_pll(struct snd_soc_codec *codec, int source, unsigned int fout); +int da7219_set_pll(struct snd_soc_component *component, int source, unsigned int fout); #endif /* __DA7219_H */ diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c index dba6f4c5074a..84f7a7a36e4b 100644 --- a/sound/soc/codecs/hdac_hdmi.c +++ b/sound/soc/codecs/hdac_hdmi.c @@ -718,10 +718,22 @@ static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_ext_device *edev, static void hdac_hdmi_set_power_state(struct hdac_ext_device *edev, hda_nid_t nid, unsigned int pwr_state) { + int count; + unsigned int state; + if (get_wcaps(&edev->hdev, nid) & AC_WCAP_POWER) { - if (!snd_hdac_check_power_state(&edev->hdev, nid, pwr_state)) - snd_hdac_codec_write(&edev->hdev, nid, 0, - AC_VERB_SET_POWER_STATE, pwr_state); + if (!snd_hdac_check_power_state(&edev->hdev, nid, pwr_state)) { + for (count = 0; count < 10; count++) { + snd_hdac_codec_read(&edev->hdev, nid, 0, + AC_VERB_SET_POWER_STATE, + pwr_state); + state = snd_hdac_sync_power_state(&edev->hdev, + nid, pwr_state); + if (!(state & AC_PWRST_ERROR)) + break; + } + } + } } @@ -1536,7 +1548,7 @@ static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe) struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev); struct hdac_hdmi_pin *pin = NULL; struct hdac_hdmi_port *hport = NULL; - struct snd_soc_codec *codec = edev->scodec; + struct snd_soc_component *component = edev->scodec; int i; /* Don't know how this mapping is derived */ @@ -1551,7 +1563,7 @@ static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe) * connection states are updated in anyway at the end of the resume, * we can skip it when received during PM process. */ - if (snd_power_get_state(codec->component.card->snd_card) != + if (snd_power_get_state(component->card->snd_card) != SNDRV_CTL_POWER_D0) return; @@ -1609,10 +1621,10 @@ static int create_fill_jack_kcontrols(struct snd_soc_card *card, char kc_name[NAME_SIZE], xname[NAME_SIZE]; char *name; int i = 0, j; - struct snd_soc_codec *codec = edev->scodec; + struct snd_soc_component *component = edev->scodec; struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev); - kc = devm_kcalloc(codec->dev, hdmi->num_ports, + kc = devm_kcalloc(component->dev, hdmi->num_ports, sizeof(*kc), GFP_KERNEL); if (!kc) @@ -1622,11 +1634,11 @@ static int create_fill_jack_kcontrols(struct snd_soc_card *card, for (j = 0; j < pin->num_ports; j++) { snprintf(xname, sizeof(xname), "hif%d-%d Jack", pin->nid, pin->ports[j].id); - name = devm_kstrdup(codec->dev, xname, GFP_KERNEL); + name = devm_kstrdup(component->dev, xname, GFP_KERNEL); if (!name) return -ENOMEM; snprintf(kc_name, sizeof(kc_name), "%s Switch", xname); - kc[i].name = devm_kstrdup(codec->dev, kc_name, + kc[i].name = devm_kstrdup(component->dev, kc_name, GFP_KERNEL); if (!kc[i].name) return -ENOMEM; @@ -1644,10 +1656,10 @@ static int create_fill_jack_kcontrols(struct snd_soc_card *card, return snd_soc_add_card_controls(card, kc, i); } -int hdac_hdmi_jack_port_init(struct snd_soc_codec *codec, +int hdac_hdmi_jack_port_init(struct snd_soc_component *component, struct snd_soc_dapm_context *dapm) { - struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); + struct hdac_ext_device *edev = snd_soc_component_get_drvdata(component); struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev); struct hdac_hdmi_pin *pin; struct snd_soc_dapm_widget *widgets; @@ -1722,8 +1734,8 @@ EXPORT_SYMBOL_GPL(hdac_hdmi_jack_port_init); int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device, struct snd_soc_jack *jack) { - struct snd_soc_codec *codec = dai->codec; - struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct hdac_ext_device *edev = snd_soc_component_get_drvdata(component); struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev); struct hdac_hdmi_pcm *pcm; struct snd_pcm *snd_pcm; @@ -1784,16 +1796,16 @@ static void hdac_hdmi_present_sense_all_pins(struct hdac_ext_device *edev, } } -static int hdmi_codec_probe(struct snd_soc_codec *codec) +static int hdmi_codec_probe(struct snd_soc_component *component) { - struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); + struct hdac_ext_device *edev = snd_soc_component_get_drvdata(component); struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev); struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(&codec->component); + snd_soc_component_get_dapm(component); struct hdac_ext_link *hlink = NULL; int ret; - edev->scodec = codec; + edev->scodec = component; /* * hold the ref while we probe, also no need to drop the ref on @@ -1834,12 +1846,11 @@ static int hdmi_codec_probe(struct snd_soc_codec *codec) return 0; } -static int hdmi_codec_remove(struct snd_soc_codec *codec) +static void hdmi_codec_remove(struct snd_soc_component *component) { - struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); + struct hdac_ext_device *edev = snd_soc_component_get_drvdata(component); pm_runtime_disable(&edev->hdev.dev); - return 0; } #ifdef CONFIG_PM @@ -1891,10 +1902,12 @@ static void hdmi_codec_complete(struct device *dev) #define hdmi_codec_complete NULL #endif -static const struct snd_soc_codec_driver hdmi_hda_codec = { - .probe = hdmi_codec_probe, - .remove = hdmi_codec_remove, - .idle_bias_off = true, +static const struct snd_soc_component_driver hdmi_hda_codec = { + .probe = hdmi_codec_probe, + .remove = hdmi_codec_remove, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static void hdac_hdmi_get_chmap(struct hdac_device *hdev, int pcm_idx, @@ -2042,7 +2055,7 @@ static int hdac_hdmi_dev_probe(struct hdac_ext_device *edev) snd_hdac_refresh_widgets(hdev, true); /* ASoC specific initialization */ - ret = snd_soc_register_codec(&hdev->dev, &hdmi_hda_codec, + ret = devm_snd_soc_register_component(&hdev->dev, &hdmi_hda_codec, hdmi_dais, num_dais); snd_hdac_ext_bus_link_put(edev->ebus, hlink); @@ -2059,8 +2072,6 @@ static int hdac_hdmi_dev_remove(struct hdac_ext_device *edev) struct hdac_hdmi_port *port, *port_next; int i; - snd_soc_unregister_codec(&edev->hdev.dev); - list_for_each_entry_safe(pcm, pcm_next, &hdmi->pcm_list, head) { pcm->cvt = NULL; if (list_empty(&pcm->port_list)) diff --git a/sound/soc/codecs/hdac_hdmi.h b/sound/soc/codecs/hdac_hdmi.h index b5b57a5cbbfd..4fa2fc9ee893 100644 --- a/sound/soc/codecs/hdac_hdmi.h +++ b/sound/soc/codecs/hdac_hdmi.h @@ -5,6 +5,6 @@ int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int pcm, struct snd_soc_jack *jack); -int hdac_hdmi_jack_port_init(struct snd_soc_codec *codec, +int hdac_hdmi_jack_port_init(struct snd_soc_component *component, struct snd_soc_dapm_context *dapm); #endif /* __HDAC_HDMI_H__ */ diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index 5672e516bec3..c1830ccd3bb8 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -798,12 +798,7 @@ static int hdmi_codec_probe(struct platform_device *pdev) static int hdmi_codec_remove(struct platform_device *pdev) { - struct device *dev = &pdev->dev; - struct hdmi_codec_priv *hcp; - - hcp = dev_get_drvdata(dev); - kfree(hcp->chmap_info); - snd_soc_unregister_codec(dev); + snd_soc_unregister_codec(&pdev->dev); return 0; } diff --git a/sound/soc/codecs/nau8825.c b/sound/soc/codecs/nau8825.c index a1b697b6fb64..dc6ea4987b7d 100644 --- a/sound/soc/codecs/nau8825.c +++ b/sound/soc/codecs/nau8825.c @@ -914,8 +914,8 @@ static bool nau8825_volatile_reg(struct device *dev, unsigned int reg) static int nau8825_adc_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 nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_POST_PMU: @@ -938,8 +938,8 @@ static int nau8825_adc_event(struct snd_soc_dapm_widget *w, static int nau8825_pump_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 nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_POST_PMU: @@ -962,8 +962,8 @@ static int nau8825_pump_event(struct snd_soc_dapm_widget *w, static int nau8825_output_dac_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 nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_PRE_PMU: @@ -1244,8 +1244,8 @@ static int nau8825_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 nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); unsigned int val_len = 0, osr, ctrl_val, bclk_fs, bclk_div; nau8825_sema_acquire(nau8825, 3 * HZ); @@ -1329,8 +1329,8 @@ static int nau8825_hw_params(struct snd_pcm_substream *substream, static int nau8825_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { - struct snd_soc_codec *codec = codec_dai->codec; - struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); unsigned int ctrl1_val = 0, ctrl2_val = 0; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { @@ -1427,10 +1427,10 @@ static struct snd_soc_dai_driver nau8825_dai = { * events will be routed to the given jack. Jack can be null to stop * reporting. */ -int nau8825_enable_jack_detect(struct snd_soc_codec *codec, +int nau8825_enable_jack_detect(struct snd_soc_component *component, struct snd_soc_jack *jack) { - struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); struct regmap *regmap = nau8825->regmap; nau8825->jack = jack; @@ -1952,24 +1952,22 @@ static const struct regmap_config nau8825_regmap_config = { .num_reg_defaults = ARRAY_SIZE(nau8825_reg_defaults), }; -static int nau8825_codec_probe(struct snd_soc_codec *codec) +static int nau8825_component_probe(struct snd_soc_component *component) { - struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); nau8825->dapm = dapm; return 0; } -static int nau8825_codec_remove(struct snd_soc_codec *codec) +static void nau8825_component_remove(struct snd_soc_component *component) { - struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); /* Cancel and reset cross tak suppresstion detection funciton */ nau8825_xtalk_cancel(nau8825); - - return 0; } /** @@ -2084,20 +2082,20 @@ static void nau8825_fll_apply(struct nau8825 *nau8825, } /* freq_out must be 256*Fs in order to achieve the best performance */ -static int nau8825_set_pll(struct snd_soc_codec *codec, int pll_id, int source, +static int nau8825_set_pll(struct snd_soc_component *component, int pll_id, int source, unsigned int freq_in, unsigned int freq_out) { - struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); struct nau8825_fll fll_param; int ret, fs; fs = freq_out / 256; ret = nau8825_calc_fll_param(freq_in, fs, &fll_param); if (ret < 0) { - dev_err(codec->dev, "Unsupported input clock %d\n", freq_in); + dev_err(component->dev, "Unsupported input clock %d\n", freq_in); return ret; } - dev_dbg(codec->dev, "mclk_src=%x ratio=%x fll_frac=%x fll_int=%x clk_ref_div=%x\n", + dev_dbg(component->dev, "mclk_src=%x ratio=%x fll_frac=%x fll_int=%x clk_ref_div=%x\n", fll_param.mclk_src, fll_param.ratio, fll_param.fll_frac, fll_param.fll_int, fll_param.clk_ref_div); @@ -2298,10 +2296,10 @@ static int nau8825_configure_sysclk(struct nau8825 *nau8825, int clk_id, return 0; } -static int nau8825_set_sysclk(struct snd_soc_codec *codec, int clk_id, +static int nau8825_set_sysclk(struct snd_soc_component *component, int clk_id, int source, unsigned int freq, int dir) { - struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); return nau8825_configure_sysclk(nau8825, clk_id, freq); } @@ -2331,10 +2329,10 @@ static int nau8825_resume_setup(struct nau8825 *nau8825) return 0; } -static int nau8825_set_bias_level(struct snd_soc_codec *codec, +static int nau8825_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); int ret; switch (level) { @@ -2345,11 +2343,11 @@ static int nau8825_set_bias_level(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) { if (nau8825->mclk_freq) { ret = clk_prepare_enable(nau8825->mclk); if (ret) { - dev_err(nau8825->dev, "Unable to prepare codec mclk\n"); + dev_err(nau8825->dev, "Unable to prepare component mclk\n"); return ret; } } @@ -2383,12 +2381,12 @@ static int nau8825_set_bias_level(struct snd_soc_codec *codec, return 0; } -static int __maybe_unused nau8825_suspend(struct snd_soc_codec *codec) +static int __maybe_unused nau8825_suspend(struct snd_soc_component *component) { - struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); disable_irq(nau8825->irq); - snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF); + snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF); /* Power down codec power; don't suppoet button wakeup */ snd_soc_dapm_disable_pin(nau8825->dapm, "SAR"); snd_soc_dapm_disable_pin(nau8825->dapm, "MICBIAS"); @@ -2399,9 +2397,9 @@ static int __maybe_unused nau8825_suspend(struct snd_soc_codec *codec) return 0; } -static int __maybe_unused nau8825_resume(struct snd_soc_codec *codec) +static int __maybe_unused nau8825_resume(struct snd_soc_component *component) { - struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); + struct nau8825 *nau8825 = snd_soc_component_get_drvdata(component); int ret; regcache_cache_only(nau8825->regmap, false); @@ -2415,24 +2413,25 @@ static int __maybe_unused nau8825_resume(struct snd_soc_codec *codec) return 0; } -static const struct snd_soc_codec_driver nau8825_codec_driver = { - .probe = nau8825_codec_probe, - .remove = nau8825_codec_remove, - .set_sysclk = nau8825_set_sysclk, - .set_pll = nau8825_set_pll, - .set_bias_level = nau8825_set_bias_level, - .suspend_bias_off = true, - .suspend = nau8825_suspend, - .resume = nau8825_resume, - - .component_driver = { - .controls = nau8825_controls, - .num_controls = ARRAY_SIZE(nau8825_controls), - .dapm_widgets = nau8825_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(nau8825_dapm_widgets), - .dapm_routes = nau8825_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(nau8825_dapm_routes), - }, +static const struct snd_soc_component_driver nau8825_component_driver = { + .probe = nau8825_component_probe, + .remove = nau8825_component_remove, + .set_sysclk = nau8825_set_sysclk, + .set_pll = nau8825_set_pll, + .set_bias_level = nau8825_set_bias_level, + .suspend = nau8825_suspend, + .resume = nau8825_resume, + .controls = nau8825_controls, + .num_controls = ARRAY_SIZE(nau8825_controls), + .dapm_widgets = nau8825_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(nau8825_dapm_widgets), + .dapm_routes = nau8825_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(nau8825_dapm_routes), + .suspend_bias_off = 1, + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static void nau8825_reset_chip(struct regmap *regmap) @@ -2619,13 +2618,13 @@ static int nau8825_i2c_probe(struct i2c_client *i2c, if (i2c->irq) nau8825_setup_irq(nau8825); - return snd_soc_register_codec(&i2c->dev, &nau8825_codec_driver, + return devm_snd_soc_register_component(&i2c->dev, + &nau8825_component_driver, &nau8825_dai, 1); } static int nau8825_i2c_remove(struct i2c_client *client) { - snd_soc_unregister_codec(&client->dev); return 0; } diff --git a/sound/soc/codecs/nau8825.h b/sound/soc/codecs/nau8825.h index f7e732125882..f6074c618569 100644 --- a/sound/soc/codecs/nau8825.h +++ b/sound/soc/codecs/nau8825.h @@ -480,7 +480,7 @@ struct nau8825 { bool xtalk_baktab_initialized; /* True if initialized. */ }; -int nau8825_enable_jack_detect(struct snd_soc_codec *codec, +int nau8825_enable_jack_detect(struct snd_soc_component *component, struct snd_soc_jack *jack); diff --git a/sound/soc/codecs/pcm1681.c b/sound/soc/codecs/pcm1681.c index c7e28dd2e815..84777d3fa464 100644 --- a/sound/soc/codecs/pcm1681.c +++ b/sound/soc/codecs/pcm1681.c @@ -90,9 +90,9 @@ struct pcm1681_private { static const int pcm1681_deemph[] = { 44100, 48000, 32000 }; -static int pcm1681_set_deemph(struct snd_soc_codec *codec) +static int pcm1681_set_deemph(struct snd_soc_component *component) { - struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); + struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); int i = 0, val = -1, enable = 0; if (priv->deemph) { @@ -120,8 +120,8 @@ static int pcm1681_set_deemph(struct snd_soc_codec *codec) static int pcm1681_get_deemph(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); ucontrol->value.integer.value[0] = priv->deemph; @@ -131,23 +131,23 @@ static int pcm1681_get_deemph(struct snd_kcontrol *kcontrol, static int pcm1681_put_deemph(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); priv->deemph = ucontrol->value.integer.value[0]; - return pcm1681_set_deemph(codec); + return pcm1681_set_deemph(component); } static int pcm1681_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int format) { - struct snd_soc_codec *codec = codec_dai->codec; - struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); /* The PCM1681 can only be slave to all clocks */ if ((format & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) { - dev_err(codec->dev, "Invalid clocking mode\n"); + dev_err(component->dev, "Invalid clocking mode\n"); return -EINVAL; } @@ -158,8 +158,8 @@ static int pcm1681_set_dai_fmt(struct snd_soc_dai *codec_dai, static int pcm1681_digital_mute(struct snd_soc_dai *dai, int mute) { - struct snd_soc_codec *codec = dai->codec; - struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); int val; if (mute) @@ -174,8 +174,8 @@ static int pcm1681_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 pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); int val = 0, ret; priv->rate = params_rate(params); @@ -200,7 +200,7 @@ static int pcm1681_hw_params(struct snd_pcm_substream *substream, val = 0x05; break; default: - dev_err(codec->dev, "Invalid DAI format\n"); + dev_err(component->dev, "Invalid DAI format\n"); return -EINVAL; } @@ -208,7 +208,7 @@ static int pcm1681_hw_params(struct snd_pcm_substream *substream, if (ret < 0) return ret; - return pcm1681_set_deemph(codec); + return pcm1681_set_deemph(component); } static const struct snd_soc_dai_ops pcm1681_dai_ops = { @@ -288,15 +288,17 @@ static const struct regmap_config pcm1681_regmap = { .readable_reg = pcm1681_accessible_reg, }; -static const struct snd_soc_codec_driver soc_codec_dev_pcm1681 = { - .component_driver = { - .controls = pcm1681_controls, - .num_controls = ARRAY_SIZE(pcm1681_controls), - .dapm_widgets = pcm1681_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(pcm1681_dapm_widgets), - .dapm_routes = pcm1681_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(pcm1681_dapm_routes), - }, +static const struct snd_soc_component_driver soc_component_dev_pcm1681 = { + .controls = pcm1681_controls, + .num_controls = ARRAY_SIZE(pcm1681_controls), + .dapm_widgets = pcm1681_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(pcm1681_dapm_widgets), + .dapm_routes = pcm1681_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(pcm1681_dapm_routes), + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static const struct i2c_device_id pcm1681_i2c_id[] = { @@ -324,16 +326,11 @@ static int pcm1681_i2c_probe(struct i2c_client *client, i2c_set_clientdata(client, priv); - return snd_soc_register_codec(&client->dev, &soc_codec_dev_pcm1681, + return devm_snd_soc_register_component(&client->dev, + &soc_component_dev_pcm1681, &pcm1681_dai, 1); } -static int pcm1681_i2c_remove(struct i2c_client *client) -{ - snd_soc_unregister_codec(&client->dev); - return 0; -} - static struct i2c_driver pcm1681_i2c_driver = { .driver = { .name = "pcm1681", @@ -341,7 +338,6 @@ static struct i2c_driver pcm1681_i2c_driver = { }, .id_table = pcm1681_i2c_id, .probe = pcm1681_i2c_probe, - .remove = pcm1681_i2c_remove, }; module_i2c_driver(pcm1681_i2c_driver); diff --git a/sound/soc/codecs/pcm1789-i2c.c b/sound/soc/codecs/pcm1789-i2c.c new file mode 100644 index 000000000000..327ec584f240 --- /dev/null +++ b/sound/soc/codecs/pcm1789-i2c.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 +// Audio driver for PCM1789 I2C +// Copyright (C) 2018 Bootlin +// Mylène Josserand <mylene.josserand@bootlin.com> + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/regmap.h> + +#include "pcm1789.h" + +static int pcm1789_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct regmap *regmap; + int ret; + + regmap = devm_regmap_init_i2c(client, &pcm1789_regmap_config); + if (IS_ERR(regmap)) { + ret = PTR_ERR(regmap); + dev_err(&client->dev, "Failed to allocate regmap: %d\n", ret); + return ret; + } + + return pcm1789_common_init(&client->dev, regmap); +} + +static int pcm1789_i2c_remove(struct i2c_client *client) +{ + return pcm1789_common_exit(&client->dev); +} + +static const struct of_device_id pcm1789_of_match[] = { + { .compatible = "ti,pcm1789", }, + { } +}; +MODULE_DEVICE_TABLE(of, pcm1789_of_match); + +static const struct i2c_device_id pcm1789_i2c_ids[] = { + { "pcm1789", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, pcm1789_i2c_ids); + +static struct i2c_driver pcm1789_i2c_driver = { + .driver = { + .name = "pcm1789", + .of_match_table = of_match_ptr(pcm1789_of_match), + }, + .id_table = pcm1789_i2c_ids, + .probe = pcm1789_i2c_probe, + .remove = pcm1789_i2c_remove, +}; + +module_i2c_driver(pcm1789_i2c_driver); + +MODULE_DESCRIPTION("ASoC PCM1789 I2C driver"); +MODULE_AUTHOR("Mylène Josserand <mylene.josserand@bootlin.com>"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/pcm1789.c b/sound/soc/codecs/pcm1789.c new file mode 100644 index 000000000000..507ac9412d6c --- /dev/null +++ b/sound/soc/codecs/pcm1789.c @@ -0,0 +1,274 @@ +// SPDX-License-Identifier: GPL-2.0 +// Audio driver for PCM1789 +// Copyright (C) 2018 Bootlin +// Mylène Josserand <mylene.josserand@bootlin.com> + +#include <linux/gpio.h> +#include <linux/module.h> +#include <linux/workqueue.h> + +#include <sound/pcm_params.h> +#include <sound/soc.h> +#include <sound/tlv.h> + +#include "pcm1789.h" + +#define PCM1789_MUTE_CONTROL 0x10 +#define PCM1789_FMT_CONTROL 0x11 +#define PCM1789_SOFT_MUTE 0x14 +#define PCM1789_DAC_VOL_LEFT 0x18 +#define PCM1789_DAC_VOL_RIGHT 0x19 + +#define PCM1789_FMT_MASK 0x07 +#define PCM1789_MUTE_MASK 0x03 +#define PCM1789_MUTE_SRET 0x06 + +struct pcm1789_private { + struct regmap *regmap; + unsigned int format; + unsigned int rate; + struct gpio_desc *reset; + struct work_struct work; + struct device *dev; +}; + +static const struct reg_default pcm1789_reg_defaults[] = { + { PCM1789_FMT_CONTROL, 0x00 }, + { PCM1789_SOFT_MUTE, 0x00 }, + { PCM1789_DAC_VOL_LEFT, 0xff }, + { PCM1789_DAC_VOL_RIGHT, 0xff }, +}; + +static bool pcm1789_accessible_reg(struct device *dev, unsigned int reg) +{ + return reg >= PCM1789_MUTE_CONTROL && reg <= PCM1789_DAC_VOL_RIGHT; +} + +static bool pcm1789_writeable_reg(struct device *dev, unsigned int reg) +{ + return pcm1789_accessible_reg(dev, reg); +} + +static int pcm1789_set_dai_fmt(struct snd_soc_dai *codec_dai, + unsigned int format) +{ + struct snd_soc_component *component = codec_dai->component; + struct pcm1789_private *priv = snd_soc_component_get_drvdata(component); + + priv->format = format; + + return 0; +} + +static int pcm1789_digital_mute(struct snd_soc_dai *codec_dai, int mute) +{ + struct snd_soc_component *component = codec_dai->component; + struct pcm1789_private *priv = snd_soc_component_get_drvdata(component); + + return regmap_update_bits(priv->regmap, PCM1789_SOFT_MUTE, + PCM1789_MUTE_MASK, + mute ? 0 : PCM1789_MUTE_MASK); +} + +static int pcm1789_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *codec_dai) +{ + struct snd_soc_component *component = codec_dai->component; + struct pcm1789_private *priv = snd_soc_component_get_drvdata(component); + int val = 0, ret; + + priv->rate = params_rate(params); + + switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) { + case SND_SOC_DAIFMT_RIGHT_J: + switch (params_width(params)) { + case 24: + val = 2; + break; + case 16: + val = 3; + break; + default: + return -EINVAL; + } + break; + case SND_SOC_DAIFMT_I2S: + switch (params_width(params)) { + case 16: + case 24: + case 32: + val = 0; + break; + default: + return -EINVAL; + } + break; + case SND_SOC_DAIFMT_LEFT_J: + switch (params_width(params)) { + case 16: + case 24: + case 32: + val = 1; + break; + default: + return -EINVAL; + } + break; + default: + dev_err(component->dev, "Invalid DAI format\n"); + return -EINVAL; + } + + ret = regmap_update_bits(priv->regmap, PCM1789_FMT_CONTROL, + PCM1789_FMT_MASK, val); + if (ret < 0) + return ret; + + return 0; +} + +static void pcm1789_work_queue(struct work_struct *work) +{ + struct pcm1789_private *priv = container_of(work, + struct pcm1789_private, + work); + + /* Perform a software reset to remove codec from desynchronized state */ + if (regmap_update_bits(priv->regmap, PCM1789_MUTE_CONTROL, + 0x3 << PCM1789_MUTE_SRET, 0) < 0) + dev_err(priv->dev, "Error while setting SRET"); +} + +static int pcm1789_trigger(struct snd_pcm_substream *substream, int cmd, + struct snd_soc_dai *dai) +{ + struct snd_soc_component *component = dai->component; + struct pcm1789_private *priv = snd_soc_component_get_drvdata(component); + int ret = 0; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + schedule_work(&priv->work); + break; + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + break; + default: + ret = -EINVAL; + } + + return ret; +} + +static const struct snd_soc_dai_ops pcm1789_dai_ops = { + .set_fmt = pcm1789_set_dai_fmt, + .hw_params = pcm1789_hw_params, + .digital_mute = pcm1789_digital_mute, + .trigger = pcm1789_trigger, +}; + +static const DECLARE_TLV_DB_SCALE(pcm1789_dac_tlv, -12000, 50, 1); + +static const struct snd_kcontrol_new pcm1789_controls[] = { + SOC_DOUBLE_R_RANGE_TLV("DAC Playback Volume", PCM1789_DAC_VOL_LEFT, + PCM1789_DAC_VOL_RIGHT, 0, 0xf, 0xff, 0, + pcm1789_dac_tlv), +}; + +static const struct snd_soc_dapm_widget pcm1789_dapm_widgets[] = { + SND_SOC_DAPM_OUTPUT("IOUTL+"), + SND_SOC_DAPM_OUTPUT("IOUTL-"), + SND_SOC_DAPM_OUTPUT("IOUTR+"), + SND_SOC_DAPM_OUTPUT("IOUTR-"), +}; + +static const struct snd_soc_dapm_route pcm1789_dapm_routes[] = { + { "IOUTL+", NULL, "Playback" }, + { "IOUTL-", NULL, "Playback" }, + { "IOUTR+", NULL, "Playback" }, + { "IOUTR-", NULL, "Playback" }, +}; + +static struct snd_soc_dai_driver pcm1789_dai = { + .name = "pcm1789-hifi", + .playback = { + .stream_name = "Playback", + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_CONTINUOUS, + .rate_min = 10000, + .rate_max = 200000, + .formats = PCM1789_FORMATS, + }, + .ops = &pcm1789_dai_ops, +}; + +const struct regmap_config pcm1789_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = PCM1789_DAC_VOL_RIGHT, + .reg_defaults = pcm1789_reg_defaults, + .num_reg_defaults = ARRAY_SIZE(pcm1789_reg_defaults), + .writeable_reg = pcm1789_writeable_reg, + .readable_reg = pcm1789_accessible_reg, +}; +EXPORT_SYMBOL_GPL(pcm1789_regmap_config); + +static const struct snd_soc_component_driver soc_component_dev_pcm1789 = { + .controls = pcm1789_controls, + .num_controls = ARRAY_SIZE(pcm1789_controls), + .dapm_widgets = pcm1789_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(pcm1789_dapm_widgets), + .dapm_routes = pcm1789_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(pcm1789_dapm_routes), + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, +}; + +int pcm1789_common_init(struct device *dev, struct regmap *regmap) +{ + struct pcm1789_private *pcm1789; + + pcm1789 = devm_kzalloc(dev, sizeof(struct pcm1789_private), + GFP_KERNEL); + if (!pcm1789) + return -ENOMEM; + + pcm1789->regmap = regmap; + pcm1789->dev = dev; + dev_set_drvdata(dev, pcm1789); + + pcm1789->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(pcm1789->reset)) + return PTR_ERR(pcm1789->reset); + + gpiod_set_value_cansleep(pcm1789->reset, 0); + msleep(300); + + INIT_WORK(&pcm1789->work, pcm1789_work_queue); + + return devm_snd_soc_register_component(dev, &soc_component_dev_pcm1789, + &pcm1789_dai, 1); +} +EXPORT_SYMBOL_GPL(pcm1789_common_init); + +int pcm1789_common_exit(struct device *dev) +{ + struct pcm1789_private *priv = dev_get_drvdata(dev); + + if (&priv->work) + flush_work(&priv->work); + + return 0; +} +EXPORT_SYMBOL_GPL(pcm1789_common_exit); + +MODULE_DESCRIPTION("ASoC PCM1789 driver"); +MODULE_AUTHOR("Mylène Josserand <mylene.josserand@free-electrons.com>"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/pcm1789.h b/sound/soc/codecs/pcm1789.h new file mode 100644 index 000000000000..c446d789ed48 --- /dev/null +++ b/sound/soc/codecs/pcm1789.h @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 +// Definitions for PCM1789 audio driver +// Copyright (C) 2018 Bootlin +// Mylène Josserand <mylene.josserand@bootlin.com> + +#ifndef __PCM1789_H__ +#define __PCM1789_H__ + +#define PCM1789_FORMATS (SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S24_LE | \ + SNDRV_PCM_FMTBIT_S16_LE) + +extern const struct regmap_config pcm1789_regmap_config; + +int pcm1789_common_init(struct device *dev, struct regmap *regmap); +int pcm1789_common_exit(struct device *dev); + +#endif diff --git a/sound/soc/codecs/pcm179x-i2c.c b/sound/soc/codecs/pcm179x-i2c.c index 4118106abb8d..03747966c6bc 100644 --- a/sound/soc/codecs/pcm179x-i2c.c +++ b/sound/soc/codecs/pcm179x-i2c.c @@ -39,11 +39,6 @@ static int pcm179x_i2c_probe(struct i2c_client *client, return pcm179x_common_init(&client->dev, regmap); } -static int pcm179x_i2c_remove(struct i2c_client *client) -{ - return pcm179x_common_exit(&client->dev); -} - static const struct of_device_id pcm179x_of_match[] = { { .compatible = "ti,pcm1792a", }, { } @@ -63,7 +58,6 @@ static struct i2c_driver pcm179x_i2c_driver = { }, .id_table = pcm179x_i2c_ids, .probe = pcm179x_i2c_probe, - .remove = pcm179x_i2c_remove, }; module_i2c_driver(pcm179x_i2c_driver); diff --git a/sound/soc/codecs/pcm179x-spi.c b/sound/soc/codecs/pcm179x-spi.c index da924d444083..89ad715676fc 100644 --- a/sound/soc/codecs/pcm179x-spi.c +++ b/sound/soc/codecs/pcm179x-spi.c @@ -38,11 +38,6 @@ static int pcm179x_spi_probe(struct spi_device *spi) return pcm179x_common_init(&spi->dev, regmap); } -static int pcm179x_spi_remove(struct spi_device *spi) -{ - return pcm179x_common_exit(&spi->dev); -} - static const struct of_device_id pcm179x_of_match[] = { { .compatible = "ti,pcm1792a", }, { } @@ -62,7 +57,6 @@ static struct spi_driver pcm179x_spi_driver = { }, .id_table = pcm179x_spi_ids, .probe = pcm179x_spi_probe, - .remove = pcm179x_spi_remove, }; module_spi_driver(pcm179x_spi_driver); diff --git a/sound/soc/codecs/pcm179x.c b/sound/soc/codecs/pcm179x.c index 82a3d9db32cb..4b311c06f97d 100644 --- a/sound/soc/codecs/pcm179x.c +++ b/sound/soc/codecs/pcm179x.c @@ -77,8 +77,8 @@ struct pcm179x_private { static int pcm179x_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int format) { - struct snd_soc_codec *codec = codec_dai->codec; - struct pcm179x_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct pcm179x_private *priv = snd_soc_component_get_drvdata(component); priv->format = format; @@ -87,8 +87,8 @@ static int pcm179x_set_dai_fmt(struct snd_soc_dai *codec_dai, static int pcm179x_digital_mute(struct snd_soc_dai *dai, int mute) { - struct snd_soc_codec *codec = dai->codec; - struct pcm179x_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm179x_private *priv = snd_soc_component_get_drvdata(component); int ret; ret = regmap_update_bits(priv->regmap, PCM179X_SOFT_MUTE, @@ -103,8 +103,8 @@ static int pcm179x_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 pcm179x_private *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm179x_private *priv = snd_soc_component_get_drvdata(component); int val = 0, ret; priv->rate = params_rate(params); @@ -137,7 +137,7 @@ static int pcm179x_hw_params(struct snd_pcm_substream *substream, } break; default: - dev_err(codec->dev, "Invalid DAI format\n"); + dev_err(component->dev, "Invalid DAI format\n"); return -EINVAL; } @@ -205,15 +205,17 @@ const struct regmap_config pcm179x_regmap_config = { }; EXPORT_SYMBOL_GPL(pcm179x_regmap_config); -static const struct snd_soc_codec_driver soc_codec_dev_pcm179x = { - .component_driver = { - .controls = pcm179x_controls, - .num_controls = ARRAY_SIZE(pcm179x_controls), - .dapm_widgets = pcm179x_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(pcm179x_dapm_widgets), - .dapm_routes = pcm179x_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(pcm179x_dapm_routes), - }, +static const struct snd_soc_component_driver soc_component_dev_pcm179x = { + .controls = pcm179x_controls, + .num_controls = ARRAY_SIZE(pcm179x_controls), + .dapm_widgets = pcm179x_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(pcm179x_dapm_widgets), + .dapm_routes = pcm179x_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(pcm179x_dapm_routes), + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; int pcm179x_common_init(struct device *dev, struct regmap *regmap) @@ -228,18 +230,11 @@ int pcm179x_common_init(struct device *dev, struct regmap *regmap) pcm179x->regmap = regmap; dev_set_drvdata(dev, pcm179x); - return snd_soc_register_codec(dev, - &soc_codec_dev_pcm179x, &pcm179x_dai, 1); + return devm_snd_soc_register_component(dev, + &soc_component_dev_pcm179x, &pcm179x_dai, 1); } EXPORT_SYMBOL_GPL(pcm179x_common_init); -int pcm179x_common_exit(struct device *dev) -{ - snd_soc_unregister_codec(dev); - return 0; -} -EXPORT_SYMBOL_GPL(pcm179x_common_exit); - MODULE_DESCRIPTION("ASoC PCM179X driver"); MODULE_AUTHOR("Michael Trimarchi <michael@amarulasolutions.com>"); MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/pcm179x.h b/sound/soc/codecs/pcm179x.h index 11e331268aae..cf8681c9a373 100644 --- a/sound/soc/codecs/pcm179x.h +++ b/sound/soc/codecs/pcm179x.h @@ -23,6 +23,5 @@ extern const struct regmap_config pcm179x_regmap_config; int pcm179x_common_init(struct device *dev, struct regmap *regmap); -int pcm179x_common_exit(struct device *dev); #endif diff --git a/sound/soc/codecs/pcm186x-i2c.c b/sound/soc/codecs/pcm186x-i2c.c index 543621232d60..0214dc6d84d0 100644 --- a/sound/soc/codecs/pcm186x-i2c.c +++ b/sound/soc/codecs/pcm186x-i2c.c @@ -36,13 +36,6 @@ static int pcm186x_i2c_probe(struct i2c_client *i2c, return pcm186x_probe(&i2c->dev, type, irq, regmap); } -static int pcm186x_i2c_remove(struct i2c_client *i2c) -{ - pcm186x_remove(&i2c->dev); - - return 0; -} - static const struct i2c_device_id pcm186x_i2c_id[] = { { "pcm1862", PCM1862 }, { "pcm1863", PCM1863 }, @@ -54,7 +47,6 @@ MODULE_DEVICE_TABLE(i2c, pcm186x_i2c_id); static struct i2c_driver pcm186x_i2c_driver = { .probe = pcm186x_i2c_probe, - .remove = pcm186x_i2c_remove, .id_table = pcm186x_i2c_id, .driver = { .name = "pcm186x", diff --git a/sound/soc/codecs/pcm186x-spi.c b/sound/soc/codecs/pcm186x-spi.c index 2366f8e4d4d4..b56e19827497 100644 --- a/sound/soc/codecs/pcm186x-spi.c +++ b/sound/soc/codecs/pcm186x-spi.c @@ -36,13 +36,6 @@ static int pcm186x_spi_probe(struct spi_device *spi) return pcm186x_probe(&spi->dev, type, irq, regmap); } -static int pcm186x_spi_remove(struct spi_device *spi) -{ - pcm186x_remove(&spi->dev); - - return 0; -} - static const struct spi_device_id pcm186x_spi_id[] = { { "pcm1862", PCM1862 }, { "pcm1863", PCM1863 }, @@ -54,7 +47,6 @@ MODULE_DEVICE_TABLE(spi, pcm186x_spi_id); static struct spi_driver pcm186x_spi_driver = { .probe = pcm186x_spi_probe, - .remove = pcm186x_spi_remove, .id_table = pcm186x_spi_id, .driver = { .name = "pcm186x", diff --git a/sound/soc/codecs/pcm186x.c b/sound/soc/codecs/pcm186x.c index cdb51427facc..88fde70b1e9e 100644 --- a/sound/soc/codecs/pcm186x.c +++ b/sound/soc/codecs/pcm186x.c @@ -262,9 +262,8 @@ static int pcm186x_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 pcm186x_priv *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm186x_priv *priv = snd_soc_component_get_drvdata(component); unsigned int rate = params_rate(params); unsigned int format = params_format(params); unsigned int width = params_width(params); @@ -274,7 +273,7 @@ static int pcm186x_hw_params(struct snd_pcm_substream *substream, u8 tdm_tx_sel = 0; u8 pcm_cfg = 0; - dev_dbg(codec->dev, "%s() rate=%u format=0x%x width=%u channels=%u\n", + dev_dbg(component->dev, "%s() rate=%u format=0x%x width=%u channels=%u\n", __func__, rate, format, width, channels); switch (width) { @@ -306,7 +305,7 @@ static int pcm186x_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - snd_soc_update_bits(codec, PCM186X_PCM_CFG, + snd_soc_component_update_bits(component, PCM186X_PCM_CFG, PCM186X_PCM_CFG_RX_WLEN_MASK | PCM186X_PCM_CFG_TX_WLEN_MASK, pcm_cfg); @@ -329,14 +328,14 @@ static int pcm186x_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - snd_soc_update_bits(codec, PCM186X_TDM_TX_SEL, + snd_soc_component_update_bits(component, PCM186X_TDM_TX_SEL, PCM186X_TDM_TX_SEL_MASK, tdm_tx_sel); /* In DSP/TDM mode, the LRCLK divider must be 256 */ div_lrck = 256; /* Configure 1/256 duty cycle for LRCK */ - snd_soc_update_bits(codec, PCM186X_PCM_CFG, + snd_soc_component_update_bits(component, PCM186X_PCM_CFG, PCM186X_PCM_CFG_TDM_LRCK_MODE, PCM186X_PCM_CFG_TDM_LRCK_MODE); } @@ -345,12 +344,12 @@ static int pcm186x_hw_params(struct snd_pcm_substream *substream, if (priv->is_master_mode) { div_bck = priv->sysclk / (div_lrck * rate); - dev_dbg(codec->dev, + dev_dbg(component->dev, "%s() master_clk=%u div_bck=%u div_lrck=%u\n", __func__, priv->sysclk, div_bck, div_lrck); - snd_soc_write(codec, PCM186X_BCK_DIV, div_bck - 1); - snd_soc_write(codec, PCM186X_LRK_DIV, div_lrck - 1); + snd_soc_component_write(component, PCM186X_BCK_DIV, div_bck - 1); + snd_soc_component_write(component, PCM186X_LRK_DIV, div_lrck - 1); } return 0; @@ -358,18 +357,18 @@ static int pcm186x_hw_params(struct snd_pcm_substream *substream, static int pcm186x_set_fmt(struct snd_soc_dai *dai, unsigned int format) { - struct snd_soc_codec *codec = dai->codec; - struct pcm186x_priv *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm186x_priv *priv = snd_soc_component_get_drvdata(component); u8 clk_ctrl = 0; u8 pcm_cfg = 0; - dev_dbg(codec->dev, "%s() format=0x%x\n", __func__, format); + dev_dbg(component->dev, "%s() format=0x%x\n", __func__, format); /* set master/slave audio interface */ switch (format & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBM_CFM: if (!priv->sysclk) { - dev_err(codec->dev, "operating in master mode requires sysclock to be configured\n"); + dev_err(component->dev, "operating in master mode requires sysclock to be configured\n"); return -EINVAL; } clk_ctrl |= PCM186X_CLK_CTRL_MST_MODE; @@ -379,7 +378,7 @@ static int pcm186x_set_fmt(struct snd_soc_dai *dai, unsigned int format) priv->is_master_mode = false; break; default: - dev_err(codec->dev, "Invalid DAI master/slave interface\n"); + dev_err(component->dev, "Invalid DAI master/slave interface\n"); return -EINVAL; } @@ -388,7 +387,7 @@ static int pcm186x_set_fmt(struct snd_soc_dai *dai, unsigned int format) case SND_SOC_DAIFMT_NB_NF: break; default: - dev_err(codec->dev, "Inverted DAI clocks not supported\n"); + dev_err(component->dev, "Inverted DAI clocks not supported\n"); return -EINVAL; } @@ -410,16 +409,16 @@ static int pcm186x_set_fmt(struct snd_soc_dai *dai, unsigned int format) pcm_cfg = PCM186X_PCM_CFG_FMT_TDM; break; default: - dev_err(codec->dev, "Invalid DAI format\n"); + dev_err(component->dev, "Invalid DAI format\n"); return -EINVAL; } - snd_soc_update_bits(codec, PCM186X_CLK_CTRL, + snd_soc_component_update_bits(component, PCM186X_CLK_CTRL, PCM186X_CLK_CTRL_MST_MODE, clk_ctrl); - snd_soc_write(codec, PCM186X_TDM_TX_OFFSET, priv->tdm_offset); + snd_soc_component_write(component, PCM186X_TDM_TX_OFFSET, priv->tdm_offset); - snd_soc_update_bits(codec, PCM186X_PCM_CFG, + snd_soc_component_update_bits(component, PCM186X_PCM_CFG, PCM186X_PCM_CFG_FMT_MASK, pcm_cfg); return 0; @@ -428,16 +427,16 @@ static int pcm186x_set_fmt(struct snd_soc_dai *dai, unsigned int format) static int pcm186x_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) { - struct snd_soc_codec *codec = dai->codec; - struct pcm186x_priv *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm186x_priv *priv = snd_soc_component_get_drvdata(component); unsigned int first_slot, last_slot, tdm_offset; - dev_dbg(codec->dev, + dev_dbg(component->dev, "%s() tx_mask=0x%x rx_mask=0x%x slots=%d slot_width=%d\n", __func__, tx_mask, rx_mask, slots, slot_width); if (!tx_mask) { - dev_err(codec->dev, "tdm tx mask must not be 0\n"); + dev_err(component->dev, "tdm tx mask must not be 0\n"); return -EINVAL; } @@ -445,14 +444,14 @@ static int pcm186x_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, last_slot = __fls(tx_mask); if (last_slot - first_slot != hweight32(tx_mask) - 1) { - dev_err(codec->dev, "tdm tx mask must be contiguous\n"); + dev_err(component->dev, "tdm tx mask must be contiguous\n"); return -EINVAL; } tdm_offset = first_slot * slot_width; if (tdm_offset > 255) { - dev_err(codec->dev, "tdm tx slot selection out of bounds\n"); + dev_err(component->dev, "tdm tx slot selection out of bounds\n"); return -EINVAL; } @@ -464,10 +463,10 @@ static int pcm186x_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, static int pcm186x_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { - struct snd_soc_codec *codec = dai->codec; - struct pcm186x_priv *priv = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm186x_priv *priv = snd_soc_component_get_drvdata(component); - dev_dbg(codec->dev, "%s() clk_id=%d freq=%u dir=%d\n", + dev_dbg(component->dev, "%s() clk_id=%d freq=%u dir=%d\n", __func__, clk_id, freq, dir); priv->sysclk = freq; @@ -506,9 +505,9 @@ static struct snd_soc_dai_driver pcm1865_dai = { .ops = &pcm186x_dai_ops, }; -static int pcm186x_power_on(struct snd_soc_codec *codec) +static int pcm186x_power_on(struct snd_soc_component *component) { - struct pcm186x_priv *priv = snd_soc_codec_get_drvdata(codec); + struct pcm186x_priv *priv = snd_soc_component_get_drvdata(component); int ret = 0; ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), @@ -519,25 +518,25 @@ static int pcm186x_power_on(struct snd_soc_codec *codec) regcache_cache_only(priv->regmap, false); ret = regcache_sync(priv->regmap); if (ret) { - dev_err(codec->dev, "Failed to restore cache\n"); + dev_err(component->dev, "Failed to restore cache\n"); regcache_cache_only(priv->regmap, true); regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); return ret; } - snd_soc_update_bits(codec, PCM186X_POWER_CTRL, + snd_soc_component_update_bits(component, PCM186X_POWER_CTRL, PCM186X_PWR_CTRL_PWRDN, 0); return 0; } -static int pcm186x_power_off(struct snd_soc_codec *codec) +static int pcm186x_power_off(struct snd_soc_component *component) { - struct pcm186x_priv *priv = snd_soc_codec_get_drvdata(codec); + struct pcm186x_priv *priv = snd_soc_component_get_drvdata(component); int ret; - snd_soc_update_bits(codec, PCM186X_POWER_CTRL, + snd_soc_component_update_bits(component, PCM186X_POWER_CTRL, PCM186X_PWR_CTRL_PWRDN, PCM186X_PWR_CTRL_PWRDN); regcache_cache_only(priv->regmap, true); @@ -550,11 +549,11 @@ static int pcm186x_power_off(struct snd_soc_codec *codec) return 0; } -static int pcm186x_set_bias_level(struct snd_soc_codec *codec, +static int pcm186x_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: @@ -562,42 +561,44 @@ static int pcm186x_set_bias_level(struct snd_soc_codec *codec, case SND_SOC_BIAS_PREPARE: break; case SND_SOC_BIAS_STANDBY: - if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) - pcm186x_power_on(codec); + if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) + pcm186x_power_on(component); break; case SND_SOC_BIAS_OFF: - pcm186x_power_off(codec); + pcm186x_power_off(component); break; } return 0; } -static struct snd_soc_codec_driver soc_codec_dev_pcm1863 = { - .set_bias_level = pcm186x_set_bias_level, - - .component_driver = { - .controls = pcm1863_snd_controls, - .num_controls = ARRAY_SIZE(pcm1863_snd_controls), - .dapm_widgets = pcm1863_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(pcm1863_dapm_widgets), - .dapm_routes = pcm1863_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(pcm1863_dapm_routes), - }, +static struct snd_soc_component_driver soc_codec_dev_pcm1863 = { + .set_bias_level = pcm186x_set_bias_level, + .controls = pcm1863_snd_controls, + .num_controls = ARRAY_SIZE(pcm1863_snd_controls), + .dapm_widgets = pcm1863_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(pcm1863_dapm_widgets), + .dapm_routes = pcm1863_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(pcm1863_dapm_routes), + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; -static struct snd_soc_codec_driver soc_codec_dev_pcm1865 = { - .set_bias_level = pcm186x_set_bias_level, - .suspend_bias_off = true, - - .component_driver = { - .controls = pcm1865_snd_controls, - .num_controls = ARRAY_SIZE(pcm1865_snd_controls), - .dapm_widgets = pcm1865_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(pcm1865_dapm_widgets), - .dapm_routes = pcm1865_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(pcm1865_dapm_routes), - }, +static struct snd_soc_component_driver soc_codec_dev_pcm1865 = { + .set_bias_level = pcm186x_set_bias_level, + .controls = pcm1865_snd_controls, + .num_controls = ARRAY_SIZE(pcm1865_snd_controls), + .dapm_widgets = pcm1865_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(pcm1865_dapm_widgets), + .dapm_routes = pcm1865_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(pcm1865_dapm_routes), + .suspend_bias_off = 1, + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static bool pcm186x_volatile(struct device *dev, unsigned int reg) @@ -687,13 +688,13 @@ int pcm186x_probe(struct device *dev, enum pcm186x_type type, int irq, switch (type) { case PCM1865: case PCM1864: - ret = snd_soc_register_codec(dev, &soc_codec_dev_pcm1865, + ret = devm_snd_soc_register_component(dev, &soc_codec_dev_pcm1865, &pcm1865_dai, 1); break; case PCM1863: case PCM1862: default: - ret = snd_soc_register_codec(dev, &soc_codec_dev_pcm1863, + ret = devm_snd_soc_register_component(dev, &soc_codec_dev_pcm1863, &pcm1863_dai, 1); } if (ret) { @@ -705,14 +706,6 @@ int pcm186x_probe(struct device *dev, enum pcm186x_type type, int irq, } EXPORT_SYMBOL_GPL(pcm186x_probe); -int pcm186x_remove(struct device *dev) -{ - snd_soc_unregister_codec(dev); - - return 0; -} -EXPORT_SYMBOL_GPL(pcm186x_remove); - MODULE_AUTHOR("Andreas Dannenberg <dannenberg@ti.com>"); MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>"); MODULE_DESCRIPTION("PCM186x Universal Audio ADC driver"); diff --git a/sound/soc/codecs/pcm186x.h b/sound/soc/codecs/pcm186x.h index b630111bb3c4..2c6ba55bf394 100644 --- a/sound/soc/codecs/pcm186x.h +++ b/sound/soc/codecs/pcm186x.h @@ -215,6 +215,5 @@ extern const struct regmap_config pcm186x_regmap; int pcm186x_probe(struct device *dev, enum pcm186x_type type, int irq, struct regmap *regmap); -int pcm186x_remove(struct device *dev); #endif /* _PCM186X_H_ */ diff --git a/sound/soc/codecs/pcm3008.c b/sound/soc/codecs/pcm3008.c index e59d8ffb93bd..c6ce9bd77c5e 100644 --- a/sound/soc/codecs/pcm3008.c +++ b/sound/soc/codecs/pcm3008.c @@ -32,8 +32,8 @@ static int pcm3008_dac_ev(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 pcm3008_setup_data *setup = codec->dev->platform_data; + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct pcm3008_setup_data *setup = component->dev->platform_data; gpio_set_value_cansleep(setup->pdda_pin, SND_SOC_DAPM_EVENT_ON(event)); @@ -45,8 +45,8 @@ static int pcm3008_adc_ev(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 pcm3008_setup_data *setup = codec->dev->platform_data; + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct pcm3008_setup_data *setup = component->dev->platform_data; gpio_set_value_cansleep(setup->pdad_pin, SND_SOC_DAPM_EVENT_ON(event)); @@ -98,13 +98,15 @@ static struct snd_soc_dai_driver pcm3008_dai = { }, }; -static const struct snd_soc_codec_driver soc_codec_dev_pcm3008 = { - .component_driver = { - .dapm_widgets = pcm3008_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(pcm3008_dapm_widgets), - .dapm_routes = pcm3008_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(pcm3008_dapm_routes), - }, +static const struct snd_soc_component_driver soc_component_dev_pcm3008 = { + .dapm_widgets = pcm3008_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(pcm3008_dapm_widgets), + .dapm_routes = pcm3008_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(pcm3008_dapm_routes), + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static int pcm3008_codec_probe(struct platform_device *pdev) @@ -146,22 +148,14 @@ static int pcm3008_codec_probe(struct platform_device *pdev) if (ret != 0) return ret; - return snd_soc_register_codec(&pdev->dev, - &soc_codec_dev_pcm3008, &pcm3008_dai, 1); -} - -static int pcm3008_codec_remove(struct platform_device *pdev) -{ - snd_soc_unregister_codec(&pdev->dev); - - return 0; + return devm_snd_soc_register_component(&pdev->dev, + &soc_component_dev_pcm3008, &pcm3008_dai, 1); } MODULE_ALIAS("platform:pcm3008-codec"); static struct platform_driver pcm3008_codec_driver = { .probe = pcm3008_codec_probe, - .remove = pcm3008_codec_remove, .driver = { .name = "pcm3008-codec", }, diff --git a/sound/soc/codecs/pcm3168a.c b/sound/soc/codecs/pcm3168a.c index b9d1207ccef2..3356c91f55b0 100644 --- a/sound/soc/codecs/pcm3168a.c +++ b/sound/soc/codecs/pcm3168a.c @@ -287,8 +287,8 @@ static int pcm3168a_reset(struct pcm3168a_priv *pcm3168a) static int pcm3168a_digital_mute(struct snd_soc_dai *dai, int mute) { - struct snd_soc_codec *codec = dai->codec; - struct pcm3168a_priv *pcm3168a = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm3168a_priv *pcm3168a = snd_soc_component_get_drvdata(component); regmap_write(pcm3168a->regmap, PCM3168A_DAC_MUTE, mute ? 0xff : 0); @@ -298,7 +298,7 @@ static int pcm3168a_digital_mute(struct snd_soc_dai *dai, int mute) static int pcm3168a_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { - struct pcm3168a_priv *pcm3168a = snd_soc_codec_get_drvdata(dai->codec); + struct pcm3168a_priv *pcm3168a = snd_soc_component_get_drvdata(dai->component); int ret; if (freq > PCM1368A_MAX_SYSCLK) @@ -316,8 +316,8 @@ static int pcm3168a_set_dai_sysclk(struct snd_soc_dai *dai, static int pcm3168a_set_dai_fmt(struct snd_soc_dai *dai, unsigned int format, bool dac) { - struct snd_soc_codec *codec = dai->codec; - struct pcm3168a_priv *pcm3168a = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm3168a_priv *pcm3168a = snd_soc_component_get_drvdata(component); u32 fmt, reg, mask, shift; bool master_mode; @@ -338,7 +338,7 @@ static int pcm3168a_set_dai_fmt(struct snd_soc_dai *dai, fmt = PCM3168A_FMT_DSP_B; break; default: - dev_err(codec->dev, "unsupported dai format\n"); + dev_err(component->dev, "unsupported dai format\n"); return -EINVAL; } @@ -350,7 +350,7 @@ static int pcm3168a_set_dai_fmt(struct snd_soc_dai *dai, master_mode = true; break; default: - dev_err(codec->dev, "unsupported master/slave mode\n"); + dev_err(component->dev, "unsupported master/slave mode\n"); return -EINVAL; } @@ -396,8 +396,8 @@ static int pcm3168a_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 pcm3168a_priv *pcm3168a = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm3168a_priv *pcm3168a = snd_soc_component_get_drvdata(component); bool tx, master_mode; u32 val, mask, shift, reg; unsigned int rate, fmt, ratio, max_ratio; @@ -430,7 +430,7 @@ static int pcm3168a_hw_params(struct snd_pcm_substream *substream, } if (i == max_ratio) { - dev_err(codec->dev, "unsupported sysclk ratio\n"); + dev_err(component->dev, "unsupported sysclk ratio\n"); return -EINVAL; } @@ -438,21 +438,21 @@ static int pcm3168a_hw_params(struct snd_pcm_substream *substream, switch (min_frame_size) { case 32: if (master_mode || (fmt != PCM3168A_FMT_RIGHT_J)) { - dev_err(codec->dev, "32-bit frames are supported only for slave mode using right justified\n"); + dev_err(component->dev, "32-bit frames are supported only for slave mode using right justified\n"); return -EINVAL; } fmt = PCM3168A_FMT_RIGHT_J_16; break; case 48: if (master_mode || (fmt & PCM3168A_FMT_DSP_MASK)) { - dev_err(codec->dev, "48-bit frames not supported in master mode, or slave mode using DSP\n"); + dev_err(component->dev, "48-bit frames not supported in master mode, or slave mode using DSP\n"); return -EINVAL; } break; case 64: break; default: - dev_err(codec->dev, "unsupported frame size: %d\n", min_frame_size); + dev_err(component->dev, "unsupported frame size: %d\n", min_frame_size); return -EINVAL; } @@ -595,16 +595,16 @@ const struct regmap_config pcm3168a_regmap = { }; EXPORT_SYMBOL_GPL(pcm3168a_regmap); -static const struct snd_soc_codec_driver pcm3168a_driver = { - .idle_bias_off = true, - .component_driver = { - .controls = pcm3168a_snd_controls, - .num_controls = ARRAY_SIZE(pcm3168a_snd_controls), - .dapm_widgets = pcm3168a_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(pcm3168a_dapm_widgets), - .dapm_routes = pcm3168a_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(pcm3168a_dapm_routes) - }, +static const struct snd_soc_component_driver pcm3168a_driver = { + .controls = pcm3168a_snd_controls, + .num_controls = ARRAY_SIZE(pcm3168a_snd_controls), + .dapm_widgets = pcm3168a_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(pcm3168a_dapm_widgets), + .dapm_routes = pcm3168a_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(pcm3168a_dapm_routes), + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; int pcm3168a_probe(struct device *dev, struct regmap *regmap) @@ -669,10 +669,10 @@ int pcm3168a_probe(struct device *dev, struct regmap *regmap) pm_runtime_enable(dev); pm_runtime_idle(dev); - ret = snd_soc_register_codec(dev, &pcm3168a_driver, pcm3168a_dais, + ret = devm_snd_soc_register_component(dev, &pcm3168a_driver, pcm3168a_dais, ARRAY_SIZE(pcm3168a_dais)); if (ret) { - dev_err(dev, "failed to register codec: %d\n", ret); + dev_err(dev, "failed to register component: %d\n", ret); goto err_regulator; } @@ -692,7 +692,6 @@ void pcm3168a_remove(struct device *dev) { struct pcm3168a_priv *pcm3168a = dev_get_drvdata(dev); - snd_soc_unregister_codec(dev); pm_runtime_disable(dev); regulator_bulk_disable(ARRAY_SIZE(pcm3168a->supplies), pcm3168a->supplies); diff --git a/sound/soc/codecs/pcm5102a.c b/sound/soc/codecs/pcm5102a.c index 8ba322a00363..39ac2857a554 100644 --- a/sound/soc/codecs/pcm5102a.c +++ b/sound/soc/codecs/pcm5102a.c @@ -32,20 +32,19 @@ static struct snd_soc_dai_driver pcm5102a_dai = { }, }; -static struct snd_soc_codec_driver soc_codec_dev_pcm5102a; +static struct snd_soc_component_driver soc_component_dev_pcm5102a = { + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, +}; static int pcm5102a_probe(struct platform_device *pdev) { - return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a, + return devm_snd_soc_register_component(&pdev->dev, &soc_component_dev_pcm5102a, &pcm5102a_dai, 1); } -static int pcm5102a_remove(struct platform_device *pdev) -{ - snd_soc_unregister_codec(&pdev->dev); - return 0; -} - static const struct of_device_id pcm5102a_of_match[] = { { .compatible = "ti,pcm5102a", }, { } @@ -54,7 +53,6 @@ MODULE_DEVICE_TABLE(of, pcm5102a_of_match); static struct platform_driver pcm5102a_codec_driver = { .probe = pcm5102a_probe, - .remove = pcm5102a_remove, .driver = { .name = "pcm5102a-codec", .of_match_table = pcm5102a_of_match, diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index e0f3556d3872..f0f2d4fd3769 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -226,8 +226,8 @@ static bool pcm512x_volatile(struct device *dev, unsigned int reg) static int pcm512x_overclock_pll_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); ucontrol->value.integer.value[0] = pcm512x->overclock_pll; return 0; @@ -236,10 +236,10 @@ static int pcm512x_overclock_pll_get(struct snd_kcontrol *kcontrol, static int pcm512x_overclock_pll_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); - switch (snd_soc_codec_get_bias_level(codec)) { + switch (snd_soc_component_get_bias_level(component)) { case SND_SOC_BIAS_OFF: case SND_SOC_BIAS_STANDBY: break; @@ -254,8 +254,8 @@ static int pcm512x_overclock_pll_put(struct snd_kcontrol *kcontrol, static int pcm512x_overclock_dsp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); ucontrol->value.integer.value[0] = pcm512x->overclock_dsp; return 0; @@ -264,10 +264,10 @@ static int pcm512x_overclock_dsp_get(struct snd_kcontrol *kcontrol, static int pcm512x_overclock_dsp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); - switch (snd_soc_codec_get_bias_level(codec)) { + switch (snd_soc_component_get_bias_level(component)) { case SND_SOC_BIAS_OFF: case SND_SOC_BIAS_STANDBY: break; @@ -282,8 +282,8 @@ static int pcm512x_overclock_dsp_put(struct snd_kcontrol *kcontrol, static int pcm512x_overclock_dac_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); ucontrol->value.integer.value[0] = pcm512x->overclock_dac; return 0; @@ -292,10 +292,10 @@ static int pcm512x_overclock_dac_get(struct snd_kcontrol *kcontrol, static int pcm512x_overclock_dac_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); - switch (snd_soc_codec_get_bias_level(codec)) { + switch (snd_soc_component_get_bias_level(component)) { case SND_SOC_BIAS_OFF: case SND_SOC_BIAS_STANDBY: break; @@ -522,8 +522,8 @@ static int pcm512x_hw_rule_rate(struct snd_pcm_hw_params *params, static int pcm512x_dai_startup_master(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); struct device *dev = dai->dev; struct snd_pcm_hw_constraint_ratnums *constraints_no_pll; struct snd_ratnum *rats_no_pll; @@ -564,8 +564,8 @@ static int pcm512x_dai_startup_master(struct snd_pcm_substream *substream, static int pcm512x_dai_startup_slave(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); struct device *dev = dai->dev; struct regmap *regmap = pcm512x->regmap; @@ -590,8 +590,8 @@ static int pcm512x_dai_startup_slave(struct snd_pcm_substream *substream, static int pcm512x_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBM_CFM: @@ -606,10 +606,10 @@ static int pcm512x_dai_startup(struct snd_pcm_substream *substream, } } -static int pcm512x_set_bias_level(struct snd_soc_codec *codec, +static int pcm512x_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - struct pcm512x_priv *pcm512x = dev_get_drvdata(codec->dev); + struct pcm512x_priv *pcm512x = dev_get_drvdata(component->dev); int ret; switch (level) { @@ -621,7 +621,7 @@ static int pcm512x_set_bias_level(struct snd_soc_codec *codec, ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER, PCM512x_RQST, 0); if (ret != 0) { - dev_err(codec->dev, "Failed to remove standby: %d\n", + dev_err(component->dev, "Failed to remove standby: %d\n", ret); return ret; } @@ -631,7 +631,7 @@ static int pcm512x_set_bias_level(struct snd_soc_codec *codec, ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER, PCM512x_RQST, PCM512x_RQST); if (ret != 0) { - dev_err(codec->dev, "Failed to request standby: %d\n", + dev_err(component->dev, "Failed to request standby: %d\n", ret); return ret; } @@ -645,8 +645,8 @@ static unsigned long pcm512x_find_sck(struct snd_soc_dai *dai, unsigned long bclk_rate) { struct device *dev = dai->dev; - struct snd_soc_codec *codec = dai->codec; - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); unsigned long sck_rate; int pow2; @@ -691,8 +691,8 @@ static int pcm512x_find_pll_coeff(struct snd_soc_dai *dai, unsigned long pll_rate) { struct device *dev = dai->dev; - struct snd_soc_codec *codec = dai->codec; - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); unsigned long common; int R, J, D, P; unsigned long K; /* 10000 * J.D */ @@ -798,8 +798,8 @@ static unsigned long pcm512x_pllin_dac_rate(struct snd_soc_dai *dai, unsigned long osr_rate, unsigned long pllin_rate) { - struct snd_soc_codec *codec = dai->codec; - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); unsigned long dac_rate; if (!pcm512x->pll_out) @@ -829,8 +829,8 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai, struct snd_pcm_hw_params *params) { struct device *dev = dai->dev; - struct snd_soc_codec *codec = dai->codec; - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); unsigned long pllin_rate = 0; unsigned long pll_rate; unsigned long sck_rate; @@ -949,7 +949,7 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai, ret = regmap_update_bits(pcm512x->regmap, PCM512x_DAC_REF, PCM512x_SDAC, PCM512x_SDAC_GPIO); if (ret != 0) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to set gpio as dacref: %d\n", ret); return ret; } @@ -958,7 +958,7 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai, ret = regmap_update_bits(pcm512x->regmap, PCM512x_GPIO_DACIN, PCM512x_GREF, gpio); if (ret != 0) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to set gpio %d as dacin: %d\n", pcm512x->pll_in, ret); return ret; @@ -987,7 +987,7 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai, ret = regmap_update_bits(pcm512x->regmap, PCM512x_DAC_REF, PCM512x_SDAC, PCM512x_SDAC_SCK); if (ret != 0) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to set sck as dacref: %d\n", ret); return ret; } @@ -1082,18 +1082,18 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai, ret = regmap_update_bits(pcm512x->regmap, PCM512x_FS_SPEED_MODE, PCM512x_FSSP, fssp); if (ret != 0) { - dev_err(codec->dev, "Failed to set fs speed: %d\n", ret); + dev_err(component->dev, "Failed to set fs speed: %d\n", ret); return ret; } - dev_dbg(codec->dev, "DSP divider %d\n", dsp_div); - dev_dbg(codec->dev, "DAC divider %d\n", dac_div); - dev_dbg(codec->dev, "NCP divider %d\n", ncp_div); - dev_dbg(codec->dev, "OSR divider %d\n", osr_div); - dev_dbg(codec->dev, "BCK divider %d\n", bclk_div); - dev_dbg(codec->dev, "LRCK divider %d\n", lrclk_div); - dev_dbg(codec->dev, "IDAC %d\n", idac); - dev_dbg(codec->dev, "1<<FSSP %d\n", 1 << fssp); + dev_dbg(component->dev, "DSP divider %d\n", dsp_div); + dev_dbg(component->dev, "DAC divider %d\n", dac_div); + dev_dbg(component->dev, "NCP divider %d\n", ncp_div); + dev_dbg(component->dev, "OSR divider %d\n", osr_div); + dev_dbg(component->dev, "BCK divider %d\n", bclk_div); + dev_dbg(component->dev, "LRCK divider %d\n", lrclk_div); + dev_dbg(component->dev, "IDAC %d\n", idac); + dev_dbg(component->dev, "1<<FSSP %d\n", 1 << fssp); return 0; } @@ -1102,15 +1102,15 @@ static int pcm512x_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 pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); int alen; int gpio; int clock_output; int master_mode; int ret; - dev_dbg(codec->dev, "hw_params %u Hz, %u channels\n", + dev_dbg(component->dev, "hw_params %u Hz, %u channels\n", params_rate(params), params_channels(params)); @@ -1128,7 +1128,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, alen = PCM512x_ALEN_32; break; default: - dev_err(codec->dev, "Bad frame size: %d\n", + dev_err(component->dev, "Bad frame size: %d\n", params_width(params)); return -EINVAL; } @@ -1141,7 +1141,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, | PCM512x_BCKO | PCM512x_LRKO, 0); if (ret != 0) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to enable slave mode: %d\n", ret); return ret; } @@ -1149,7 +1149,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret = regmap_update_bits(pcm512x->regmap, PCM512x_ERROR_DETECT, PCM512x_DCAS, 0); if (ret != 0) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to enable clock divider autoset: %d\n", ret); return ret; @@ -1170,20 +1170,20 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1, PCM512x_ALEN, alen); if (ret != 0) { - dev_err(codec->dev, "Failed to set frame size: %d\n", ret); + dev_err(component->dev, "Failed to set frame size: %d\n", ret); return ret; } if (pcm512x->pll_out) { ret = regmap_write(pcm512x->regmap, PCM512x_FLEX_A, 0x11); if (ret != 0) { - dev_err(codec->dev, "Failed to set FLEX_A: %d\n", ret); + dev_err(component->dev, "Failed to set FLEX_A: %d\n", ret); return ret; } ret = regmap_write(pcm512x->regmap, PCM512x_FLEX_B, 0xff); if (ret != 0) { - dev_err(codec->dev, "Failed to set FLEX_B: %d\n", ret); + dev_err(component->dev, "Failed to set FLEX_B: %d\n", ret); return ret; } @@ -1196,7 +1196,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, | PCM512x_IDSK | PCM512x_IDCH | PCM512x_DCAS); if (ret != 0) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to ignore auto-clock failures: %d\n", ret); return ret; @@ -1211,7 +1211,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, | PCM512x_IDSK | PCM512x_IDCH | PCM512x_DCAS | PCM512x_IPLK); if (ret != 0) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to ignore auto-clock failures: %d\n", ret); return ret; @@ -1220,7 +1220,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret = regmap_update_bits(pcm512x->regmap, PCM512x_PLL_EN, PCM512x_PLLE, 0); if (ret != 0) { - dev_err(codec->dev, "Failed to disable pll: %d\n", ret); + dev_err(component->dev, "Failed to disable pll: %d\n", ret); return ret; } } @@ -1233,7 +1233,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret = regmap_update_bits(pcm512x->regmap, PCM512x_PLL_REF, PCM512x_SREF, PCM512x_SREF_GPIO); if (ret != 0) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to set gpio as pllref: %d\n", ret); return ret; } @@ -1242,7 +1242,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret = regmap_update_bits(pcm512x->regmap, PCM512x_GPIO_PLLIN, PCM512x_GREF, gpio); if (ret != 0) { - dev_err(codec->dev, + dev_err(component->dev, "Failed to set gpio %d as pllin: %d\n", pcm512x->pll_in, ret); return ret; @@ -1251,7 +1251,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret = regmap_update_bits(pcm512x->regmap, PCM512x_PLL_EN, PCM512x_PLLE, PCM512x_PLLE); if (ret != 0) { - dev_err(codec->dev, "Failed to enable pll: %d\n", ret); + dev_err(component->dev, "Failed to enable pll: %d\n", ret); return ret; } } @@ -1260,7 +1260,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, PCM512x_BCKP | PCM512x_BCKO | PCM512x_LRKO, clock_output); if (ret != 0) { - dev_err(codec->dev, "Failed to enable clock output: %d\n", ret); + dev_err(component->dev, "Failed to enable clock output: %d\n", ret); return ret; } @@ -1268,7 +1268,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, PCM512x_RLRK | PCM512x_RBCK, master_mode); if (ret != 0) { - dev_err(codec->dev, "Failed to enable master mode: %d\n", ret); + dev_err(component->dev, "Failed to enable master mode: %d\n", ret); return ret; } @@ -1277,7 +1277,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret = regmap_update_bits(pcm512x->regmap, PCM512x_GPIO_EN, gpio, gpio); if (ret != 0) { - dev_err(codec->dev, "Failed to enable gpio %d: %d\n", + dev_err(component->dev, "Failed to enable gpio %d: %d\n", pcm512x->pll_out, ret); return ret; } @@ -1286,7 +1286,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret = regmap_update_bits(pcm512x->regmap, gpio, PCM512x_GxSL, PCM512x_GxSL_PLLCK); if (ret != 0) { - dev_err(codec->dev, "Failed to output pll on %d: %d\n", + dev_err(component->dev, "Failed to output pll on %d: %d\n", ret, pcm512x->pll_out); return ret; } @@ -1295,14 +1295,14 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret = regmap_update_bits(pcm512x->regmap, PCM512x_SYNCHRONIZE, PCM512x_RQSY, PCM512x_RQSY_HALT); if (ret != 0) { - dev_err(codec->dev, "Failed to halt clocks: %d\n", ret); + dev_err(component->dev, "Failed to halt clocks: %d\n", ret); return ret; } ret = regmap_update_bits(pcm512x->regmap, PCM512x_SYNCHRONIZE, PCM512x_RQSY, PCM512x_RQSY_RESUME); if (ret != 0) { - dev_err(codec->dev, "Failed to resume clocks: %d\n", ret); + dev_err(component->dev, "Failed to resume clocks: %d\n", ret); return ret; } @@ -1311,8 +1311,8 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) { - struct snd_soc_codec *codec = dai->codec; - struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); pcm512x->fmt = fmt; @@ -1341,18 +1341,17 @@ static struct snd_soc_dai_driver pcm512x_dai = { .ops = &pcm512x_dai_ops, }; -static const struct snd_soc_codec_driver pcm512x_codec_driver = { - .set_bias_level = pcm512x_set_bias_level, - .idle_bias_off = true, - - .component_driver = { - .controls = pcm512x_controls, - .num_controls = ARRAY_SIZE(pcm512x_controls), - .dapm_widgets = pcm512x_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(pcm512x_dapm_widgets), - .dapm_routes = pcm512x_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes), - }, +static const struct snd_soc_component_driver pcm512x_component_driver = { + .set_bias_level = pcm512x_set_bias_level, + .controls = pcm512x_controls, + .num_controls = ARRAY_SIZE(pcm512x_controls), + .dapm_widgets = pcm512x_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(pcm512x_dapm_widgets), + .dapm_routes = pcm512x_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes), + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static const struct regmap_range_cfg pcm512x_range = { @@ -1498,7 +1497,7 @@ int pcm512x_probe(struct device *dev, struct regmap *regmap) } #endif - ret = snd_soc_register_codec(dev, &pcm512x_codec_driver, + ret = devm_snd_soc_register_component(dev, &pcm512x_component_driver, &pcm512x_dai, 1); if (ret != 0) { dev_err(dev, "Failed to register CODEC: %d\n", ret); @@ -1523,7 +1522,6 @@ void pcm512x_remove(struct device *dev) { struct pcm512x_priv *pcm512x = dev_get_drvdata(dev); - snd_soc_unregister_codec(dev); pm_runtime_disable(dev); if (!IS_ERR(pcm512x->sclk)) clk_disable_unprepare(pcm512x->sclk); diff --git a/sound/soc/codecs/rt286.c b/sound/soc/codecs/rt286.c index af6325c78292..e1643571d643 100644 --- a/sound/soc/codecs/rt286.c +++ b/sound/soc/codecs/rt286.c @@ -40,7 +40,7 @@ struct rt286_priv { struct reg_default *index_cache; int index_cache_size; struct regmap *regmap; - struct snd_soc_codec *codec; + struct snd_soc_component *component; struct rt286_platform_data pdata; struct i2c_client *i2c; struct snd_soc_jack *jack; @@ -187,13 +187,13 @@ static bool rt286_readable_register(struct device *dev, unsigned int reg) } #ifdef CONFIG_PM -static void rt286_index_sync(struct snd_soc_codec *codec) +static void rt286_index_sync(struct snd_soc_component *component) { - struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + struct rt286_priv *rt286 = snd_soc_component_get_drvdata(component); int i; for (i = 0; i < INDEX_CACHE_SIZE; i++) { - snd_soc_write(codec, rt286->index_cache[i].reg, + snd_soc_component_write(component, rt286->index_cache[i].reg, rt286->index_cache[i].def); } } @@ -220,10 +220,10 @@ static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic) *hp = false; *mic = false; - if (!rt286->codec) + if (!rt286->component) return -EINVAL; - dapm = snd_soc_codec_get_dapm(rt286->codec); + dapm = snd_soc_component_get_dapm(rt286->component); if (rt286->pdata.cbj_en) { regmap_read(rt286->regmap, RT286_GET_HP_SENSE, &buf); @@ -305,10 +305,10 @@ static void rt286_jack_detect_work(struct work_struct *work) SND_JACK_MICROPHONE | SND_JACK_HEADPHONE); } -int rt286_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack) +int rt286_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack) { - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + struct rt286_priv *rt286 = snd_soc_component_get_drvdata(component); rt286->jack = jack; @@ -334,8 +334,8 @@ EXPORT_SYMBOL_GPL(rt286_mic_detect); static int is_mclk_mode(struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm); - struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); + struct rt286_priv *rt286 = snd_soc_component_get_drvdata(component); if (rt286->clk_id == RT286_SCLK_S_MCLK) return 1; @@ -434,15 +434,15 @@ SOC_DAPM_ENUM("SPO source", rt286_spo_enum); static int rt286_spk_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_write(codec, + snd_soc_component_write(component, RT286_SPK_EAPD, RT286_SET_EAPD_HIGH); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_write(codec, + snd_soc_component_write(component, RT286_SPK_EAPD, RT286_SET_EAPD_LOW); break; @@ -456,14 +456,14 @@ static int rt286_spk_event(struct snd_soc_dapm_widget *w, static int rt286_set_dmic1_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_write(codec, RT286_SET_PIN_DMIC1, 0x20); + snd_soc_component_write(component, RT286_SET_PIN_DMIC1, 0x20); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_write(codec, RT286_SET_PIN_DMIC1, 0); + snd_soc_component_write(component, RT286_SET_PIN_DMIC1, 0); break; default: return 0; @@ -475,14 +475,14 @@ static int rt286_set_dmic1_event(struct snd_soc_dapm_widget *w, static int rt286_ldo2_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_update_bits(codec, RT286_POWER_CTRL2, 0x38, 0x08); + snd_soc_component_update_bits(component, RT286_POWER_CTRL2, 0x38, 0x08); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_update_bits(codec, RT286_POWER_CTRL2, 0x38, 0x30); + snd_soc_component_update_bits(component, RT286_POWER_CTRL2, 0x38, 0x30); break; default: return 0; @@ -494,19 +494,19 @@ static int rt286_ldo2_event(struct snd_soc_dapm_widget *w, static int rt286_mic1_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_PRE_PMU: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_A_BIAS_CTRL3, 0xc000, 0x8000); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_A_BIAS_CTRL2, 0xc000, 0x8000); break; case SND_SOC_DAPM_POST_PMD: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_A_BIAS_CTRL3, 0xc000, 0x0000); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_A_BIAS_CTRL2, 0xc000, 0x0000); break; default: @@ -674,8 +674,8 @@ static int rt286_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 rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt286_priv *rt286 = snd_soc_component_get_drvdata(component); unsigned int val = 0; int d_len_code; @@ -687,7 +687,7 @@ static int rt286_hw_params(struct snd_pcm_substream *substream, case 48000: break; default: - dev_err(codec->dev, "Unsupported sample rate %d\n", + dev_err(component->dev, "Unsupported sample rate %d\n", params_rate(params)); return -EINVAL; } @@ -695,7 +695,7 @@ static int rt286_hw_params(struct snd_pcm_substream *substream, case 12288000: case 24576000: if (params_rate(params) != 48000) { - dev_err(codec->dev, "Sys_clk is not matched (%d %d)\n", + dev_err(component->dev, "Sys_clk is not matched (%d %d)\n", params_rate(params), rt286->sys_clk); return -EINVAL; } @@ -703,7 +703,7 @@ static int rt286_hw_params(struct snd_pcm_substream *substream, case 11289600: case 22579200: if (params_rate(params) != 44100) { - dev_err(codec->dev, "Sys_clk is not matched (%d %d)\n", + dev_err(component->dev, "Sys_clk is not matched (%d %d)\n", params_rate(params), rt286->sys_clk); return -EINVAL; } @@ -714,7 +714,7 @@ static int rt286_hw_params(struct snd_pcm_substream *substream, /* bit 3:0 Number of Channel */ val |= (params_channels(params) - 1); } else { - dev_err(codec->dev, "Unsupported channels %d\n", + dev_err(component->dev, "Unsupported channels %d\n", params_channels(params)); return -EINVAL; } @@ -745,27 +745,27 @@ static int rt286_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL1, 0x0018, d_len_code << 3); - dev_dbg(codec->dev, "format val = 0x%x\n", val); + dev_dbg(component->dev, "format val = 0x%x\n", val); - snd_soc_update_bits(codec, RT286_DAC_FORMAT, 0x407f, val); - snd_soc_update_bits(codec, RT286_ADC_FORMAT, 0x407f, val); + snd_soc_component_update_bits(component, RT286_DAC_FORMAT, 0x407f, val); + snd_soc_component_update_bits(component, RT286_ADC_FORMAT, 0x407f, val); return 0; } static int rt286_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBM_CFM: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL1, 0x800, 0x800); break; case SND_SOC_DAIFMT_CBS_CFS: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL1, 0x800, 0x0); break; default: @@ -774,27 +774,27 @@ static int rt286_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL1, 0x300, 0x0); break; case SND_SOC_DAIFMT_LEFT_J: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL1, 0x300, 0x1 << 8); break; case SND_SOC_DAIFMT_DSP_A: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL1, 0x300, 0x2 << 8); break; case SND_SOC_DAIFMT_DSP_B: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL1, 0x300, 0x3 << 8); break; default: return -EINVAL; } /* bit 15 Stream Type 0:PCM 1:Non-PCM */ - snd_soc_update_bits(codec, RT286_DAC_FORMAT, 0x8000, 0); - snd_soc_update_bits(codec, RT286_ADC_FORMAT, 0x8000, 0); + snd_soc_component_update_bits(component, RT286_DAC_FORMAT, 0x8000, 0); + snd_soc_component_update_bits(component, RT286_ADC_FORMAT, 0x8000, 0); return 0; } @@ -802,58 +802,58 @@ static int rt286_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) static int rt286_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { - struct snd_soc_codec *codec = dai->codec; - struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt286_priv *rt286 = snd_soc_component_get_drvdata(component); - dev_dbg(codec->dev, "%s freq=%d\n", __func__, freq); + dev_dbg(component->dev, "%s freq=%d\n", __func__, freq); if (RT286_SCLK_S_MCLK == clk_id) { - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL2, 0x0100, 0x0); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_PLL_CTRL1, 0x20, 0x20); } else { - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL2, 0x0100, 0x0100); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_PLL_CTRL, 0x4, 0x4); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_PLL_CTRL1, 0x20, 0x0); } switch (freq) { case 19200000: if (RT286_SCLK_S_MCLK == clk_id) { - dev_err(codec->dev, "Should not use MCLK\n"); + dev_err(component->dev, "Should not use MCLK\n"); return -EINVAL; } - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL2, 0x40, 0x40); break; case 24000000: if (RT286_SCLK_S_MCLK == clk_id) { - dev_err(codec->dev, "Should not use MCLK\n"); + dev_err(component->dev, "Should not use MCLK\n"); return -EINVAL; } - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL2, 0x40, 0x0); break; case 12288000: case 11289600: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL2, 0x8, 0x0); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_CLK_DIV, 0xfc1e, 0x0004); break; case 24576000: case 22579200: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL2, 0x8, 0x8); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_CLK_DIV, 0xfc1e, 0x5406); break; default: - dev_err(codec->dev, "Unsupported system clock\n"); + dev_err(component->dev, "Unsupported system clock\n"); return -EINVAL; } @@ -865,42 +865,42 @@ static int rt286_set_dai_sysclk(struct snd_soc_dai *dai, static int rt286_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; - dev_dbg(codec->dev, "%s ratio=%d\n", __func__, ratio); + dev_dbg(component->dev, "%s ratio=%d\n", __func__, ratio); if (50 == ratio) - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL1, 0x1000, 0x1000); else - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_I2S_CTRL1, 0x1000, 0x0); return 0; } -static int rt286_set_bias_level(struct snd_soc_codec *codec, +static int rt286_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { switch (level) { case SND_SOC_BIAS_PREPARE: - if (SND_SOC_BIAS_STANDBY == snd_soc_codec_get_bias_level(codec)) { - snd_soc_write(codec, + if (SND_SOC_BIAS_STANDBY == snd_soc_component_get_bias_level(component)) { + snd_soc_component_write(component, RT286_SET_AUDIO_POWER, AC_PWRST_D0); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_DC_GAIN, 0x200, 0x200); } break; case SND_SOC_BIAS_ON: mdelay(10); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT286_DC_GAIN, 0x200, 0x0); break; case SND_SOC_BIAS_STANDBY: - snd_soc_write(codec, + snd_soc_component_write(component, RT286_SET_AUDIO_POWER, AC_PWRST_D3); break; @@ -937,11 +937,11 @@ static irqreturn_t rt286_irq(int irq, void *data) return IRQ_HANDLED; } -static int rt286_probe(struct snd_soc_codec *codec) +static int rt286_probe(struct snd_soc_component *component) { - struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + struct rt286_priv *rt286 = snd_soc_component_get_drvdata(component); - rt286->codec = codec; + rt286->component = component; if (rt286->i2c->irq) { regmap_update_bits(rt286->regmap, @@ -956,19 +956,17 @@ static int rt286_probe(struct snd_soc_codec *codec) return 0; } -static int rt286_remove(struct snd_soc_codec *codec) +static void rt286_remove(struct snd_soc_component *component) { - struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + struct rt286_priv *rt286 = snd_soc_component_get_drvdata(component); cancel_delayed_work_sync(&rt286->jack_detect_work); - - return 0; } #ifdef CONFIG_PM -static int rt286_suspend(struct snd_soc_codec *codec) +static int rt286_suspend(struct snd_soc_component *component) { - struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + struct rt286_priv *rt286 = snd_soc_component_get_drvdata(component); regcache_cache_only(rt286->regmap, true); regcache_mark_dirty(rt286->regmap); @@ -976,12 +974,12 @@ static int rt286_suspend(struct snd_soc_codec *codec) return 0; } -static int rt286_resume(struct snd_soc_codec *codec) +static int rt286_resume(struct snd_soc_component *component) { - struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); + struct rt286_priv *rt286 = snd_soc_component_get_drvdata(component); regcache_cache_only(rt286->regmap, false); - rt286_index_sync(codec); + rt286_index_sync(component); regcache_sync(rt286->regmap); return 0; @@ -1046,21 +1044,21 @@ static struct snd_soc_dai_driver rt286_dai[] = { }; -static const struct snd_soc_codec_driver soc_codec_dev_rt286 = { - .probe = rt286_probe, - .remove = rt286_remove, - .suspend = rt286_suspend, - .resume = rt286_resume, - .set_bias_level = rt286_set_bias_level, - .idle_bias_off = true, - .component_driver = { - .controls = rt286_snd_controls, - .num_controls = ARRAY_SIZE(rt286_snd_controls), - .dapm_widgets = rt286_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(rt286_dapm_widgets), - .dapm_routes = rt286_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(rt286_dapm_routes), - }, +static const struct snd_soc_component_driver soc_component_dev_rt286 = { + .probe = rt286_probe, + .remove = rt286_remove, + .suspend = rt286_suspend, + .resume = rt286_resume, + .set_bias_level = rt286_set_bias_level, + .controls = rt286_snd_controls, + .num_controls = ARRAY_SIZE(rt286_snd_controls), + .dapm_widgets = rt286_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rt286_dapm_widgets), + .dapm_routes = rt286_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(rt286_dapm_routes), + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static const struct regmap_config rt286_regmap = { @@ -1243,7 +1241,8 @@ static int rt286_i2c_probe(struct i2c_client *i2c, } } - ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt286, + ret = devm_snd_soc_register_component(&i2c->dev, + &soc_component_dev_rt286, rt286_dai, ARRAY_SIZE(rt286_dai)); return ret; @@ -1255,7 +1254,6 @@ static int rt286_i2c_remove(struct i2c_client *i2c) if (i2c->irq) free_irq(i2c->irq, rt286); - snd_soc_unregister_codec(&i2c->dev); return 0; } diff --git a/sound/soc/codecs/rt286.h b/sound/soc/codecs/rt286.h index 7130edb152ef..c63d0e79ba86 100644 --- a/sound/soc/codecs/rt286.h +++ b/sound/soc/codecs/rt286.h @@ -199,7 +199,7 @@ enum { RT286_AIFS, }; -int rt286_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack); +int rt286_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack); #endif /* __RT286_H__ */ diff --git a/sound/soc/codecs/rt298.c b/sound/soc/codecs/rt298.c index ce963768449f..7bf4b31bdf55 100644 --- a/sound/soc/codecs/rt298.c +++ b/sound/soc/codecs/rt298.c @@ -39,7 +39,7 @@ struct rt298_priv { struct reg_default *index_cache; int index_cache_size; struct regmap *regmap; - struct snd_soc_codec *codec; + struct snd_soc_component *component; struct rt298_platform_data pdata; struct i2c_client *i2c; struct snd_soc_jack *jack; @@ -194,13 +194,13 @@ static bool rt298_readable_register(struct device *dev, unsigned int reg) } #ifdef CONFIG_PM -static void rt298_index_sync(struct snd_soc_codec *codec) +static void rt298_index_sync(struct snd_soc_component *component) { - struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec); + struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component); int i; for (i = 0; i < INDEX_CACHE_SIZE; i++) { - snd_soc_write(codec, rt298->index_cache[i].reg, + snd_soc_component_write(component, rt298->index_cache[i].reg, rt298->index_cache[i].def); } } @@ -227,10 +227,10 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) *hp = false; *mic = false; - if (!rt298->codec) + if (!rt298->component) return -EINVAL; - dapm = snd_soc_codec_get_dapm(rt298->codec); + dapm = snd_soc_component_get_dapm(rt298->component); if (rt298->pdata.cbj_en) { regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); @@ -323,9 +323,9 @@ static void rt298_jack_detect_work(struct work_struct *work) SND_JACK_MICROPHONE | SND_JACK_HEADPHONE); } -int rt298_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack) +int rt298_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack) { - struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec); + struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component); struct snd_soc_dapm_context *dapm; bool hp = false; bool mic = false; @@ -334,7 +334,7 @@ int rt298_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack) /* If jack in NULL, disable HS jack */ if (!jack) { regmap_update_bits(rt298->regmap, RT298_IRQ_CTRL, 0x2, 0x0); - dapm = snd_soc_codec_get_dapm(codec); + dapm = snd_soc_component_get_dapm(component); snd_soc_dapm_disable_pin(dapm, "LDO1"); snd_soc_dapm_sync(dapm); return 0; @@ -360,8 +360,8 @@ EXPORT_SYMBOL_GPL(rt298_mic_detect); static int is_mclk_mode(struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm); - struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); + struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component); if (rt298->clk_id == RT298_SCLK_S_MCLK) return 1; @@ -458,15 +458,15 @@ SOC_DAPM_ENUM("SPO source", rt298_spo_enum); static int rt298_spk_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_write(codec, + snd_soc_component_write(component, RT298_SPK_EAPD, RT298_SET_EAPD_HIGH); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_write(codec, + snd_soc_component_write(component, RT298_SPK_EAPD, RT298_SET_EAPD_LOW); break; @@ -480,14 +480,14 @@ static int rt298_spk_event(struct snd_soc_dapm_widget *w, static int rt298_set_dmic1_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_write(codec, RT298_SET_PIN_DMIC1, 0x20); + snd_soc_component_write(component, RT298_SET_PIN_DMIC1, 0x20); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_write(codec, RT298_SET_PIN_DMIC1, 0); + snd_soc_component_write(component, RT298_SET_PIN_DMIC1, 0); break; default: return 0; @@ -499,39 +499,39 @@ static int rt298_set_dmic1_event(struct snd_soc_dapm_widget *w, static int rt298_adc_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); unsigned int nid; nid = (w->reg >> 20) & 0xff; switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, nid, 0), 0x7080, 0x7000); /* If MCLK doesn't exist, reset AD filter */ - if (!(snd_soc_read(codec, RT298_VAD_CTRL) & 0x200)) { + if (!(snd_soc_component_read32(component, RT298_VAD_CTRL) & 0x200)) { pr_info("NO MCLK\n"); switch (nid) { case RT298_ADC_IN1: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_D_FILTER_CTRL, 0x2, 0x2); mdelay(10); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_D_FILTER_CTRL, 0x2, 0x0); break; case RT298_ADC_IN2: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_D_FILTER_CTRL, 0x4, 0x4); mdelay(10); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_D_FILTER_CTRL, 0x4, 0x0); break; } } break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, nid, 0), 0x7080, 0x7080); break; @@ -545,19 +545,19 @@ static int rt298_adc_event(struct snd_soc_dapm_widget *w, static int rt298_mic1_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_PRE_PMU: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_A_BIAS_CTRL3, 0xc000, 0x8000); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_A_BIAS_CTRL2, 0xc000, 0x8000); break; case SND_SOC_DAPM_POST_PMD: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_A_BIAS_CTRL3, 0xc000, 0x0000); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_A_BIAS_CTRL2, 0xc000, 0x0000); break; default: @@ -745,8 +745,8 @@ static int rt298_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 rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component); unsigned int val = 0; int d_len_code; @@ -756,7 +756,7 @@ static int rt298_hw_params(struct snd_pcm_substream *substream, case 48000: break; default: - dev_err(codec->dev, "Unsupported sample rate %d\n", + dev_err(component->dev, "Unsupported sample rate %d\n", params_rate(params)); return -EINVAL; } @@ -764,7 +764,7 @@ static int rt298_hw_params(struct snd_pcm_substream *substream, case 12288000: case 24576000: if (params_rate(params) != 48000) { - dev_err(codec->dev, "Sys_clk is not matched (%d %d)\n", + dev_err(component->dev, "Sys_clk is not matched (%d %d)\n", params_rate(params), rt298->sys_clk); return -EINVAL; } @@ -772,7 +772,7 @@ static int rt298_hw_params(struct snd_pcm_substream *substream, case 11289600: case 22579200: if (params_rate(params) != 44100) { - dev_err(codec->dev, "Sys_clk is not matched (%d %d)\n", + dev_err(component->dev, "Sys_clk is not matched (%d %d)\n", params_rate(params), rt298->sys_clk); return -EINVAL; } @@ -783,7 +783,7 @@ static int rt298_hw_params(struct snd_pcm_substream *substream, /* bit 3:0 Number of Channel */ val |= (params_channels(params) - 1); } else { - dev_err(codec->dev, "Unsupported channels %d\n", + dev_err(component->dev, "Unsupported channels %d\n", params_channels(params)); return -EINVAL; } @@ -814,27 +814,27 @@ static int rt298_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL1, 0x0018, d_len_code << 3); - dev_dbg(codec->dev, "format val = 0x%x\n", val); + dev_dbg(component->dev, "format val = 0x%x\n", val); - snd_soc_update_bits(codec, RT298_DAC_FORMAT, 0x407f, val); - snd_soc_update_bits(codec, RT298_ADC_FORMAT, 0x407f, val); + snd_soc_component_update_bits(component, RT298_DAC_FORMAT, 0x407f, val); + snd_soc_component_update_bits(component, RT298_ADC_FORMAT, 0x407f, val); return 0; } static int rt298_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBM_CFM: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL1, 0x800, 0x800); break; case SND_SOC_DAIFMT_CBS_CFS: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL1, 0x800, 0x0); break; default: @@ -843,27 +843,27 @@ static int rt298_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL1, 0x300, 0x0); break; case SND_SOC_DAIFMT_LEFT_J: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL1, 0x300, 0x1 << 8); break; case SND_SOC_DAIFMT_DSP_A: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL1, 0x300, 0x2 << 8); break; case SND_SOC_DAIFMT_DSP_B: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL1, 0x300, 0x3 << 8); break; default: return -EINVAL; } /* bit 15 Stream Type 0:PCM 1:Non-PCM */ - snd_soc_update_bits(codec, RT298_DAC_FORMAT, 0x8000, 0); - snd_soc_update_bits(codec, RT298_ADC_FORMAT, 0x8000, 0); + snd_soc_component_update_bits(component, RT298_DAC_FORMAT, 0x8000, 0); + snd_soc_component_update_bits(component, RT298_ADC_FORMAT, 0x8000, 0); return 0; } @@ -871,56 +871,56 @@ static int rt298_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) static int rt298_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { - struct snd_soc_codec *codec = dai->codec; - struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component); - dev_dbg(codec->dev, "%s freq=%d\n", __func__, freq); + dev_dbg(component->dev, "%s freq=%d\n", __func__, freq); if (RT298_SCLK_S_MCLK == clk_id) { - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL2, 0x0100, 0x0); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_PLL_CTRL1, 0x20, 0x20); } else { - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL2, 0x0100, 0x0100); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_PLL_CTRL1, 0x20, 0x0); } switch (freq) { case 19200000: if (RT298_SCLK_S_MCLK == clk_id) { - dev_err(codec->dev, "Should not use MCLK\n"); + dev_err(component->dev, "Should not use MCLK\n"); return -EINVAL; } - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL2, 0x40, 0x40); break; case 24000000: if (RT298_SCLK_S_MCLK == clk_id) { - dev_err(codec->dev, "Should not use MCLK\n"); + dev_err(component->dev, "Should not use MCLK\n"); return -EINVAL; } - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL2, 0x40, 0x0); break; case 12288000: case 11289600: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL2, 0x8, 0x0); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_CLK_DIV, 0xfc1e, 0x0004); break; case 24576000: case 22579200: - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL2, 0x8, 0x8); - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_CLK_DIV, 0xfc1e, 0x5406); break; default: - dev_err(codec->dev, "Unsupported system clock\n"); + dev_err(component->dev, "Unsupported system clock\n"); return -EINVAL; } @@ -932,39 +932,39 @@ static int rt298_set_dai_sysclk(struct snd_soc_dai *dai, static int rt298_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; - dev_dbg(codec->dev, "%s ratio=%d\n", __func__, ratio); + dev_dbg(component->dev, "%s ratio=%d\n", __func__, ratio); if (50 == ratio) - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL1, 0x1000, 0x1000); else - snd_soc_update_bits(codec, + snd_soc_component_update_bits(component, RT298_I2S_CTRL1, 0x1000, 0x0); return 0; } -static int rt298_set_bias_level(struct snd_soc_codec *codec, +static int rt298_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { switch (level) { case SND_SOC_BIAS_PREPARE: if (SND_SOC_BIAS_STANDBY == - snd_soc_codec_get_bias_level(codec)) { - snd_soc_write(codec, + snd_soc_component_get_bias_level(component)) { + snd_soc_component_write(component, RT298_SET_AUDIO_POWER, AC_PWRST_D0); - snd_soc_update_bits(codec, 0x0d, 0x200, 0x200); - snd_soc_update_bits(codec, 0x52, 0x80, 0x0); + snd_soc_component_update_bits(component, 0x0d, 0x200, 0x200); + snd_soc_component_update_bits(component, 0x52, 0x80, 0x0); mdelay(20); - snd_soc_update_bits(codec, 0x0d, 0x200, 0x0); - snd_soc_update_bits(codec, 0x52, 0x80, 0x80); + snd_soc_component_update_bits(component, 0x0d, 0x200, 0x0); + snd_soc_component_update_bits(component, 0x52, 0x80, 0x80); } break; case SND_SOC_BIAS_STANDBY: - snd_soc_write(codec, + snd_soc_component_write(component, RT298_SET_AUDIO_POWER, AC_PWRST_D3); break; @@ -1003,11 +1003,11 @@ static irqreturn_t rt298_irq(int irq, void *data) return IRQ_HANDLED; } -static int rt298_probe(struct snd_soc_codec *codec) +static int rt298_probe(struct snd_soc_component *component) { - struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec); + struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component); - rt298->codec = codec; + rt298->component = component; if (rt298->i2c->irq) { regmap_update_bits(rt298->regmap, @@ -1022,19 +1022,17 @@ static int rt298_probe(struct snd_soc_codec *codec) return 0; } -static int rt298_remove(struct snd_soc_codec *codec) +static void rt298_remove(struct snd_soc_component *component) { - struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec); + struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component); cancel_delayed_work_sync(&rt298->jack_detect_work); - - return 0; } #ifdef CONFIG_PM -static int rt298_suspend(struct snd_soc_codec *codec) +static int rt298_suspend(struct snd_soc_component *component) { - struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec); + struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component); rt298->is_hp_in = -1; regcache_cache_only(rt298->regmap, true); @@ -1043,12 +1041,12 @@ static int rt298_suspend(struct snd_soc_codec *codec) return 0; } -static int rt298_resume(struct snd_soc_codec *codec) +static int rt298_resume(struct snd_soc_component *component) { - struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec); + struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component); regcache_cache_only(rt298->regmap, false); - rt298_index_sync(codec); + rt298_index_sync(component); regcache_sync(rt298->regmap); return 0; @@ -1113,21 +1111,21 @@ static struct snd_soc_dai_driver rt298_dai[] = { }; -static const struct snd_soc_codec_driver soc_codec_dev_rt298 = { - .probe = rt298_probe, - .remove = rt298_remove, - .suspend = rt298_suspend, - .resume = rt298_resume, - .set_bias_level = rt298_set_bias_level, - .idle_bias_off = true, - .component_driver = { - .controls = rt298_snd_controls, - .num_controls = ARRAY_SIZE(rt298_snd_controls), - .dapm_widgets = rt298_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(rt298_dapm_widgets), - .dapm_routes = rt298_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(rt298_dapm_routes), - }, +static const struct snd_soc_component_driver soc_component_dev_rt298 = { + .probe = rt298_probe, + .remove = rt298_remove, + .suspend = rt298_suspend, + .resume = rt298_resume, + .set_bias_level = rt298_set_bias_level, + .controls = rt298_snd_controls, + .num_controls = ARRAY_SIZE(rt298_snd_controls), + .dapm_widgets = rt298_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rt298_dapm_widgets), + .dapm_routes = rt298_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(rt298_dapm_routes), + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static const struct regmap_config rt298_regmap = { @@ -1288,7 +1286,8 @@ static int rt298_i2c_probe(struct i2c_client *i2c, } } - ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt298, + ret = devm_snd_soc_register_component(&i2c->dev, + &soc_component_dev_rt298, rt298_dai, ARRAY_SIZE(rt298_dai)); return ret; @@ -1300,7 +1299,6 @@ static int rt298_i2c_remove(struct i2c_client *i2c) if (i2c->irq) free_irq(i2c->irq, rt298); - snd_soc_unregister_codec(&i2c->dev); return 0; } diff --git a/sound/soc/codecs/rt298.h b/sound/soc/codecs/rt298.h index 3638f3d61209..b4db935359fa 100644 --- a/sound/soc/codecs/rt298.h +++ b/sound/soc/codecs/rt298.h @@ -210,7 +210,7 @@ enum { RT298_AIFS, }; -int rt298_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack); +int rt298_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack); #endif /* __RT298_H__ */ diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c index 2144edca97b0..84184d90385b 100644 --- a/sound/soc/codecs/rt5514-spi.c +++ b/sound/soc/codecs/rt5514-spi.c @@ -35,6 +35,8 @@ #include "rt5514-spi.h" +#define DRV_NAME "rt5514-spi" + static struct spi_device *rt5514_spi; struct rt5514_dsp { @@ -211,8 +213,9 @@ static int rt5514_spi_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); struct rt5514_dsp *rt5514_dsp = - snd_soc_platform_get_drvdata(rtd->platform); + snd_soc_component_get_drvdata(component); int ret; u8 buf[8]; @@ -235,8 +238,9 @@ static int rt5514_spi_hw_params(struct snd_pcm_substream *substream, static int rt5514_spi_hw_free(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); struct rt5514_dsp *rt5514_dsp = - snd_soc_platform_get_drvdata(rtd->platform); + snd_soc_component_get_drvdata(component); mutex_lock(&rt5514_dsp->dma_lock); rt5514_dsp->substream = NULL; @@ -252,8 +256,9 @@ static snd_pcm_uframes_t rt5514_spi_pcm_pointer( { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); struct rt5514_dsp *rt5514_dsp = - snd_soc_platform_get_drvdata(rtd->platform); + snd_soc_component_get_drvdata(component); return bytes_to_frames(runtime, rt5514_dsp->dma_offset); } @@ -267,18 +272,18 @@ static const struct snd_pcm_ops rt5514_spi_pcm_ops = { .page = snd_pcm_lib_get_vmalloc_page, }; -static int rt5514_spi_pcm_probe(struct snd_soc_platform *platform) +static int rt5514_spi_pcm_probe(struct snd_soc_component *component) { struct rt5514_dsp *rt5514_dsp; int ret; - rt5514_dsp = devm_kzalloc(platform->dev, sizeof(*rt5514_dsp), + rt5514_dsp = devm_kzalloc(component->dev, sizeof(*rt5514_dsp), GFP_KERNEL); rt5514_dsp->dev = &rt5514_spi->dev; mutex_init(&rt5514_dsp->dma_lock); INIT_DELAYED_WORK(&rt5514_dsp->copy_work, rt5514_spi_copy_work); - snd_soc_platform_set_drvdata(platform, rt5514_dsp); + snd_soc_component_set_drvdata(component, rt5514_dsp); if (rt5514_spi->irq) { ret = devm_request_threaded_irq(&rt5514_spi->dev, @@ -296,15 +301,12 @@ static int rt5514_spi_pcm_probe(struct snd_soc_platform *platform) return 0; } -static const struct snd_soc_platform_driver rt5514_spi_platform = { +static const struct snd_soc_component_driver rt5514_spi_component = { + .name = DRV_NAME, .probe = rt5514_spi_pcm_probe, .ops = &rt5514_spi_pcm_ops, }; -static const struct snd_soc_component_driver rt5514_spi_dai_component = { - .name = "rt5514-spi-dai", -}; - /** * rt5514_spi_burst_read - Read data from SPI by rt5514 address. * @addr: Start address. @@ -445,14 +447,8 @@ static int rt5514_spi_probe(struct spi_device *spi) rt5514_spi = spi; - ret = devm_snd_soc_register_platform(&spi->dev, &rt5514_spi_platform); - if (ret < 0) { - dev_err(&spi->dev, "Failed to register platform.\n"); - return ret; - } - ret = devm_snd_soc_register_component(&spi->dev, - &rt5514_spi_dai_component, + &rt5514_spi_component, &rt5514_spi_dai, 1); if (ret < 0) { dev_err(&spi->dev, "Failed to register component.\n"); diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c index 831b297978a4..6b5669f3e85d 100644 --- a/sound/soc/codecs/rt5651.c +++ b/sound/soc/codecs/rt5651.c @@ -19,7 +19,6 @@ #include <linux/platform_device.h> #include <linux/spi/spi.h> #include <linux/acpi.h> -#include <linux/dmi.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h> @@ -32,10 +31,6 @@ #include "rl6231.h" #include "rt5651.h" -#define RT5651_JD_MAP(quirk) ((quirk) & GENMASK(7, 0)) -#define RT5651_IN2_DIFF BIT(16) -#define RT5651_DMIC_EN BIT(17) - #define RT5651_DEVICE_ID_VALUE 0x6281 #define RT5651_PR_RANGE_BASE (0xff + 1) @@ -43,8 +38,6 @@ #define RT5651_PR_BASE (RT5651_PR_RANGE_BASE + (0 * RT5651_PR_SPACING)) -static unsigned long rt5651_quirk; - static const struct regmap_range_cfg rt5651_ranges[] = { { .name = "PR", .range_min = RT5651_PR_BASE, .range_max = RT5651_PR_BASE + 0xb4, @@ -384,36 +377,22 @@ static const struct snd_kcontrol_new rt5651_snd_controls[] = { static int set_dmic_clk(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 rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); int idx, rate; rate = rt5651->sysclk / rl6231_get_pre_div(rt5651->regmap, RT5651_ADDA_CLK1, RT5651_I2S_PD1_SFT); idx = rl6231_calc_dmic_clk(rate); if (idx < 0) - dev_err(codec->dev, "Failed to set DMIC clock\n"); + dev_err(component->dev, "Failed to set DMIC clock\n"); else - snd_soc_update_bits(codec, RT5651_DMIC, RT5651_DMIC_CLK_MASK, + snd_soc_component_update_bits(component, RT5651_DMIC, RT5651_DMIC_CLK_MASK, idx << RT5651_DMIC_CLK_SFT); return idx; } -static int is_sysclk_from_pll(struct snd_soc_dapm_widget *source, - struct snd_soc_dapm_widget *sink) -{ - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm); - unsigned int val; - - val = snd_soc_read(codec, RT5651_GLB_CLK); - val &= RT5651_SCLK_SRC_MASK; - if (val == RT5651_SCLK_SRC_PLL1) - return 1; - else - return 0; -} - /* Digital Mixer */ static const struct snd_kcontrol_new rt5651_sto1_adc_l_mix[] = { SOC_DAPM_SINGLE("ADC1 Switch", RT5651_STO1_ADC_MIXER, @@ -703,8 +682,8 @@ static const struct snd_kcontrol_new rt5651_pdm_r_mux = static int rt5651_amp_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 rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_POST_PMU: @@ -741,8 +720,8 @@ static int rt5651_amp_power_event(struct snd_soc_dapm_widget *w, static int rt5651_hp_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 rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_POST_PMU: @@ -786,8 +765,8 @@ static int rt5651_hp_post_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 rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_POST_PMU: @@ -806,16 +785,16 @@ static int rt5651_hp_post_event(struct snd_soc_dapm_widget *w, static int rt5651_bst1_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_update_bits(codec, RT5651_PWR_ANLG2, + snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, RT5651_PWR_BST1_OP2, RT5651_PWR_BST1_OP2); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_update_bits(codec, RT5651_PWR_ANLG2, + snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, RT5651_PWR_BST1_OP2, 0); break; @@ -829,16 +808,16 @@ static int rt5651_bst1_event(struct snd_soc_dapm_widget *w, static int rt5651_bst2_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_update_bits(codec, RT5651_PWR_ANLG2, + snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, RT5651_PWR_BST2_OP2, RT5651_PWR_BST2_OP2); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_update_bits(codec, RT5651_PWR_ANLG2, + snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, RT5651_PWR_BST2_OP2, 0); break; @@ -852,16 +831,16 @@ static int rt5651_bst2_event(struct snd_soc_dapm_widget *w, static int rt5651_bst3_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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_update_bits(codec, RT5651_PWR_ANLG2, + snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, RT5651_PWR_BST3_OP2, RT5651_PWR_BST3_OP2); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_update_bits(codec, RT5651_PWR_ANLG2, + snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, RT5651_PWR_BST3_OP2, 0); break; @@ -885,12 +864,6 @@ static const struct snd_soc_dapm_widget rt5651_dapm_widgets[] = { SND_SOC_DAPM_SUPPLY_S("ADC ASRC", 1, RT5651_PLL_MODE_2, 11, 0, NULL, 0), - SND_SOC_DAPM_SUPPLY("PLL1", RT5651_PWR_ANLG2, - RT5651_PWR_PLL_BIT, 0, NULL, 0), - /* Input Side */ - SND_SOC_DAPM_SUPPLY("JD Power", RT5651_PWR_ANLG2, - RT5651_PWM_JD_M_BIT, 0, NULL, 0), - /* micbias */ SND_SOC_DAPM_SUPPLY("LDO", RT5651_PWR_ANLG1, RT5651_PWR_LDO_BIT, 0, NULL, 0), @@ -1169,7 +1142,6 @@ static const struct snd_soc_dapm_route rt5651_dapm_routes[] = { {"Stereo1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux"}, {"Stereo1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux"}, {"Stereo1 ADC MIXL", NULL, "Stereo1 Filter"}, - {"Stereo1 Filter", NULL, "PLL1", is_sysclk_from_pll}, {"Stereo1 Filter", NULL, "ADC ASRC"}, {"Stereo1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux"}, @@ -1179,7 +1151,6 @@ static const struct snd_soc_dapm_route rt5651_dapm_routes[] = { {"Stereo2 ADC MIXL", "ADC1 Switch", "Stereo2 ADC L1 Mux"}, {"Stereo2 ADC MIXL", "ADC2 Switch", "Stereo2 ADC L2 Mux"}, {"Stereo2 ADC MIXL", NULL, "Stereo2 Filter"}, - {"Stereo2 Filter", NULL, "PLL1", is_sysclk_from_pll}, {"Stereo2 Filter", NULL, "ADC ASRC"}, {"Stereo2 ADC MIXR", "ADC1 Switch", "Stereo2 ADC R1 Mux"}, @@ -1246,10 +1217,8 @@ static const struct snd_soc_dapm_route rt5651_dapm_routes[] = { {"PDM R Mux", "DD MIX", "DAC MIXR"}, {"DAC L1", NULL, "Stereo DAC MIXL"}, - {"DAC L1", NULL, "PLL1", is_sysclk_from_pll}, {"DAC L1", NULL, "DAC L1 Power"}, {"DAC R1", NULL, "Stereo DAC MIXR"}, - {"DAC R1", NULL, "PLL1", is_sysclk_from_pll}, {"DAC R1", NULL, "DAC R1 Power"}, {"DD MIXL", "DAC L1 Switch", "DAC MIXL"}, @@ -1313,8 +1282,8 @@ static const struct snd_soc_dapm_route rt5651_dapm_routes[] = { static int rt5651_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 rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); unsigned int val_len = 0, val_clk, mask_clk; int pre_div, bclk_ms, frame_size; @@ -1322,12 +1291,12 @@ static int rt5651_hw_params(struct snd_pcm_substream *substream, pre_div = rl6231_get_clk_info(rt5651->sysclk, rt5651->lrck[dai->id]); if (pre_div < 0) { - dev_err(codec->dev, "Unsupported clock setting\n"); + dev_err(component->dev, "Unsupported clock setting\n"); return -EINVAL; } frame_size = snd_soc_params_to_frame_size(params); if (frame_size < 0) { - dev_err(codec->dev, "Unsupported frame size: %d\n", frame_size); + dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); return -EINVAL; } bclk_ms = frame_size > 32 ? 1 : 0; @@ -1358,19 +1327,19 @@ static int rt5651_hw_params(struct snd_pcm_substream *substream, case RT5651_AIF1: mask_clk = RT5651_I2S_PD1_MASK; val_clk = pre_div << RT5651_I2S_PD1_SFT; - snd_soc_update_bits(codec, RT5651_I2S1_SDP, + snd_soc_component_update_bits(component, RT5651_I2S1_SDP, RT5651_I2S_DL_MASK, val_len); - snd_soc_update_bits(codec, RT5651_ADDA_CLK1, mask_clk, val_clk); + snd_soc_component_update_bits(component, RT5651_ADDA_CLK1, mask_clk, val_clk); break; case RT5651_AIF2: mask_clk = RT5651_I2S_BCLK_MS2_MASK | RT5651_I2S_PD2_MASK; val_clk = pre_div << RT5651_I2S_PD2_SFT; - snd_soc_update_bits(codec, RT5651_I2S2_SDP, + snd_soc_component_update_bits(component, RT5651_I2S2_SDP, RT5651_I2S_DL_MASK, val_len); - snd_soc_update_bits(codec, RT5651_ADDA_CLK1, mask_clk, val_clk); + snd_soc_component_update_bits(component, RT5651_ADDA_CLK1, mask_clk, val_clk); break; default: - dev_err(codec->dev, "Wrong dai->id: %d\n", dai->id); + dev_err(component->dev, "Wrong dai->id: %d\n", dai->id); return -EINVAL; } @@ -1379,8 +1348,8 @@ static int rt5651_hw_params(struct snd_pcm_substream *substream, static int rt5651_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) { - struct snd_soc_codec *codec = dai->codec; - struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); unsigned int reg_val = 0; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { @@ -1423,17 +1392,17 @@ static int rt5651_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) switch (dai->id) { case RT5651_AIF1: - snd_soc_update_bits(codec, RT5651_I2S1_SDP, + snd_soc_component_update_bits(component, RT5651_I2S1_SDP, RT5651_I2S_MS_MASK | RT5651_I2S_BP_MASK | RT5651_I2S_DF_MASK, reg_val); break; case RT5651_AIF2: - snd_soc_update_bits(codec, RT5651_I2S2_SDP, + snd_soc_component_update_bits(component, RT5651_I2S2_SDP, RT5651_I2S_MS_MASK | RT5651_I2S_BP_MASK | RT5651_I2S_DF_MASK, reg_val); break; default: - dev_err(codec->dev, "Wrong dai->id: %d\n", dai->id); + dev_err(component->dev, "Wrong dai->id: %d\n", dai->id); return -EINVAL; } return 0; @@ -1442,9 +1411,10 @@ static int rt5651_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) static int rt5651_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { - struct snd_soc_codec *codec = dai->codec; - struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); unsigned int reg_val = 0; + unsigned int pll_bit = 0; if (freq == rt5651->sysclk && clk_id == rt5651->sysclk_src) return 0; @@ -1455,15 +1425,18 @@ static int rt5651_set_dai_sysclk(struct snd_soc_dai *dai, break; case RT5651_SCLK_S_PLL1: reg_val |= RT5651_SCLK_SRC_PLL1; + pll_bit |= RT5651_PWR_PLL; break; case RT5651_SCLK_S_RCCLK: reg_val |= RT5651_SCLK_SRC_RCCLK; break; default: - dev_err(codec->dev, "Invalid clock id (%d)\n", clk_id); + dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); return -EINVAL; } - snd_soc_update_bits(codec, RT5651_GLB_CLK, + snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, + RT5651_PWR_PLL, pll_bit); + snd_soc_component_update_bits(component, RT5651_GLB_CLK, RT5651_SCLK_SRC_MASK, reg_val); rt5651->sysclk = freq; rt5651->sysclk_src = clk_id; @@ -1476,8 +1449,8 @@ static int rt5651_set_dai_sysclk(struct snd_soc_dai *dai, static int rt5651_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, unsigned int freq_in, unsigned int freq_out) { - struct snd_soc_codec *codec = dai->codec; - struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); struct rl6231_pll_code pll_code; int ret; @@ -1486,46 +1459,46 @@ static int rt5651_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, return 0; if (!freq_in || !freq_out) { - dev_dbg(codec->dev, "PLL disabled\n"); + dev_dbg(component->dev, "PLL disabled\n"); rt5651->pll_in = 0; rt5651->pll_out = 0; - snd_soc_update_bits(codec, RT5651_GLB_CLK, + snd_soc_component_update_bits(component, RT5651_GLB_CLK, RT5651_SCLK_SRC_MASK, RT5651_SCLK_SRC_MCLK); return 0; } switch (source) { case RT5651_PLL1_S_MCLK: - snd_soc_update_bits(codec, RT5651_GLB_CLK, + snd_soc_component_update_bits(component, RT5651_GLB_CLK, RT5651_PLL1_SRC_MASK, RT5651_PLL1_SRC_MCLK); break; case RT5651_PLL1_S_BCLK1: - snd_soc_update_bits(codec, RT5651_GLB_CLK, + snd_soc_component_update_bits(component, RT5651_GLB_CLK, RT5651_PLL1_SRC_MASK, RT5651_PLL1_SRC_BCLK1); break; case RT5651_PLL1_S_BCLK2: - snd_soc_update_bits(codec, RT5651_GLB_CLK, + snd_soc_component_update_bits(component, RT5651_GLB_CLK, RT5651_PLL1_SRC_MASK, RT5651_PLL1_SRC_BCLK2); break; default: - dev_err(codec->dev, "Unknown PLL source %d\n", source); + dev_err(component->dev, "Unknown PLL source %d\n", source); return -EINVAL; } ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); if (ret < 0) { - dev_err(codec->dev, "Unsupport input clock %d\n", freq_in); + dev_err(component->dev, "Unsupport input clock %d\n", freq_in); return ret; } - dev_dbg(codec->dev, "bypass=%d m=%d n=%d k=%d\n", + dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), pll_code.n_code, pll_code.k_code); - snd_soc_write(codec, RT5651_PLL_CTRL1, + snd_soc_component_write(component, RT5651_PLL_CTRL1, pll_code.n_code << RT5651_PLL_N_SFT | pll_code.k_code); - snd_soc_write(codec, RT5651_PLL_CTRL2, + snd_soc_component_write(component, RT5651_PLL_CTRL2, (pll_code.m_bp ? 0 : pll_code.m_code) << RT5651_PLL_M_SFT | pll_code.m_bp << RT5651_PLL_M_BP_SFT); @@ -1536,46 +1509,44 @@ static int rt5651_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, return 0; } -static int rt5651_set_bias_level(struct snd_soc_codec *codec, +static int rt5651_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); - switch (level) { case SND_SOC_BIAS_PREPARE: - if (SND_SOC_BIAS_STANDBY == snd_soc_codec_get_bias_level(codec)) { - snd_soc_update_bits(codec, RT5651_PWR_ANLG1, + if (SND_SOC_BIAS_STANDBY == snd_soc_component_get_bias_level(component)) { + if (snd_soc_component_read32(component, RT5651_PLL_MODE_1) & 0x9200) + snd_soc_component_update_bits(component, RT5651_D_MISC, + 0xc00, 0xc00); + } + break; + case SND_SOC_BIAS_STANDBY: + if (SND_SOC_BIAS_OFF == snd_soc_component_get_bias_level(component)) { + snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, RT5651_PWR_VREF1 | RT5651_PWR_MB | RT5651_PWR_BG | RT5651_PWR_VREF2, RT5651_PWR_VREF1 | RT5651_PWR_MB | RT5651_PWR_BG | RT5651_PWR_VREF2); usleep_range(10000, 15000); - snd_soc_update_bits(codec, RT5651_PWR_ANLG1, + snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, RT5651_PWR_FV1 | RT5651_PWR_FV2, RT5651_PWR_FV1 | RT5651_PWR_FV2); - snd_soc_update_bits(codec, RT5651_PWR_ANLG1, - RT5651_PWR_LDO_DVO_MASK, - RT5651_PWR_LDO_DVO_1_2V); - snd_soc_update_bits(codec, RT5651_D_MISC, 0x1, 0x1); - if (snd_soc_read(codec, RT5651_PLL_MODE_1) & 0x9200) - snd_soc_update_bits(codec, RT5651_D_MISC, - 0xc00, 0xc00); + snd_soc_component_update_bits(component, RT5651_D_MISC, 0x1, 0x1); } break; - case SND_SOC_BIAS_STANDBY: - snd_soc_write(codec, RT5651_D_MISC, 0x0010); - snd_soc_write(codec, RT5651_PWR_DIG1, 0x0000); - snd_soc_write(codec, RT5651_PWR_DIG2, 0x0000); - snd_soc_write(codec, RT5651_PWR_VOL, 0x0000); - snd_soc_write(codec, RT5651_PWR_MIXER, 0x0000); - if (rt5651->pdata.jd_src) { - snd_soc_write(codec, RT5651_PWR_ANLG2, 0x0204); - snd_soc_write(codec, RT5651_PWR_ANLG1, 0x0002); - } else { - snd_soc_write(codec, RT5651_PWR_ANLG1, 0x0000); - snd_soc_write(codec, RT5651_PWR_ANLG2, 0x0000); - } + case SND_SOC_BIAS_OFF: + snd_soc_component_write(component, RT5651_D_MISC, 0x0010); + snd_soc_component_write(component, RT5651_PWR_DIG1, 0x0000); + snd_soc_component_write(component, RT5651_PWR_DIG2, 0x0000); + snd_soc_component_write(component, RT5651_PWR_VOL, 0x0000); + snd_soc_component_write(component, RT5651_PWR_MIXER, 0x0000); + /* Do not touch the LDO voltage select bits on bias-off */ + snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, + ~RT5651_PWR_LDO_DVO_MASK, 0); + /* Leave PLL1 and jack-detect power as is, all others off */ + snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, + ~(RT5651_PWR_PLL | RT5651_PWR_JD_M), 0); break; default: @@ -1585,53 +1556,326 @@ static int rt5651_set_bias_level(struct snd_soc_codec *codec, return 0; } -static int rt5651_probe(struct snd_soc_codec *codec) +static void rt5651_enable_micbias1_for_ovcd(struct snd_soc_component *component) +{ + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + + snd_soc_dapm_mutex_lock(dapm); + snd_soc_dapm_force_enable_pin_unlocked(dapm, "LDO"); + snd_soc_dapm_force_enable_pin_unlocked(dapm, "micbias1"); + /* OVCD is unreliable when used with RCCLK as sysclk-source */ + snd_soc_dapm_force_enable_pin_unlocked(dapm, "Platform Clock"); + snd_soc_dapm_sync_unlocked(dapm); + snd_soc_dapm_mutex_unlock(dapm); +} + +static void rt5651_disable_micbias1_for_ovcd(struct snd_soc_component *component) +{ + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + + snd_soc_dapm_mutex_lock(dapm); + snd_soc_dapm_disable_pin_unlocked(dapm, "Platform Clock"); + snd_soc_dapm_disable_pin_unlocked(dapm, "micbias1"); + snd_soc_dapm_disable_pin_unlocked(dapm, "LDO"); + snd_soc_dapm_sync_unlocked(dapm); + snd_soc_dapm_mutex_unlock(dapm); +} + +static void rt5651_clear_micbias1_ovcd(struct snd_soc_component *component) +{ + snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2, + RT5651_MB1_OC_CLR, 0); +} + +static bool rt5651_micbias1_ovcd(struct snd_soc_component *component) +{ + int val; + + val = snd_soc_component_read32(component, RT5651_IRQ_CTRL2); + dev_dbg(component->dev, "irq ctrl2 %#04x\n", val); + + return (val & RT5651_MB1_OC_CLR); +} + +static bool rt5651_jack_inserted(struct snd_soc_component *component) +{ + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); + int val; + + val = snd_soc_component_read32(component, RT5651_INT_IRQ_ST); + dev_dbg(component->dev, "irq status %#04x\n", val); + + switch (rt5651->jd_src) { + case RT5651_JD1_1: + val &= 0x1000; + break; + case RT5651_JD1_2: + val &= 0x2000; + break; + case RT5651_JD2: + val &= 0x4000; + break; + default: + break; + } + + return val == 0; +} + +/* Jack detect timings */ +#define JACK_SETTLE_TIME 100 /* milli seconds */ +#define JACK_DETECT_COUNT 5 +#define JACK_DETECT_MAXCOUNT 20 /* Aprox. 2 seconds worth of tries */ + +static int rt5651_detect_headset(struct snd_soc_component *component) +{ + int i, headset_count = 0, headphone_count = 0; + + /* + * We get the insertion event before the jack is fully inserted at which + * point the second ring on a TRRS connector may short the 2nd ring and + * sleeve contacts, also the overcurrent detection is not entirely + * reliable. So we try several times with a wait in between until we + * detect the same type JACK_DETECT_COUNT times in a row. + */ + for (i = 0; i < JACK_DETECT_MAXCOUNT; i++) { + /* Clear any previous over-current status flag */ + rt5651_clear_micbias1_ovcd(component); + + msleep(JACK_SETTLE_TIME); + + /* Check the jack is still connected before checking ovcd */ + if (!rt5651_jack_inserted(component)) + return 0; + + if (rt5651_micbias1_ovcd(component)) { + /* + * Over current detected, there is a short between the + * 2nd ring contact and the ground, so a TRS connector + * without a mic contact and thus plain headphones. + */ + dev_dbg(component->dev, "mic-gnd shorted\n"); + headset_count = 0; + headphone_count++; + if (headphone_count == JACK_DETECT_COUNT) + return SND_JACK_HEADPHONE; + } else { + dev_dbg(component->dev, "mic-gnd open\n"); + headphone_count = 0; + headset_count++; + if (headset_count == JACK_DETECT_COUNT) + return SND_JACK_HEADSET; + } + } + + dev_err(component->dev, "Error detecting headset vs headphones, bad contact?, assuming headphones\n"); + return SND_JACK_HEADPHONE; +} + +static void rt5651_jack_detect_work(struct work_struct *work) { - struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - - rt5651->codec = codec; - - snd_soc_update_bits(codec, RT5651_PWR_ANLG1, - RT5651_PWR_VREF1 | RT5651_PWR_MB | - RT5651_PWR_BG | RT5651_PWR_VREF2, - RT5651_PWR_VREF1 | RT5651_PWR_MB | - RT5651_PWR_BG | RT5651_PWR_VREF2); - usleep_range(10000, 15000); - snd_soc_update_bits(codec, RT5651_PWR_ANLG1, - RT5651_PWR_FV1 | RT5651_PWR_FV2, - RT5651_PWR_FV1 | RT5651_PWR_FV2); - - snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF); - - if (rt5651->pdata.jd_src) { - snd_soc_dapm_force_enable_pin(dapm, "JD Power"); - snd_soc_dapm_force_enable_pin(dapm, "LDO"); - snd_soc_dapm_sync(dapm); - - regmap_update_bits(rt5651->regmap, RT5651_MICBIAS, - 0x38, 0x38); + struct rt5651_priv *rt5651 = + container_of(work, struct rt5651_priv, jack_detect_work); + int report = 0; + + if (rt5651_jack_inserted(rt5651->component)) { + rt5651_enable_micbias1_for_ovcd(rt5651->component); + report = rt5651_detect_headset(rt5651->component); + rt5651_disable_micbias1_for_ovcd(rt5651->component); + } + + snd_soc_jack_report(rt5651->hp_jack, report, SND_JACK_HEADSET); +} + +static irqreturn_t rt5651_irq(int irq, void *data) +{ + struct rt5651_priv *rt5651 = data; + + queue_work(system_power_efficient_wq, &rt5651->jack_detect_work); + + return IRQ_HANDLED; +} + +static int rt5651_set_jack(struct snd_soc_component *component, + struct snd_soc_jack *hp_jack, void *data) +{ + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); + int ret; + + if (!rt5651->irq) + return -EINVAL; + + /* IRQ output on GPIO1 */ + snd_soc_component_update_bits(component, RT5651_GPIO_CTRL1, + RT5651_GP1_PIN_MASK, RT5651_GP1_PIN_IRQ); + + /* Select jack detect source */ + switch (rt5651->jd_src) { + case RT5651_JD1_1: + snd_soc_component_update_bits(component, RT5651_JD_CTRL2, + RT5651_JD_TRG_SEL_MASK, RT5651_JD_TRG_SEL_JD1_1); + snd_soc_component_update_bits(component, RT5651_IRQ_CTRL1, + RT5651_JD1_1_IRQ_EN, RT5651_JD1_1_IRQ_EN); + break; + case RT5651_JD1_2: + snd_soc_component_update_bits(component, RT5651_JD_CTRL2, + RT5651_JD_TRG_SEL_MASK, RT5651_JD_TRG_SEL_JD1_2); + snd_soc_component_update_bits(component, RT5651_IRQ_CTRL1, + RT5651_JD1_2_IRQ_EN, RT5651_JD1_2_IRQ_EN); + break; + case RT5651_JD2: + snd_soc_component_update_bits(component, RT5651_JD_CTRL2, + RT5651_JD_TRG_SEL_MASK, RT5651_JD_TRG_SEL_JD2); + snd_soc_component_update_bits(component, RT5651_IRQ_CTRL1, + RT5651_JD2_IRQ_EN, RT5651_JD2_IRQ_EN); + break; + case RT5651_JD_NULL: + return 0; + default: + dev_err(component->dev, "Currently only JD1_1 / JD1_2 / JD2 are supported\n"); + return -EINVAL; } + /* Enable jack detect power */ + snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, + RT5651_PWR_JD_M, RT5651_PWR_JD_M); + + /* Set OVCD threshold current and scale-factor */ + snd_soc_component_write(component, RT5651_PR_BASE + RT5651_BIAS_CUR4, + 0xa800 | rt5651->ovcd_sf); + + snd_soc_component_update_bits(component, RT5651_MICBIAS, + RT5651_MIC1_OVCD_MASK | + RT5651_MIC1_OVTH_MASK | + RT5651_PWR_CLK12M_MASK | + RT5651_PWR_MB_MASK, + RT5651_MIC1_OVCD_EN | + rt5651->ovcd_th | + RT5651_PWR_MB_PU | + RT5651_PWR_CLK12M_PU); + + /* + * The over-current-detect is only reliable in detecting the absence + * of over-current, when the mic-contact in the jack is short-circuited, + * the hardware periodically retries if it can apply the bias-current + * leading to the ovcd status flip-flopping 1-0-1 with it being 0 about + * 10% of the time, as we poll the ovcd status bit we might hit that + * 10%, so we enable sticky mode and when checking OVCD we clear the + * status, msleep() a bit and then check to get a reliable reading. + */ + snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2, + RT5651_MB1_OC_STKY_MASK, RT5651_MB1_OC_STKY_EN); + + rt5651->hp_jack = hp_jack; + + ret = devm_request_threaded_irq(component->dev, rt5651->irq, NULL, + rt5651_irq, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, "rt5651", rt5651); + if (ret) { + dev_err(component->dev, "Failed to reguest IRQ: %d\n", ret); + return ret; + } + + /* sync initial jack state */ + queue_work(system_power_efficient_wq, &rt5651->jack_detect_work); + + return 0; +} + +/* + * Note on some platforms the platform code may need to add device-properties, + * rather then relying only on properties set by the firmware. Therefor the + * property parsing MUST be done from the component driver's probe function, + * rather then from the i2c driver's probe function, so that the platform-code + * can attach extra properties before calling snd_soc_register_card(). + */ +static void rt5651_apply_properties(struct snd_soc_component *component) +{ + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); + u32 val; + + if (device_property_read_bool(component->dev, "realtek,in2-differential")) + snd_soc_component_update_bits(component, RT5651_IN1_IN2, + RT5651_IN_DF2, RT5651_IN_DF2); + + if (device_property_read_bool(component->dev, "realtek,dmic-en")) + snd_soc_component_update_bits(component, RT5651_GPIO_CTRL1, + RT5651_GP2_PIN_MASK, RT5651_GP2_PIN_DMIC1_SCL); + + if (device_property_read_u32(component->dev, + "realtek,jack-detect-source", &val) == 0) + rt5651->jd_src = val; + + /* + * Testing on various boards has shown that good defaults for the OVCD + * threshold and scale-factor are 2000µA and 0.75. For an effective + * limit of 1500µA, this seems to be more reliable then 1500µA and 1.0. + */ + rt5651->ovcd_th = RT5651_MIC1_OVTH_2000UA; + rt5651->ovcd_sf = RT5651_MIC_OVCD_SF_0P75; + + if (device_property_read_u32(component->dev, + "realtek,over-current-threshold-microamp", &val) == 0) { + switch (val) { + case 600: + rt5651->ovcd_th = RT5651_MIC1_OVTH_600UA; + break; + case 1500: + rt5651->ovcd_th = RT5651_MIC1_OVTH_1500UA; + break; + case 2000: + rt5651->ovcd_th = RT5651_MIC1_OVTH_2000UA; + break; + default: + dev_warn(component->dev, "Warning: Invalid over-current-threshold-microamp value: %d, defaulting to 2000uA\n", + val); + } + } + + if (device_property_read_u32(component->dev, + "realtek,over-current-scale-factor", &val) == 0) { + if (val <= RT5651_OVCD_SF_1P5) + rt5651->ovcd_sf = val << RT5651_MIC_OVCD_SF_SFT; + else + dev_warn(component->dev, "Warning: Invalid over-current-scale-factor value: %d, defaulting to 0.75\n", + val); + } +} + +static int rt5651_probe(struct snd_soc_component *component) +{ + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); + + rt5651->component = component; + + snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, + RT5651_PWR_LDO_DVO_MASK, RT5651_PWR_LDO_DVO_1_2V); + + snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF); + + rt5651_apply_properties(component); + return 0; } #ifdef CONFIG_PM -static int rt5651_suspend(struct snd_soc_codec *codec) +static int rt5651_suspend(struct snd_soc_component *component) { - struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); regcache_cache_only(rt5651->regmap, true); regcache_mark_dirty(rt5651->regmap); return 0; } -static int rt5651_resume(struct snd_soc_codec *codec) +static int rt5651_resume(struct snd_soc_component *component) { - struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); + struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); regcache_cache_only(rt5651->regmap, false); - snd_soc_cache_sync(codec); + snd_soc_component_cache_sync(component); return 0; } @@ -1692,20 +1936,21 @@ static struct snd_soc_dai_driver rt5651_dai[] = { }, }; -static const struct snd_soc_codec_driver soc_codec_dev_rt5651 = { - .probe = rt5651_probe, - .suspend = rt5651_suspend, - .resume = rt5651_resume, - .set_bias_level = rt5651_set_bias_level, - .idle_bias_off = true, - .component_driver = { - .controls = rt5651_snd_controls, - .num_controls = ARRAY_SIZE(rt5651_snd_controls), - .dapm_widgets = rt5651_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(rt5651_dapm_widgets), - .dapm_routes = rt5651_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(rt5651_dapm_routes), - }, +static const struct snd_soc_component_driver soc_component_dev_rt5651 = { + .probe = rt5651_probe, + .suspend = rt5651_suspend, + .resume = rt5651_resume, + .set_bias_level = rt5651_set_bias_level, + .set_jack = rt5651_set_jack, + .controls = rt5651_snd_controls, + .num_controls = ARRAY_SIZE(rt5651_snd_controls), + .dapm_widgets = rt5651_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rt5651_dapm_widgets), + .dapm_routes = rt5651_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(rt5651_dapm_routes), + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static const struct regmap_config rt5651_regmap = { @@ -1722,6 +1967,7 @@ static const struct regmap_config rt5651_regmap = { .num_reg_defaults = ARRAY_SIZE(rt5651_reg), .ranges = rt5651_ranges, .num_ranges = ARRAY_SIZE(rt5651_ranges), + .use_single_rw = true, }; #if defined(CONFIG_OF) @@ -1746,135 +1992,13 @@ static const struct i2c_device_id rt5651_i2c_id[] = { }; MODULE_DEVICE_TABLE(i2c, rt5651_i2c_id); -static int rt5651_quirk_cb(const struct dmi_system_id *id) -{ - rt5651_quirk = (unsigned long) id->driver_data; - return 1; -} - -static const struct dmi_system_id rt5651_quirk_table[] = { - { - .callback = rt5651_quirk_cb, - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "KIANO"), - DMI_MATCH(DMI_PRODUCT_NAME, "KIANO SlimNote 14.2"), - }, - .driver_data = (unsigned long *) RT5651_JD1_1, - }, - {} -}; - -static int rt5651_parse_dt(struct rt5651_priv *rt5651, struct device_node *np) -{ - if (of_property_read_bool(np, "realtek,in2-differential")) - rt5651_quirk |= RT5651_IN2_DIFF; - if (of_property_read_bool(np, "realtek,dmic-en")) - rt5651_quirk |= RT5651_DMIC_EN; - - return 0; -} - -static void rt5651_set_pdata(struct rt5651_priv *rt5651) -{ - if (rt5651_quirk & RT5651_IN2_DIFF) - rt5651->pdata.in2_diff = true; - if (rt5651_quirk & RT5651_DMIC_EN) - rt5651->pdata.dmic_en = true; - if (RT5651_JD_MAP(rt5651_quirk)) - rt5651->pdata.jd_src = RT5651_JD_MAP(rt5651_quirk); -} - -static irqreturn_t rt5651_irq(int irq, void *data) -{ - struct rt5651_priv *rt5651 = data; - - queue_delayed_work(system_power_efficient_wq, - &rt5651->jack_detect_work, msecs_to_jiffies(250)); - - return IRQ_HANDLED; -} - -static int rt5651_jack_detect(struct snd_soc_codec *codec, int jack_insert) -{ - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - int jack_type; - - if (jack_insert) { - snd_soc_dapm_force_enable_pin(dapm, "LDO"); - snd_soc_dapm_sync(dapm); - - snd_soc_update_bits(codec, RT5651_MICBIAS, - RT5651_MIC1_OVCD_MASK | - RT5651_MIC1_OVTH_MASK | - RT5651_PWR_CLK12M_MASK | - RT5651_PWR_MB_MASK, - RT5651_MIC1_OVCD_EN | - RT5651_MIC1_OVTH_600UA | - RT5651_PWR_MB_PU | - RT5651_PWR_CLK12M_PU); - msleep(100); - if (snd_soc_read(codec, RT5651_IRQ_CTRL2) & RT5651_MB1_OC_CLR) - jack_type = SND_JACK_HEADPHONE; - else - jack_type = SND_JACK_HEADSET; - snd_soc_update_bits(codec, RT5651_IRQ_CTRL2, - RT5651_MB1_OC_CLR, 0); - } else { /* jack out */ - jack_type = 0; - - snd_soc_update_bits(codec, RT5651_MICBIAS, - RT5651_MIC1_OVCD_MASK, - RT5651_MIC1_OVCD_DIS); - } - - return jack_type; -} - -static void rt5651_jack_detect_work(struct work_struct *work) -{ - struct rt5651_priv *rt5651 = - container_of(work, struct rt5651_priv, jack_detect_work.work); - - int report, val = 0; - - if (!rt5651->codec) - return; - - switch (rt5651->pdata.jd_src) { - case RT5651_JD1_1: - val = snd_soc_read(rt5651->codec, RT5651_INT_IRQ_ST) & 0x1000; - break; - case RT5651_JD1_2: - val = snd_soc_read(rt5651->codec, RT5651_INT_IRQ_ST) & 0x2000; - break; - case RT5651_JD2: - val = snd_soc_read(rt5651->codec, RT5651_INT_IRQ_ST) & 0x4000; - break; - default: - break; - } - - report = rt5651_jack_detect(rt5651->codec, !val); - - snd_soc_jack_report(rt5651->hp_jack, report, SND_JACK_HEADSET); -} - -int rt5651_set_jack_detect(struct snd_soc_codec *codec, - struct snd_soc_jack *hp_jack) -{ - struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); - - rt5651->hp_jack = hp_jack; - rt5651_irq(0, rt5651); - - return 0; -} -EXPORT_SYMBOL_GPL(rt5651_set_jack_detect); - +/* + * Note this function MUST not look at device-properties, see the comment + * above rt5651_apply_properties(). + */ static int rt5651_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { - struct rt5651_platform_data *pdata = dev_get_platdata(&i2c->dev); struct rt5651_priv *rt5651; int ret; @@ -1885,15 +2009,6 @@ static int rt5651_i2c_probe(struct i2c_client *i2c, i2c_set_clientdata(i2c, rt5651); - if (pdata) - rt5651->pdata = *pdata; - else if (i2c->dev.of_node) - rt5651_parse_dt(rt5651, i2c->dev.of_node); - else - dmi_check_system(rt5651_quirk_table); - - rt5651_set_pdata(rt5651); - rt5651->regmap = devm_regmap_init_i2c(i2c, &rt5651_regmap); if (IS_ERR(rt5651->regmap)) { ret = PTR_ERR(rt5651->regmap); @@ -1916,70 +2031,13 @@ static int rt5651_i2c_probe(struct i2c_client *i2c, if (ret != 0) dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); - if (rt5651->pdata.in2_diff) - regmap_update_bits(rt5651->regmap, RT5651_IN1_IN2, - RT5651_IN_DF2, RT5651_IN_DF2); - - if (rt5651->pdata.dmic_en) - regmap_update_bits(rt5651->regmap, RT5651_GPIO_CTRL1, - RT5651_GP2_PIN_MASK, RT5651_GP2_PIN_DMIC1_SCL); - + rt5651->irq = i2c->irq; rt5651->hp_mute = 1; - if (rt5651->pdata.jd_src) { - - /* IRQ output on GPIO1 */ - regmap_update_bits(rt5651->regmap, RT5651_GPIO_CTRL1, - RT5651_GP1_PIN_MASK, RT5651_GP1_PIN_IRQ); - - switch (rt5651->pdata.jd_src) { - case RT5651_JD1_1: - regmap_update_bits(rt5651->regmap, RT5651_JD_CTRL2, - RT5651_JD_TRG_SEL_MASK, - RT5651_JD_TRG_SEL_JD1_1); - regmap_update_bits(rt5651->regmap, RT5651_IRQ_CTRL1, - RT5651_JD1_1_IRQ_EN, - RT5651_JD1_1_IRQ_EN); - break; - case RT5651_JD1_2: - regmap_update_bits(rt5651->regmap, RT5651_JD_CTRL2, - RT5651_JD_TRG_SEL_MASK, - RT5651_JD_TRG_SEL_JD1_2); - regmap_update_bits(rt5651->regmap, RT5651_IRQ_CTRL1, - RT5651_JD1_2_IRQ_EN, - RT5651_JD1_2_IRQ_EN); - break; - case RT5651_JD2: - regmap_update_bits(rt5651->regmap, RT5651_JD_CTRL2, - RT5651_JD_TRG_SEL_MASK, - RT5651_JD_TRG_SEL_JD2); - regmap_update_bits(rt5651->regmap, RT5651_IRQ_CTRL1, - RT5651_JD2_IRQ_EN, - RT5651_JD2_IRQ_EN); - break; - case RT5651_JD_NULL: - break; - default: - dev_warn(&i2c->dev, "Currently only JD1_1 / JD1_2 / JD2 are supported\n"); - break; - } - } - - INIT_DELAYED_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work); - - if (i2c->irq) { - ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, - rt5651_irq, - IRQF_TRIGGER_RISING | - IRQF_TRIGGER_FALLING | - IRQF_ONESHOT, "rt5651", rt5651); - if (ret) { - dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); - return ret; - } - } + INIT_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work); - ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5651, + ret = devm_snd_soc_register_component(&i2c->dev, + &soc_component_dev_rt5651, rt5651_dai, ARRAY_SIZE(rt5651_dai)); return ret; @@ -1989,8 +2047,7 @@ static int rt5651_i2c_remove(struct i2c_client *i2c) { struct rt5651_priv *rt5651 = i2c_get_clientdata(i2c); - cancel_delayed_work_sync(&rt5651->jack_detect_work); - snd_soc_unregister_codec(&i2c->dev); + cancel_work_sync(&rt5651->jack_detect_work); return 0; } diff --git a/sound/soc/codecs/rt5651.h b/sound/soc/codecs/rt5651.h index 4f8b202121d7..f20c9be94fb2 100644 --- a/sound/soc/codecs/rt5651.h +++ b/sound/soc/codecs/rt5651.h @@ -138,6 +138,7 @@ /* Index of Codec Private Register definition */ #define RT5651_BIAS_CUR1 0x12 #define RT5651_BIAS_CUR3 0x14 +#define RT5651_BIAS_CUR4 0x15 #define RT5651_CLSD_INT_REG1 0x1c #define RT5651_CHPUMP_INT_REG1 0x24 #define RT5651_MAMP_INT_REG2 0x37 @@ -1966,6 +1967,15 @@ #define RT5651_D_GATE_EN_SFT 0 /* Codec Private Register definition */ + +/* MIC Over current threshold scale factor (0x15) */ +#define RT5651_MIC_OVCD_SF_MASK (0x3 << 8) +#define RT5651_MIC_OVCD_SF_SFT 8 +#define RT5651_MIC_OVCD_SF_0P5 (0x0 << 8) +#define RT5651_MIC_OVCD_SF_0P75 (0x1 << 8) +#define RT5651_MIC_OVCD_SF_1P0 (0x2 << 8) +#define RT5651_MIC_OVCD_SF_1P5 (0x3 << 8) + /* 3D Speaker Control (0x63) */ #define RT5651_3D_SPK_MASK (0x1 << 15) #define RT5651_3D_SPK_SFT 15 @@ -2059,12 +2069,15 @@ struct rt5651_pll_code { }; struct rt5651_priv { - struct snd_soc_codec *codec; - struct rt5651_platform_data pdata; + struct snd_soc_component *component; struct regmap *regmap; struct snd_soc_jack *hp_jack; - struct delayed_work jack_detect_work; + struct work_struct jack_detect_work; + enum rt5651_jd_src jd_src; + unsigned int ovcd_th; + unsigned int ovcd_sf; + int irq; int sysclk; int sysclk_src; int lrck[RT5651_AIFS]; @@ -2079,6 +2092,4 @@ struct rt5651_priv { bool hp_mute; }; -int rt5651_set_jack_detect(struct snd_soc_codec *codec, - struct snd_soc_jack *hp_jack); #endif /* __RT5651_H__ */ diff --git a/sound/soc/codecs/rt5659.c b/sound/soc/codecs/rt5659.c index 07e7757417bc..ebadc3da0aaf 100644 --- a/sound/soc/codecs/rt5659.c +++ b/sound/soc/codecs/rt5659.c @@ -2500,9 +2500,9 @@ static const struct snd_soc_dapm_widget rt5659_dapm_widgets[] = { RT5659_PWR_ADC_L1_BIT, 0, NULL, 0), SND_SOC_DAPM_SUPPLY("ADC1 R Power", RT5659_PWR_DIG_1, RT5659_PWR_ADC_R1_BIT, 0, NULL, 0), - SND_SOC_DAPM_SUPPLY("ADC2 L Power", RT5659_PWR_DIG_2, + SND_SOC_DAPM_SUPPLY("ADC2 L Power", RT5659_PWR_DIG_1, RT5659_PWR_ADC_L2_BIT, 0, NULL, 0), - SND_SOC_DAPM_SUPPLY("ADC2 R Power", RT5659_PWR_DIG_2, + SND_SOC_DAPM_SUPPLY("ADC2 R Power", RT5659_PWR_DIG_1, RT5659_PWR_ADC_R2_BIT, 0, NULL, 0), SND_SOC_DAPM_SUPPLY("ADC1 clock", SND_SOC_NOPM, 0, 0, set_adc_clk, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), diff --git a/sound/soc/codecs/rt5659.h b/sound/soc/codecs/rt5659.h index 8f1aeef08489..3ae2d74861ef 100644 --- a/sound/soc/codecs/rt5659.h +++ b/sound/soc/codecs/rt5659.h @@ -1008,7 +1008,7 @@ #define RT5659_PWR_ADC_R1 (0x1 << 3) #define RT5659_PWR_ADC_R1_BIT 3 #define RT5659_PWR_ADC_L2 (0x1 << 2) -#define RT5659_PWR_ADC_L2_BIT 4 +#define RT5659_PWR_ADC_L2_BIT 2 #define RT5659_PWR_ADC_R2 (0x1 << 1) #define RT5659_PWR_ADC_R2_BIT 1 #define RT5659_PWR_CLS_D (0x1) diff --git a/sound/soc/codecs/rt5663.c b/sound/soc/codecs/rt5663.c index d329bf719d80..20c0aeea6ca3 100644 --- a/sound/soc/codecs/rt5663.c +++ b/sound/soc/codecs/rt5663.c @@ -49,7 +49,7 @@ struct impedance_mapping_table { }; struct rt5663_priv { - struct snd_soc_codec *codec; + struct snd_soc_component *component; struct rt5663_platform_data pdata; struct regmap *regmap; struct delayed_work jack_detect_work, jd_unplug_work; @@ -1384,57 +1384,57 @@ static const char * const rt5663_if1_adc_data_select[] = { static SOC_ENUM_SINGLE_DECL(rt5663_if1_adc_enum, RT5663_TDM_2, RT5663_DATA_SWAP_ADCDAT1_SHIFT, rt5663_if1_adc_data_select); -static void rt5663_enable_push_button_irq(struct snd_soc_codec *codec, +static void rt5663_enable_push_button_irq(struct snd_soc_component *component, bool enable) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); if (enable) { - snd_soc_update_bits(codec, RT5663_IL_CMD_6, + snd_soc_component_update_bits(component, RT5663_IL_CMD_6, RT5663_EN_4BTN_INL_MASK, RT5663_EN_4BTN_INL_EN); /* reset in-line command */ - snd_soc_update_bits(codec, RT5663_IL_CMD_6, + snd_soc_component_update_bits(component, RT5663_IL_CMD_6, RT5663_RESET_4BTN_INL_MASK, RT5663_RESET_4BTN_INL_RESET); - snd_soc_update_bits(codec, RT5663_IL_CMD_6, + snd_soc_component_update_bits(component, RT5663_IL_CMD_6, RT5663_RESET_4BTN_INL_MASK, RT5663_RESET_4BTN_INL_NOR); switch (rt5663->codec_ver) { case CODEC_VER_1: - snd_soc_update_bits(codec, RT5663_IRQ_3, + snd_soc_component_update_bits(component, RT5663_IRQ_3, RT5663_V2_EN_IRQ_INLINE_MASK, RT5663_V2_EN_IRQ_INLINE_NOR); break; case CODEC_VER_0: - snd_soc_update_bits(codec, RT5663_IRQ_2, + snd_soc_component_update_bits(component, RT5663_IRQ_2, RT5663_EN_IRQ_INLINE_MASK, RT5663_EN_IRQ_INLINE_NOR); break; default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); } } else { switch (rt5663->codec_ver) { case CODEC_VER_1: - snd_soc_update_bits(codec, RT5663_IRQ_3, + snd_soc_component_update_bits(component, RT5663_IRQ_3, RT5663_V2_EN_IRQ_INLINE_MASK, RT5663_V2_EN_IRQ_INLINE_BYP); break; case CODEC_VER_0: - snd_soc_update_bits(codec, RT5663_IRQ_2, + snd_soc_component_update_bits(component, RT5663_IRQ_2, RT5663_EN_IRQ_INLINE_MASK, RT5663_EN_IRQ_INLINE_BYP); break; default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); } - snd_soc_update_bits(codec, RT5663_IL_CMD_6, + snd_soc_component_update_bits(component, RT5663_IL_CMD_6, RT5663_EN_4BTN_INL_MASK, RT5663_EN_4BTN_INL_DIS); /* reset in-line command */ - snd_soc_update_bits(codec, RT5663_IL_CMD_6, + snd_soc_component_update_bits(component, RT5663_IL_CMD_6, RT5663_RESET_4BTN_INL_MASK, RT5663_RESET_4BTN_INL_RESET); - snd_soc_update_bits(codec, RT5663_IL_CMD_6, + snd_soc_component_update_bits(component, RT5663_IL_CMD_6, RT5663_RESET_4BTN_INL_MASK, RT5663_RESET_4BTN_INL_NOR); } @@ -1442,7 +1442,7 @@ static void rt5663_enable_push_button_irq(struct snd_soc_codec *codec, /** * rt5663_v2_jack_detect - Detect headset. - * @codec: SoC audio codec device. + * @component: SoC audio component device. * @jack_insert: Jack insert or not. * * Detect whether is headset or not when jack inserted. @@ -1450,41 +1450,41 @@ static void rt5663_enable_push_button_irq(struct snd_soc_codec *codec, * Returns detect status. */ -static int rt5663_v2_jack_detect(struct snd_soc_codec *codec, int jack_insert) +static int rt5663_v2_jack_detect(struct snd_soc_component *component, int jack_insert) { - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); int val, i = 0, sleep_time[5] = {300, 150, 100, 50, 30}; - dev_dbg(codec->dev, "%s jack_insert:%d\n", __func__, jack_insert); + dev_dbg(component->dev, "%s jack_insert:%d\n", __func__, jack_insert); if (jack_insert) { - snd_soc_write(codec, RT5663_CBJ_TYPE_2, 0x8040); - snd_soc_write(codec, RT5663_CBJ_TYPE_3, 0x1484); + snd_soc_component_write(component, RT5663_CBJ_TYPE_2, 0x8040); + snd_soc_component_write(component, RT5663_CBJ_TYPE_3, 0x1484); snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); snd_soc_dapm_force_enable_pin(dapm, "MICBIAS2"); snd_soc_dapm_force_enable_pin(dapm, "Mic Det Power"); snd_soc_dapm_force_enable_pin(dapm, "CBJ Power"); snd_soc_dapm_sync(dapm); - snd_soc_update_bits(codec, RT5663_RC_CLK, + snd_soc_component_update_bits(component, RT5663_RC_CLK, RT5663_DIG_1M_CLK_MASK, RT5663_DIG_1M_CLK_EN); - snd_soc_update_bits(codec, RT5663_RECMIX, 0x8, 0x8); + snd_soc_component_update_bits(component, RT5663_RECMIX, 0x8, 0x8); while (i < 5) { msleep(sleep_time[i]); - val = snd_soc_read(codec, RT5663_CBJ_TYPE_2) & 0x0003; + val = snd_soc_component_read32(component, RT5663_CBJ_TYPE_2) & 0x0003; if (val == 0x1 || val == 0x2 || val == 0x3) break; - dev_dbg(codec->dev, "%s: MX-0011 val=%x sleep %d\n", + dev_dbg(component->dev, "%s: MX-0011 val=%x sleep %d\n", __func__, val, sleep_time[i]); i++; } - dev_dbg(codec->dev, "%s val = %d\n", __func__, val); + dev_dbg(component->dev, "%s val = %d\n", __func__, val); switch (val) { case 1: case 2: rt5663->jack_type = SND_JACK_HEADSET; - rt5663_enable_push_button_irq(codec, true); + rt5663_enable_push_button_irq(component, true); break; default: snd_soc_dapm_disable_pin(dapm, "MICBIAS1"); @@ -1496,10 +1496,10 @@ static int rt5663_v2_jack_detect(struct snd_soc_codec *codec, int jack_insert) break; } } else { - snd_soc_update_bits(codec, RT5663_RECMIX, 0x8, 0x0); + snd_soc_component_update_bits(component, RT5663_RECMIX, 0x8, 0x0); if (rt5663->jack_type == SND_JACK_HEADSET) { - rt5663_enable_push_button_irq(codec, false); + rt5663_enable_push_button_irq(component, false); snd_soc_dapm_disable_pin(dapm, "MICBIAS1"); snd_soc_dapm_disable_pin(dapm, "MICBIAS2"); snd_soc_dapm_disable_pin(dapm, "Mic Det Power"); @@ -1509,60 +1509,60 @@ static int rt5663_v2_jack_detect(struct snd_soc_codec *codec, int jack_insert) rt5663->jack_type = 0; } - dev_dbg(codec->dev, "jack_type = %d\n", rt5663->jack_type); + dev_dbg(component->dev, "jack_type = %d\n", rt5663->jack_type); return rt5663->jack_type; } /** * rt5663_jack_detect - Detect headset. - * @codec: SoC audio codec device. + * @component: SoC audio component device. * @jack_insert: Jack insert or not. * * Detect whether is headset or not when jack inserted. * * Returns detect status. */ -static int rt5663_jack_detect(struct snd_soc_codec *codec, int jack_insert) +static int rt5663_jack_detect(struct snd_soc_component *component, int jack_insert) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); int val, i = 0; - dev_dbg(codec->dev, "%s jack_insert:%d\n", __func__, jack_insert); + dev_dbg(component->dev, "%s jack_insert:%d\n", __func__, jack_insert); if (jack_insert) { - snd_soc_update_bits(codec, RT5663_DIG_MISC, + snd_soc_component_update_bits(component, RT5663_DIG_MISC, RT5663_DIG_GATE_CTRL_MASK, RT5663_DIG_GATE_CTRL_EN); - snd_soc_update_bits(codec, RT5663_HP_CHARGE_PUMP_1, + snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1, RT5663_SI_HP_MASK | RT5663_OSW_HP_L_MASK | RT5663_OSW_HP_R_MASK, RT5663_SI_HP_EN | RT5663_OSW_HP_L_DIS | RT5663_OSW_HP_R_DIS); - snd_soc_update_bits(codec, RT5663_DUMMY_1, + snd_soc_component_update_bits(component, RT5663_DUMMY_1, RT5663_EMB_CLK_MASK | RT5663_HPA_CPL_BIAS_MASK | RT5663_HPA_CPR_BIAS_MASK, RT5663_EMB_CLK_EN | RT5663_HPA_CPL_BIAS_1 | RT5663_HPA_CPR_BIAS_1); - snd_soc_update_bits(codec, RT5663_CBJ_1, + snd_soc_component_update_bits(component, RT5663_CBJ_1, RT5663_INBUF_CBJ_BST1_MASK | RT5663_CBJ_SENSE_BST1_MASK, RT5663_INBUF_CBJ_BST1_ON | RT5663_CBJ_SENSE_BST1_L); - snd_soc_update_bits(codec, RT5663_IL_CMD_2, + snd_soc_component_update_bits(component, RT5663_IL_CMD_2, RT5663_PWR_MIC_DET_MASK, RT5663_PWR_MIC_DET_ON); /* BST1 power on for JD */ - snd_soc_update_bits(codec, RT5663_PWR_ANLG_2, + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2, RT5663_PWR_BST1_MASK, RT5663_PWR_BST1_ON); - snd_soc_update_bits(codec, RT5663_EM_JACK_TYPE_1, + snd_soc_component_update_bits(component, RT5663_EM_JACK_TYPE_1, RT5663_CBJ_DET_MASK | RT5663_EXT_JD_MASK | RT5663_POL_EXT_JD_MASK, RT5663_CBJ_DET_EN | RT5663_EXT_JD_EN | RT5663_POL_EXT_JD_EN); - snd_soc_update_bits(codec, RT5663_PWR_ANLG_1, + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1, RT5663_PWR_MB_MASK | RT5663_LDO1_DVO_MASK | RT5663_AMP_HP_MASK, RT5663_PWR_MB | RT5663_LDO1_DVO_0_9V | RT5663_AMP_HP_3X); - snd_soc_update_bits(codec, RT5663_AUTO_1MRC_CLK, + snd_soc_component_update_bits(component, RT5663_AUTO_1MRC_CLK, RT5663_IRQ_POW_SAV_MASK, RT5663_IRQ_POW_SAV_EN); - snd_soc_update_bits(codec, RT5663_IRQ_1, + snd_soc_component_update_bits(component, RT5663_IRQ_1, RT5663_EN_IRQ_JD1_MASK, RT5663_EN_IRQ_JD1_EN); - snd_soc_update_bits(codec, RT5663_EM_JACK_TYPE_1, + snd_soc_component_update_bits(component, RT5663_EM_JACK_TYPE_1, RT5663_EM_JD_MASK, RT5663_EM_JD_RST); - snd_soc_update_bits(codec, RT5663_EM_JACK_TYPE_1, + snd_soc_component_update_bits(component, RT5663_EM_JACK_TYPE_1, RT5663_EM_JD_MASK, RT5663_EM_JD_NOR); while (true) { @@ -1577,10 +1577,10 @@ static int rt5663_jack_detect(struct snd_soc_codec *codec, int jack_insert) i++; } - val = snd_soc_read(codec, RT5663_EM_JACK_TYPE_2) & 0x0003; - dev_dbg(codec->dev, "%s val = %d\n", __func__, val); + val = snd_soc_component_read32(component, RT5663_EM_JACK_TYPE_2) & 0x0003; + dev_dbg(component->dev, "%s val = %d\n", __func__, val); - snd_soc_update_bits(codec, RT5663_HP_CHARGE_PUMP_1, + snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1, RT5663_OSW_HP_L_MASK | RT5663_OSW_HP_R_MASK, RT5663_OSW_HP_L_EN | RT5663_OSW_HP_R_EN); @@ -1588,7 +1588,7 @@ static int rt5663_jack_detect(struct snd_soc_codec *codec, int jack_insert) case 1: case 2: rt5663->jack_type = SND_JACK_HEADSET; - rt5663_enable_push_button_irq(codec, true); + rt5663_enable_push_button_irq(component, true); if (rt5663->pdata.impedance_sensing_num) break; @@ -1636,17 +1636,17 @@ static int rt5663_jack_detect(struct snd_soc_codec *codec, int jack_insert) } } else { if (rt5663->jack_type == SND_JACK_HEADSET) - rt5663_enable_push_button_irq(codec, false); + rt5663_enable_push_button_irq(component, false); rt5663->jack_type = 0; } - dev_dbg(codec->dev, "jack_type = %d\n", rt5663->jack_type); + dev_dbg(component->dev, "jack_type = %d\n", rt5663->jack_type); return rt5663->jack_type; } -static int rt5663_impedance_sensing(struct snd_soc_codec *codec) +static int rt5663_impedance_sensing(struct snd_soc_component *component) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); unsigned int value, i, reg84, reg26, reg2fa, reg91, reg10, reg80; for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) { @@ -1655,59 +1655,59 @@ static int rt5663_impedance_sensing(struct snd_soc_codec *codec) } if (rt5663->jack_type == SND_JACK_HEADSET) { - snd_soc_write(codec, RT5663_MIC_DECRO_2, + snd_soc_component_write(component, RT5663_MIC_DECRO_2, rt5663->imp_table[i].dc_offset_l_manual_mic >> 16); - snd_soc_write(codec, RT5663_MIC_DECRO_3, + snd_soc_component_write(component, RT5663_MIC_DECRO_3, rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff); - snd_soc_write(codec, RT5663_MIC_DECRO_5, + snd_soc_component_write(component, RT5663_MIC_DECRO_5, rt5663->imp_table[i].dc_offset_r_manual_mic >> 16); - snd_soc_write(codec, RT5663_MIC_DECRO_6, + snd_soc_component_write(component, RT5663_MIC_DECRO_6, rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff); } else { - snd_soc_write(codec, RT5663_MIC_DECRO_2, + snd_soc_component_write(component, RT5663_MIC_DECRO_2, rt5663->imp_table[i].dc_offset_l_manual >> 16); - snd_soc_write(codec, RT5663_MIC_DECRO_3, + snd_soc_component_write(component, RT5663_MIC_DECRO_3, rt5663->imp_table[i].dc_offset_l_manual & 0xffff); - snd_soc_write(codec, RT5663_MIC_DECRO_5, + snd_soc_component_write(component, RT5663_MIC_DECRO_5, rt5663->imp_table[i].dc_offset_r_manual >> 16); - snd_soc_write(codec, RT5663_MIC_DECRO_6, + snd_soc_component_write(component, RT5663_MIC_DECRO_6, rt5663->imp_table[i].dc_offset_r_manual & 0xffff); } - reg84 = snd_soc_read(codec, RT5663_ASRC_2); - reg26 = snd_soc_read(codec, RT5663_STO1_ADC_MIXER); - reg2fa = snd_soc_read(codec, RT5663_DUMMY_1); - reg91 = snd_soc_read(codec, RT5663_HP_CHARGE_PUMP_1); - reg10 = snd_soc_read(codec, RT5663_RECMIX); - reg80 = snd_soc_read(codec, RT5663_GLB_CLK); - - snd_soc_update_bits(codec, RT5663_STO_DRE_1, 0x8000, 0); - snd_soc_write(codec, RT5663_ASRC_2, 0); - snd_soc_write(codec, RT5663_STO1_ADC_MIXER, 0x4040); - snd_soc_update_bits(codec, RT5663_PWR_ANLG_1, + reg84 = snd_soc_component_read32(component, RT5663_ASRC_2); + reg26 = snd_soc_component_read32(component, RT5663_STO1_ADC_MIXER); + reg2fa = snd_soc_component_read32(component, RT5663_DUMMY_1); + reg91 = snd_soc_component_read32(component, RT5663_HP_CHARGE_PUMP_1); + reg10 = snd_soc_component_read32(component, RT5663_RECMIX); + reg80 = snd_soc_component_read32(component, RT5663_GLB_CLK); + + snd_soc_component_update_bits(component, RT5663_STO_DRE_1, 0x8000, 0); + snd_soc_component_write(component, RT5663_ASRC_2, 0); + snd_soc_component_write(component, RT5663_STO1_ADC_MIXER, 0x4040); + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1, RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK | RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK, RT5663_PWR_VREF1 | RT5663_PWR_VREF2); usleep_range(10000, 10005); - snd_soc_update_bits(codec, RT5663_PWR_ANLG_1, + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1, RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK, RT5663_PWR_FV1 | RT5663_PWR_FV2); - snd_soc_update_bits(codec, RT5663_GLB_CLK, RT5663_SCLK_SRC_MASK, + snd_soc_component_update_bits(component, RT5663_GLB_CLK, RT5663_SCLK_SRC_MASK, RT5663_SCLK_SRC_RCCLK); - snd_soc_update_bits(codec, RT5663_RC_CLK, RT5663_DIG_25M_CLK_MASK, + snd_soc_component_update_bits(component, RT5663_RC_CLK, RT5663_DIG_25M_CLK_MASK, RT5663_DIG_25M_CLK_EN); - snd_soc_update_bits(codec, RT5663_ADDA_CLK_1, RT5663_I2S_PD1_MASK, 0); - snd_soc_write(codec, RT5663_PRE_DIV_GATING_1, 0xff00); - snd_soc_write(codec, RT5663_PRE_DIV_GATING_2, 0xfffc); - snd_soc_write(codec, RT5663_HP_CHARGE_PUMP_1, 0x1232); - snd_soc_write(codec, RT5663_HP_LOGIC_2, 0x0005); - snd_soc_write(codec, RT5663_DEPOP_2, 0x3003); - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0030, 0x0030); - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0003, 0x0003); - snd_soc_update_bits(codec, RT5663_PWR_DIG_2, + snd_soc_component_update_bits(component, RT5663_ADDA_CLK_1, RT5663_I2S_PD1_MASK, 0); + snd_soc_component_write(component, RT5663_PRE_DIV_GATING_1, 0xff00); + snd_soc_component_write(component, RT5663_PRE_DIV_GATING_2, 0xfffc); + snd_soc_component_write(component, RT5663_HP_CHARGE_PUMP_1, 0x1232); + snd_soc_component_write(component, RT5663_HP_LOGIC_2, 0x0005); + snd_soc_component_write(component, RT5663_DEPOP_2, 0x3003); + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0030, 0x0030); + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0003, 0x0003); + snd_soc_component_update_bits(component, RT5663_PWR_DIG_2, RT5663_PWR_ADC_S1F | RT5663_PWR_DAC_S1F, RT5663_PWR_ADC_S1F | RT5663_PWR_DAC_S1F); - snd_soc_update_bits(codec, RT5663_PWR_DIG_1, + snd_soc_component_update_bits(component, RT5663_PWR_DIG_1, RT5663_PWR_DAC_L1 | RT5663_PWR_DAC_R1 | RT5663_PWR_LDO_DACREF_MASK | RT5663_PWR_ADC_L1 | RT5663_PWR_ADC_R1, @@ -1715,71 +1715,71 @@ static int rt5663_impedance_sensing(struct snd_soc_codec *codec) RT5663_PWR_LDO_DACREF_ON | RT5663_PWR_ADC_L1 | RT5663_PWR_ADC_R1); msleep(40); - snd_soc_update_bits(codec, RT5663_PWR_ANLG_2, + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2, RT5663_PWR_RECMIX1 | RT5663_PWR_RECMIX2, RT5663_PWR_RECMIX1 | RT5663_PWR_RECMIX2); msleep(30); - snd_soc_write(codec, RT5663_HP_CHARGE_PUMP_2, 0x1371); - snd_soc_write(codec, RT5663_STO_DAC_MIXER, 0); - snd_soc_write(codec, RT5663_BYPASS_STO_DAC, 0x000c); - snd_soc_write(codec, RT5663_HP_BIAS, 0xafaa); - snd_soc_write(codec, RT5663_CHARGE_PUMP_1, 0x2224); - snd_soc_write(codec, RT5663_HP_OUT_EN, 0x8088); - snd_soc_write(codec, RT5663_CHOP_ADC, 0x3000); - snd_soc_write(codec, RT5663_ADDA_RST, 0xc000); - snd_soc_write(codec, RT5663_STO1_HPF_ADJ1, 0x3320); - snd_soc_write(codec, RT5663_HP_CALIB_2, 0x00c9); - snd_soc_write(codec, RT5663_DUMMY_1, 0x004c); - snd_soc_write(codec, RT5663_ANA_BIAS_CUR_1, 0x7733); - snd_soc_write(codec, RT5663_CHARGE_PUMP_2, 0x7777); - snd_soc_write(codec, RT5663_STO_DRE_9, 0x0007); - snd_soc_write(codec, RT5663_STO_DRE_10, 0x0007); - snd_soc_write(codec, RT5663_DUMMY_2, 0x02a4); - snd_soc_write(codec, RT5663_RECMIX, 0x0005); - snd_soc_write(codec, RT5663_HP_IMP_SEN_1, 0x4334); - snd_soc_update_bits(codec, RT5663_IRQ_3, 0x0004, 0x0004); - snd_soc_write(codec, RT5663_HP_LOGIC_1, 0x2200); - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x3000, 0x3000); - snd_soc_write(codec, RT5663_HP_LOGIC_1, 0x6200); + snd_soc_component_write(component, RT5663_HP_CHARGE_PUMP_2, 0x1371); + snd_soc_component_write(component, RT5663_STO_DAC_MIXER, 0); + snd_soc_component_write(component, RT5663_BYPASS_STO_DAC, 0x000c); + snd_soc_component_write(component, RT5663_HP_BIAS, 0xafaa); + snd_soc_component_write(component, RT5663_CHARGE_PUMP_1, 0x2224); + snd_soc_component_write(component, RT5663_HP_OUT_EN, 0x8088); + snd_soc_component_write(component, RT5663_CHOP_ADC, 0x3000); + snd_soc_component_write(component, RT5663_ADDA_RST, 0xc000); + snd_soc_component_write(component, RT5663_STO1_HPF_ADJ1, 0x3320); + snd_soc_component_write(component, RT5663_HP_CALIB_2, 0x00c9); + snd_soc_component_write(component, RT5663_DUMMY_1, 0x004c); + snd_soc_component_write(component, RT5663_ANA_BIAS_CUR_1, 0x7733); + snd_soc_component_write(component, RT5663_CHARGE_PUMP_2, 0x7777); + snd_soc_component_write(component, RT5663_STO_DRE_9, 0x0007); + snd_soc_component_write(component, RT5663_STO_DRE_10, 0x0007); + snd_soc_component_write(component, RT5663_DUMMY_2, 0x02a4); + snd_soc_component_write(component, RT5663_RECMIX, 0x0005); + snd_soc_component_write(component, RT5663_HP_IMP_SEN_1, 0x4334); + snd_soc_component_update_bits(component, RT5663_IRQ_3, 0x0004, 0x0004); + snd_soc_component_write(component, RT5663_HP_LOGIC_1, 0x2200); + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x3000, 0x3000); + snd_soc_component_write(component, RT5663_HP_LOGIC_1, 0x6200); for (i = 0; i < 100; i++) { msleep(20); - if (snd_soc_read(codec, RT5663_INT_ST_1) & 0x2) + if (snd_soc_component_read32(component, RT5663_INT_ST_1) & 0x2) break; } - value = snd_soc_read(codec, RT5663_HP_IMP_SEN_4); + value = snd_soc_component_read32(component, RT5663_HP_IMP_SEN_4); - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x3000, 0); - snd_soc_write(codec, RT5663_INT_ST_1, 0); - snd_soc_write(codec, RT5663_HP_LOGIC_1, 0); - snd_soc_update_bits(codec, RT5663_RC_CLK, RT5663_DIG_25M_CLK_MASK, + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x3000, 0); + snd_soc_component_write(component, RT5663_INT_ST_1, 0); + snd_soc_component_write(component, RT5663_HP_LOGIC_1, 0); + snd_soc_component_update_bits(component, RT5663_RC_CLK, RT5663_DIG_25M_CLK_MASK, RT5663_DIG_25M_CLK_DIS); - snd_soc_write(codec, RT5663_GLB_CLK, reg80); - snd_soc_write(codec, RT5663_RECMIX, reg10); - snd_soc_write(codec, RT5663_DUMMY_2, 0x00a4); - snd_soc_write(codec, RT5663_DUMMY_1, reg2fa); - snd_soc_write(codec, RT5663_HP_CALIB_2, 0x00c8); - snd_soc_write(codec, RT5663_STO1_HPF_ADJ1, 0xb320); - snd_soc_write(codec, RT5663_ADDA_RST, 0xe400); - snd_soc_write(codec, RT5663_CHOP_ADC, 0x2000); - snd_soc_write(codec, RT5663_HP_OUT_EN, 0x0008); - snd_soc_update_bits(codec, RT5663_PWR_ANLG_2, + snd_soc_component_write(component, RT5663_GLB_CLK, reg80); + snd_soc_component_write(component, RT5663_RECMIX, reg10); + snd_soc_component_write(component, RT5663_DUMMY_2, 0x00a4); + snd_soc_component_write(component, RT5663_DUMMY_1, reg2fa); + snd_soc_component_write(component, RT5663_HP_CALIB_2, 0x00c8); + snd_soc_component_write(component, RT5663_STO1_HPF_ADJ1, 0xb320); + snd_soc_component_write(component, RT5663_ADDA_RST, 0xe400); + snd_soc_component_write(component, RT5663_CHOP_ADC, 0x2000); + snd_soc_component_write(component, RT5663_HP_OUT_EN, 0x0008); + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2, RT5663_PWR_RECMIX1 | RT5663_PWR_RECMIX2, 0); - snd_soc_update_bits(codec, RT5663_PWR_DIG_1, + snd_soc_component_update_bits(component, RT5663_PWR_DIG_1, RT5663_PWR_DAC_L1 | RT5663_PWR_DAC_R1 | RT5663_PWR_LDO_DACREF_MASK | RT5663_PWR_ADC_L1 | RT5663_PWR_ADC_R1, 0); - snd_soc_update_bits(codec, RT5663_PWR_DIG_2, + snd_soc_component_update_bits(component, RT5663_PWR_DIG_2, RT5663_PWR_ADC_S1F | RT5663_PWR_DAC_S1F, 0); - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0003, 0); - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0030, 0); - snd_soc_write(codec, RT5663_HP_LOGIC_2, 0); - snd_soc_write(codec, RT5663_HP_CHARGE_PUMP_1, reg91); - snd_soc_update_bits(codec, RT5663_PWR_ANLG_1, + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0003, 0); + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0030, 0); + snd_soc_component_write(component, RT5663_HP_LOGIC_2, 0); + snd_soc_component_write(component, RT5663_HP_CHARGE_PUMP_1, reg91); + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1, RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK, 0); - snd_soc_write(codec, RT5663_STO1_ADC_MIXER, reg26); - snd_soc_write(codec, RT5663_ASRC_2, reg84); + snd_soc_component_write(component, RT5663_STO1_ADC_MIXER, reg26); + snd_soc_component_write(component, RT5663_ASRC_2, reg84); for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) { if (value >= rt5663->imp_table[i].imp_min && @@ -1787,42 +1787,42 @@ static int rt5663_impedance_sensing(struct snd_soc_codec *codec) break; } - snd_soc_update_bits(codec, RT5663_STO_DRE_9, RT5663_DRE_GAIN_HP_MASK, + snd_soc_component_update_bits(component, RT5663_STO_DRE_9, RT5663_DRE_GAIN_HP_MASK, rt5663->imp_table[i].vol); - snd_soc_update_bits(codec, RT5663_STO_DRE_10, RT5663_DRE_GAIN_HP_MASK, + snd_soc_component_update_bits(component, RT5663_STO_DRE_10, RT5663_DRE_GAIN_HP_MASK, rt5663->imp_table[i].vol); if (rt5663->jack_type == SND_JACK_HEADSET) { - snd_soc_write(codec, RT5663_MIC_DECRO_2, + snd_soc_component_write(component, RT5663_MIC_DECRO_2, rt5663->imp_table[i].dc_offset_l_manual_mic >> 16); - snd_soc_write(codec, RT5663_MIC_DECRO_3, + snd_soc_component_write(component, RT5663_MIC_DECRO_3, rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff); - snd_soc_write(codec, RT5663_MIC_DECRO_5, + snd_soc_component_write(component, RT5663_MIC_DECRO_5, rt5663->imp_table[i].dc_offset_r_manual_mic >> 16); - snd_soc_write(codec, RT5663_MIC_DECRO_6, + snd_soc_component_write(component, RT5663_MIC_DECRO_6, rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff); } else { - snd_soc_write(codec, RT5663_MIC_DECRO_2, + snd_soc_component_write(component, RT5663_MIC_DECRO_2, rt5663->imp_table[i].dc_offset_l_manual >> 16); - snd_soc_write(codec, RT5663_MIC_DECRO_3, + snd_soc_component_write(component, RT5663_MIC_DECRO_3, rt5663->imp_table[i].dc_offset_l_manual & 0xffff); - snd_soc_write(codec, RT5663_MIC_DECRO_5, + snd_soc_component_write(component, RT5663_MIC_DECRO_5, rt5663->imp_table[i].dc_offset_r_manual >> 16); - snd_soc_write(codec, RT5663_MIC_DECRO_6, + snd_soc_component_write(component, RT5663_MIC_DECRO_6, rt5663->imp_table[i].dc_offset_r_manual & 0xffff); } return 0; } -static int rt5663_button_detect(struct snd_soc_codec *codec) +static int rt5663_button_detect(struct snd_soc_component *component) { int btn_type, val; - val = snd_soc_read(codec, RT5663_IL_CMD_5); - dev_dbg(codec->dev, "%s: val=0x%x\n", __func__, val); + val = snd_soc_component_read32(component, RT5663_IL_CMD_5); + dev_dbg(component->dev, "%s: val=0x%x\n", __func__, val); btn_type = val & 0xfff0; - snd_soc_write(codec, RT5663_IL_CMD_5, val); + snd_soc_component_write(component, RT5663_IL_CMD_5, val); return btn_type; } @@ -1840,10 +1840,10 @@ static irqreturn_t rt5663_irq(int irq, void *data) return IRQ_HANDLED; } -int rt5663_set_jack_detect(struct snd_soc_codec *codec, +int rt5663_set_jack_detect(struct snd_soc_component *component, struct snd_soc_jack *hs_jack) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); rt5663->hs_jack = hs_jack; @@ -1853,12 +1853,12 @@ int rt5663_set_jack_detect(struct snd_soc_codec *codec, } EXPORT_SYMBOL_GPL(rt5663_set_jack_detect); -static bool rt5663_check_jd_status(struct snd_soc_codec *codec) +static bool rt5663_check_jd_status(struct snd_soc_component *component) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); - int val = snd_soc_read(codec, RT5663_INT_ST_1); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); + int val = snd_soc_component_read32(component, RT5663_INT_ST_1); - dev_dbg(codec->dev, "%s val=%x\n", __func__, val); + dev_dbg(component->dev, "%s val=%x\n", __func__, val); /* JD1 */ switch (rt5663->codec_ver) { @@ -1867,7 +1867,7 @@ static bool rt5663_check_jd_status(struct snd_soc_codec *codec) case CODEC_VER_0: return !(val & 0x1000); default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); } return false; @@ -1877,28 +1877,28 @@ static void rt5663_jack_detect_work(struct work_struct *work) { struct rt5663_priv *rt5663 = container_of(work, struct rt5663_priv, jack_detect_work.work); - struct snd_soc_codec *codec = rt5663->codec; + struct snd_soc_component *component = rt5663->component; int btn_type, report = 0; - if (!codec) + if (!component) return; - if (rt5663_check_jd_status(codec)) { + if (rt5663_check_jd_status(component)) { /* jack in */ if (rt5663->jack_type == 0) { /* jack was out, report jack type */ switch (rt5663->codec_ver) { case CODEC_VER_1: report = rt5663_v2_jack_detect( - rt5663->codec, 1); + rt5663->component, 1); break; case CODEC_VER_0: - report = rt5663_jack_detect(rt5663->codec, 1); + report = rt5663_jack_detect(rt5663->component, 1); if (rt5663->pdata.impedance_sensing_num) - rt5663_impedance_sensing(rt5663->codec); + rt5663_impedance_sensing(rt5663->component); break; default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); } /* Delay the jack insert report to avoid pop noise */ @@ -1906,7 +1906,7 @@ static void rt5663_jack_detect_work(struct work_struct *work) } else { /* jack is already in, report button event */ report = SND_JACK_HEADSET; - btn_type = rt5663_button_detect(rt5663->codec); + btn_type = rt5663_button_detect(rt5663->component); /** * rt5663 can report three kinds of button behavior, * one click, double click and hold. However, @@ -1939,7 +1939,7 @@ static void rt5663_jack_detect_work(struct work_struct *work) break; default: btn_type = 0; - dev_err(rt5663->codec->dev, + dev_err(rt5663->component->dev, "Unexpected button code 0x%04x\n", btn_type); break; @@ -1959,16 +1959,16 @@ static void rt5663_jack_detect_work(struct work_struct *work) /* jack out */ switch (rt5663->codec_ver) { case CODEC_VER_1: - report = rt5663_v2_jack_detect(rt5663->codec, 0); + report = rt5663_v2_jack_detect(rt5663->component, 0); break; case CODEC_VER_0: - report = rt5663_jack_detect(rt5663->codec, 0); + report = rt5663_jack_detect(rt5663->component, 0); break; default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); } } - dev_dbg(codec->dev, "%s jack report: 0x%04x\n", __func__, report); + dev_dbg(component->dev, "%s jack report: 0x%04x\n", __func__, report); snd_soc_jack_report(rt5663->hs_jack, report, SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 | SND_JACK_BTN_3); @@ -1978,22 +1978,22 @@ static void rt5663_jd_unplug_work(struct work_struct *work) { struct rt5663_priv *rt5663 = container_of(work, struct rt5663_priv, jd_unplug_work.work); - struct snd_soc_codec *codec = rt5663->codec; + struct snd_soc_component *component = rt5663->component; - if (!codec) + if (!component) return; - if (!rt5663_check_jd_status(codec)) { + if (!rt5663_check_jd_status(component)) { /* jack out */ switch (rt5663->codec_ver) { case CODEC_VER_1: - rt5663_v2_jack_detect(rt5663->codec, 0); + rt5663_v2_jack_detect(rt5663->component, 0); break; case CODEC_VER_0: - rt5663_jack_detect(rt5663->codec, 0); + rt5663_jack_detect(rt5663->component, 0); break; default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); } snd_soc_jack_report(rt5663->hs_jack, 0, SND_JACK_HEADSET | @@ -2047,9 +2047,9 @@ static int rt5663_is_sys_clk_from_pll(struct snd_soc_dapm_widget *w, struct snd_soc_dapm_widget *sink) { unsigned int val; - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); - val = snd_soc_read(codec, RT5663_GLB_CLK); + val = snd_soc_component_read32(component, RT5663_GLB_CLK); val &= RT5663_SCLK_SRC_MASK; if (val == RT5663_SCLK_SRC_PLL1) return 1; @@ -2061,8 +2061,8 @@ static int rt5663_is_using_asrc(struct snd_soc_dapm_widget *w, struct snd_soc_dapm_widget *sink) { unsigned int reg, shift, val; - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); if (rt5663->codec_ver == CODEC_VER_1) { switch (w->shift) { @@ -2092,7 +2092,7 @@ static int rt5663_is_using_asrc(struct snd_soc_dapm_widget *w, } } - val = (snd_soc_read(codec, reg) >> shift) & 0x7; + val = (snd_soc_component_read32(component, reg) >> shift) & 0x7; if (val) return 1; @@ -2103,23 +2103,23 @@ static int rt5663_is_using_asrc(struct snd_soc_dapm_widget *w, static int rt5663_i2s_use_asrc(struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm); - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); int da_asrc_en, ad_asrc_en; - da_asrc_en = (snd_soc_read(codec, RT5663_ASRC_2) & + da_asrc_en = (snd_soc_component_read32(component, RT5663_ASRC_2) & RT5663_DA_STO1_TRACK_MASK) ? 1 : 0; switch (rt5663->codec_ver) { case CODEC_VER_1: - ad_asrc_en = (snd_soc_read(codec, RT5663_ASRC_3) & + ad_asrc_en = (snd_soc_component_read32(component, RT5663_ASRC_3) & RT5663_V2_AD_STO1_TRACK_MASK) ? 1 : 0; break; case CODEC_VER_0: - ad_asrc_en = (snd_soc_read(codec, RT5663_ASRC_2) & + ad_asrc_en = (snd_soc_component_read32(component, RT5663_ASRC_2) & RT5663_AD_STO1_TRACK_MASK) ? 1 : 0; break; default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); return 1; } @@ -2127,14 +2127,14 @@ static int rt5663_i2s_use_asrc(struct snd_soc_dapm_widget *source, if (rt5663->sysclk > rt5663->lrck * 384) return 1; - dev_err(codec->dev, "sysclk < 384 x fs, disable i2s asrc\n"); + dev_err(component->dev, "sysclk < 384 x fs, disable i2s asrc\n"); return 0; } /** * rt5663_sel_asrc_clk_src - select ASRC clock source for a set of filters - * @codec: SoC audio codec device. + * @component: SoC audio component device. * @filter_mask: mask of filters. * @clk_src: clock source * @@ -2146,10 +2146,10 @@ static int rt5663_i2s_use_asrc(struct snd_soc_dapm_widget *source, * set of filters specified by the mask. And the codec driver will turn on ASRC * for these filters if ASRC is selected as their clock source. */ -int rt5663_sel_asrc_clk_src(struct snd_soc_codec *codec, +int rt5663_sel_asrc_clk_src(struct snd_soc_component *component, unsigned int filter_mask, unsigned int clk_src) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); unsigned int asrc2_mask = 0; unsigned int asrc2_value = 0; unsigned int asrc3_mask = 0; @@ -2180,16 +2180,16 @@ int rt5663_sel_asrc_clk_src(struct snd_soc_codec *codec, asrc2_value |= clk_src << RT5663_AD_STO1_TRACK_SHIFT; break; default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); } } if (asrc2_mask) - snd_soc_update_bits(codec, RT5663_ASRC_2, asrc2_mask, + snd_soc_component_update_bits(component, RT5663_ASRC_2, asrc2_mask, asrc2_value); if (asrc3_mask) - snd_soc_update_bits(codec, RT5663_ASRC_3, asrc3_mask, + snd_soc_component_update_bits(component, RT5663_ASRC_3, asrc3_mask, asrc3_value); return 0; @@ -2295,42 +2295,42 @@ static const struct snd_kcontrol_new rt5663_alg_dacr_mux = static int rt5663_hp_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 rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_POST_PMU: if (rt5663->codec_ver == CODEC_VER_1) { - snd_soc_update_bits(codec, RT5663_HP_CHARGE_PUMP_1, + snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1, RT5663_SEL_PM_HP_SHIFT, RT5663_SEL_PM_HP_HIGH); - snd_soc_update_bits(codec, RT5663_HP_LOGIC_2, + snd_soc_component_update_bits(component, RT5663_HP_LOGIC_2, RT5663_HP_SIG_SRC1_MASK, RT5663_HP_SIG_SRC1_SILENCE); } else { - snd_soc_write(codec, RT5663_DEPOP_2, 0x3003); - snd_soc_update_bits(codec, RT5663_HP_CHARGE_PUMP_1, + snd_soc_component_write(component, RT5663_DEPOP_2, 0x3003); + snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1, RT5663_OVCD_HP_MASK, RT5663_OVCD_HP_DIS); - snd_soc_write(codec, RT5663_HP_CHARGE_PUMP_2, 0x1371); - snd_soc_write(codec, RT5663_HP_BIAS, 0xabba); - snd_soc_write(codec, RT5663_CHARGE_PUMP_1, 0x2224); - snd_soc_write(codec, RT5663_ANA_BIAS_CUR_1, 0x7766); - snd_soc_write(codec, RT5663_HP_BIAS, 0xafaa); - snd_soc_write(codec, RT5663_CHARGE_PUMP_2, 0x7777); - snd_soc_update_bits(codec, RT5663_STO_DRE_1, 0x8000, + snd_soc_component_write(component, RT5663_HP_CHARGE_PUMP_2, 0x1371); + snd_soc_component_write(component, RT5663_HP_BIAS, 0xabba); + snd_soc_component_write(component, RT5663_CHARGE_PUMP_1, 0x2224); + snd_soc_component_write(component, RT5663_ANA_BIAS_CUR_1, 0x7766); + snd_soc_component_write(component, RT5663_HP_BIAS, 0xafaa); + snd_soc_component_write(component, RT5663_CHARGE_PUMP_2, 0x7777); + snd_soc_component_update_bits(component, RT5663_STO_DRE_1, 0x8000, 0x8000); - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x3000, + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x3000, 0x3000); } break; case SND_SOC_DAPM_PRE_PMD: if (rt5663->codec_ver == CODEC_VER_1) { - snd_soc_update_bits(codec, RT5663_HP_LOGIC_2, + snd_soc_component_update_bits(component, RT5663_HP_LOGIC_2, RT5663_HP_SIG_SRC1_MASK, RT5663_HP_SIG_SRC1_REG); } else { - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x3000, 0x0); - snd_soc_update_bits(codec, RT5663_HP_CHARGE_PUMP_1, + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x3000, 0x0); + snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1, RT5663_OVCD_HP_MASK, RT5663_OVCD_HP_EN); } break; @@ -2345,23 +2345,23 @@ static int rt5663_hp_event(struct snd_soc_dapm_widget *w, static int rt5663_charge_pump_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 rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); switch (event) { case SND_SOC_DAPM_PRE_PMU: if (rt5663->codec_ver == CODEC_VER_0) { - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0030, + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0030, 0x0030); - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0003, + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0003, 0x0003); } break; case SND_SOC_DAPM_POST_PMD: if (rt5663->codec_ver == CODEC_VER_0) { - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0003, 0); - snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0030, 0); + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0003, 0); + snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0030, 0); } break; @@ -2375,17 +2375,17 @@ static int rt5663_charge_pump_event(struct snd_soc_dapm_widget *w, static int rt5663_bst2_power(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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_update_bits(codec, RT5663_PWR_ANLG_2, + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2, RT5663_PWR_BST2_MASK | RT5663_PWR_BST2_OP_MASK, RT5663_PWR_BST2 | RT5663_PWR_BST2_OP); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_update_bits(codec, RT5663_PWR_ANLG_2, + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2, RT5663_PWR_BST2_MASK | RT5663_PWR_BST2_OP_MASK, 0); break; @@ -2399,17 +2399,17 @@ static int rt5663_bst2_power(struct snd_soc_dapm_widget *w, static int rt5663_pre_div_power(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 snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_write(codec, RT5663_PRE_DIV_GATING_1, 0xff00); - snd_soc_write(codec, RT5663_PRE_DIV_GATING_2, 0xfffc); + snd_soc_component_write(component, RT5663_PRE_DIV_GATING_1, 0xff00); + snd_soc_component_write(component, RT5663_PRE_DIV_GATING_2, 0xfffc); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_write(codec, RT5663_PRE_DIV_GATING_1, 0x0000); - snd_soc_write(codec, RT5663_PRE_DIV_GATING_2, 0x0000); + snd_soc_component_write(component, RT5663_PRE_DIV_GATING_1, 0x0000); + snd_soc_component_write(component, RT5663_PRE_DIV_GATING_2, 0x0000); break; default: @@ -2731,8 +2731,8 @@ static const struct snd_soc_dapm_route rt5663_specific_dapm_routes[] = { static int rt5663_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 rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); unsigned int val_len = 0; int pre_div; @@ -2743,7 +2743,7 @@ static int rt5663_hw_params(struct snd_pcm_substream *substream, pre_div = rl6231_get_clk_info(rt5663->sysclk, rt5663->lrck); if (pre_div < 0) { - dev_err(codec->dev, "Unsupported clock setting %d for DAI %d\n", + dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n", rt5663->lrck, dai->id); return -EINVAL; } @@ -2767,10 +2767,10 @@ static int rt5663_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - snd_soc_update_bits(codec, RT5663_I2S1_SDP, + snd_soc_component_update_bits(component, RT5663_I2S1_SDP, RT5663_I2S_DL_MASK, val_len); - snd_soc_update_bits(codec, RT5663_ADDA_CLK_1, + snd_soc_component_update_bits(component, RT5663_ADDA_CLK_1, RT5663_I2S_PD1_MASK, pre_div << RT5663_I2S_PD1_SHIFT); return 0; @@ -2778,7 +2778,7 @@ static int rt5663_hw_params(struct snd_pcm_substream *substream, static int rt5663_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; unsigned int reg_val = 0; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { @@ -2817,7 +2817,7 @@ static int rt5663_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) return -EINVAL; } - snd_soc_update_bits(codec, RT5663_I2S1_SDP, RT5663_I2S_MS_MASK | + snd_soc_component_update_bits(component, RT5663_I2S1_SDP, RT5663_I2S_MS_MASK | RT5663_I2S_BP_MASK | RT5663_I2S_DF_MASK, reg_val); return 0; @@ -2826,8 +2826,8 @@ static int rt5663_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) static int rt5663_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { - struct snd_soc_codec *codec = dai->codec; - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); unsigned int reg_val = 0; if (freq == rt5663->sysclk && clk_id == rt5663->sysclk_src) @@ -2844,15 +2844,15 @@ static int rt5663_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, reg_val |= RT5663_SCLK_SRC_RCCLK; break; default: - dev_err(codec->dev, "Invalid clock id (%d)\n", clk_id); + dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); return -EINVAL; } - snd_soc_update_bits(codec, RT5663_GLB_CLK, RT5663_SCLK_SRC_MASK, + snd_soc_component_update_bits(component, RT5663_GLB_CLK, RT5663_SCLK_SRC_MASK, reg_val); rt5663->sysclk = freq; rt5663->sysclk_src = clk_id; - dev_dbg(codec->dev, "Sysclk is %dHz and clock id is %d\n", + dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); return 0; @@ -2861,8 +2861,8 @@ static int rt5663_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, static int rt5663_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, unsigned int freq_in, unsigned int freq_out) { - struct snd_soc_codec *codec = dai->codec; - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); struct rl6231_pll_code pll_code; int ret; int mask, shift, val; @@ -2872,11 +2872,11 @@ static int rt5663_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, return 0; if (!freq_in || !freq_out) { - dev_dbg(codec->dev, "PLL disabled\n"); + dev_dbg(component->dev, "PLL disabled\n"); rt5663->pll_in = 0; rt5663->pll_out = 0; - snd_soc_update_bits(codec, RT5663_GLB_CLK, + snd_soc_component_update_bits(component, RT5663_GLB_CLK, RT5663_SCLK_SRC_MASK, RT5663_SCLK_SRC_MCLK); return 0; } @@ -2891,7 +2891,7 @@ static int rt5663_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, shift = RT5663_PLL1_SRC_SHIFT; break; default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); return -EINVAL; } @@ -2903,24 +2903,24 @@ static int rt5663_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, val = 0x1; break; default: - dev_err(codec->dev, "Unknown PLL source %d\n", source); + dev_err(component->dev, "Unknown PLL source %d\n", source); return -EINVAL; } - snd_soc_update_bits(codec, RT5663_GLB_CLK, mask, (val << shift)); + snd_soc_component_update_bits(component, RT5663_GLB_CLK, mask, (val << shift)); ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); if (ret < 0) { - dev_err(codec->dev, "Unsupport input clock %d\n", freq_in); + dev_err(component->dev, "Unsupport input clock %d\n", freq_in); return ret; } - dev_dbg(codec->dev, "bypass=%d m=%d n=%d k=%d\n", pll_code.m_bp, + dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), pll_code.n_code, pll_code.k_code); - snd_soc_write(codec, RT5663_PLL_1, + snd_soc_component_write(component, RT5663_PLL_1, pll_code.n_code << RT5663_PLL_N_SHIFT | pll_code.k_code); - snd_soc_write(codec, RT5663_PLL_2, + snd_soc_component_write(component, RT5663_PLL_2, (pll_code.m_bp ? 0 : pll_code.m_code) << RT5663_PLL_M_SHIFT | pll_code.m_bp << RT5663_PLL_M_BP_SHIFT); @@ -2934,8 +2934,8 @@ static int rt5663_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, static int rt5663_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) { - struct snd_soc_codec *codec = dai->codec; - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); unsigned int val = 0, reg; if (rx_mask || tx_mask) @@ -2987,11 +2987,11 @@ static int rt5663_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, reg = RT5663_TDM_1; break; default: - dev_err(codec->dev, "Unknown CODEC Version\n"); + dev_err(component->dev, "Unknown CODEC Version\n"); return -EINVAL; } - snd_soc_update_bits(codec, reg, RT5663_TDM_MODE_MASK | + snd_soc_component_update_bits(component, reg, RT5663_TDM_MODE_MASK | RT5663_TDM_IN_CH_MASK | RT5663_TDM_OUT_CH_MASK | RT5663_TDM_IN_LEN_MASK | RT5663_TDM_OUT_LEN_MASK, val); @@ -3000,11 +3000,11 @@ static int rt5663_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, static int rt5663_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) { - struct snd_soc_codec *codec = dai->codec; - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); unsigned int reg; - dev_dbg(codec->dev, "%s ratio = %d\n", __func__, ratio); + dev_dbg(component->dev, "%s ratio = %d\n", __func__, ratio); if (rt5663->codec_ver == CODEC_VER_1) reg = RT5663_TDM_9; @@ -3013,51 +3013,51 @@ static int rt5663_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) switch (ratio) { case 32: - snd_soc_update_bits(codec, reg, + snd_soc_component_update_bits(component, reg, RT5663_TDM_LENGTN_MASK, RT5663_TDM_LENGTN_16); break; case 40: - snd_soc_update_bits(codec, reg, + snd_soc_component_update_bits(component, reg, RT5663_TDM_LENGTN_MASK, RT5663_TDM_LENGTN_20); break; case 48: - snd_soc_update_bits(codec, reg, + snd_soc_component_update_bits(component, reg, RT5663_TDM_LENGTN_MASK, RT5663_TDM_LENGTN_24); break; case 64: - snd_soc_update_bits(codec, reg, + snd_soc_component_update_bits(component, reg, RT5663_TDM_LENGTN_MASK, RT5663_TDM_LENGTN_32); break; default: - dev_err(codec->dev, "Invalid ratio!\n"); + dev_err(component->dev, "Invalid ratio!\n"); return -EINVAL; } return 0; } -static int rt5663_set_bias_level(struct snd_soc_codec *codec, +static int rt5663_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); switch (level) { case SND_SOC_BIAS_ON: - snd_soc_update_bits(codec, RT5663_PWR_ANLG_1, + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1, RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK, RT5663_PWR_FV1 | RT5663_PWR_FV2); break; case SND_SOC_BIAS_PREPARE: if (rt5663->codec_ver == CODEC_VER_1) { - snd_soc_update_bits(codec, RT5663_DIG_MISC, + snd_soc_component_update_bits(component, RT5663_DIG_MISC, RT5663_DIG_GATE_CTRL_MASK, RT5663_DIG_GATE_CTRL_EN); - snd_soc_update_bits(codec, RT5663_SIG_CLK_DET, + snd_soc_component_update_bits(component, RT5663_SIG_CLK_DET, RT5663_EN_ANA_CLK_DET_MASK | RT5663_PWR_CLK_DET_MASK, RT5663_EN_ANA_CLK_DET_AUTO | @@ -3067,17 +3067,17 @@ static int rt5663_set_bias_level(struct snd_soc_codec *codec, case SND_SOC_BIAS_STANDBY: if (rt5663->codec_ver == CODEC_VER_1) - snd_soc_update_bits(codec, RT5663_DIG_MISC, + snd_soc_component_update_bits(component, RT5663_DIG_MISC, RT5663_DIG_GATE_CTRL_MASK, RT5663_DIG_GATE_CTRL_DIS); - snd_soc_update_bits(codec, RT5663_PWR_ANLG_1, + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1, RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK | RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK | RT5663_PWR_MB_MASK, RT5663_PWR_VREF1 | RT5663_PWR_VREF2 | RT5663_PWR_MB); usleep_range(10000, 10005); if (rt5663->codec_ver == CODEC_VER_1) { - snd_soc_update_bits(codec, RT5663_SIG_CLK_DET, + snd_soc_component_update_bits(component, RT5663_SIG_CLK_DET, RT5663_EN_ANA_CLK_DET_MASK | RT5663_PWR_CLK_DET_MASK, RT5663_EN_ANA_CLK_DET_DIS | @@ -3086,7 +3086,7 @@ static int rt5663_set_bias_level(struct snd_soc_codec *codec, break; case SND_SOC_BIAS_OFF: - snd_soc_update_bits(codec, RT5663_PWR_ANLG_1, + snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1, RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK | RT5663_PWR_FV1 | RT5663_PWR_FV2, 0x0); break; @@ -3098,12 +3098,12 @@ static int rt5663_set_bias_level(struct snd_soc_codec *codec, return 0; } -static int rt5663_probe(struct snd_soc_codec *codec) +static int rt5663_probe(struct snd_soc_component *component) { - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); - rt5663->codec = codec; + rt5663->component = component; switch (rt5663->codec_ver) { case CODEC_VER_1: @@ -3113,7 +3113,7 @@ static int rt5663_probe(struct snd_soc_codec *codec) snd_soc_dapm_add_routes(dapm, rt5663_v2_specific_dapm_routes, ARRAY_SIZE(rt5663_v2_specific_dapm_routes)); - snd_soc_add_codec_controls(codec, rt5663_v2_specific_controls, + snd_soc_add_component_controls(component, rt5663_v2_specific_controls, ARRAY_SIZE(rt5663_v2_specific_controls)); break; case CODEC_VER_0: @@ -3123,11 +3123,11 @@ static int rt5663_probe(struct snd_soc_codec *codec) snd_soc_dapm_add_routes(dapm, rt5663_specific_dapm_routes, ARRAY_SIZE(rt5663_specific_dapm_routes)); - snd_soc_add_codec_controls(codec, rt5663_specific_controls, + snd_soc_add_component_controls(component, rt5663_specific_controls, ARRAY_SIZE(rt5663_specific_controls)); if (!rt5663->imp_table) - snd_soc_add_codec_controls(codec, rt5663_hpvol_controls, + snd_soc_add_component_controls(component, rt5663_hpvol_controls, ARRAY_SIZE(rt5663_hpvol_controls)); break; } @@ -3135,19 +3135,17 @@ static int rt5663_probe(struct snd_soc_codec *codec) return 0; } -static int rt5663_remove(struct snd_soc_codec *codec) +static void rt5663_remove(struct snd_soc_component *component) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); regmap_write(rt5663->regmap, RT5663_RESET, 0); - - return 0; } #ifdef CONFIG_PM -static int rt5663_suspend(struct snd_soc_codec *codec) +static int rt5663_suspend(struct snd_soc_component *component) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); regcache_cache_only(rt5663->regmap, true); regcache_mark_dirty(rt5663->regmap); @@ -3155,9 +3153,9 @@ static int rt5663_suspend(struct snd_soc_codec *codec) return 0; } -static int rt5663_resume(struct snd_soc_codec *codec) +static int rt5663_resume(struct snd_soc_component *component) { - struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec); + struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component); regcache_cache_only(rt5663->regmap, false); regcache_sync(rt5663->regmap); @@ -3206,21 +3204,22 @@ static struct snd_soc_dai_driver rt5663_dai[] = { }, }; -static const struct snd_soc_codec_driver soc_codec_dev_rt5663 = { - .probe = rt5663_probe, - .remove = rt5663_remove, - .suspend = rt5663_suspend, - .resume = rt5663_resume, - .set_bias_level = rt5663_set_bias_level, - .idle_bias_off = true, - .component_driver = { - .controls = rt5663_snd_controls, - .num_controls = ARRAY_SIZE(rt5663_snd_controls), - .dapm_widgets = rt5663_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(rt5663_dapm_widgets), - .dapm_routes = rt5663_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(rt5663_dapm_routes), - } +static const struct snd_soc_component_driver soc_component_dev_rt5663 = { + .probe = rt5663_probe, + .remove = rt5663_remove, + .suspend = rt5663_suspend, + .resume = rt5663_resume, + .set_bias_level = rt5663_set_bias_level, + .controls = rt5663_snd_controls, + .num_controls = ARRAY_SIZE(rt5663_snd_controls), + .dapm_widgets = rt5663_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rt5663_dapm_widgets), + .dapm_routes = rt5663_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(rt5663_dapm_routes), + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, + }; static const struct regmap_config rt5663_v2_regmap = { @@ -3610,7 +3609,8 @@ static int rt5663_i2c_probe(struct i2c_client *i2c, __func__, ret); } - ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5663, + ret = devm_snd_soc_register_component(&i2c->dev, + &soc_component_dev_rt5663, rt5663_dai, ARRAY_SIZE(rt5663_dai)); if (ret) { @@ -3628,8 +3628,6 @@ static int rt5663_i2c_remove(struct i2c_client *i2c) if (i2c->irq) free_irq(i2c->irq, rt5663); - snd_soc_unregister_codec(&i2c->dev); - return 0; } diff --git a/sound/soc/codecs/rt5663.h b/sound/soc/codecs/rt5663.h index 03adc8004ba9..865203cc2034 100644 --- a/sound/soc/codecs/rt5663.h +++ b/sound/soc/codecs/rt5663.h @@ -1125,9 +1125,9 @@ enum { RT5663_AD_STEREO_FILTER = 0x2, }; -int rt5663_set_jack_detect(struct snd_soc_codec *codec, +int rt5663_set_jack_detect(struct snd_soc_component *component, struct snd_soc_jack *hs_jack); -int rt5663_sel_asrc_clk_src(struct snd_soc_codec *codec, +int rt5663_sel_asrc_clk_src(struct snd_soc_component *component, unsigned int filter_mask, unsigned int clk_src); #endif /* __RT5663_H__ */ diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c index e1ab5537d27a..c5c76ab8ccf1 100644 --- a/sound/soc/codecs/sgtl5000.c +++ b/sound/soc/codecs/sgtl5000.c @@ -529,10 +529,15 @@ static const struct snd_kcontrol_new sgtl5000_snd_controls[] = { static int sgtl5000_digital_mute(struct snd_soc_dai *codec_dai, int mute) { struct snd_soc_codec *codec = codec_dai->codec; - u16 adcdac_ctrl = SGTL5000_DAC_MUTE_LEFT | SGTL5000_DAC_MUTE_RIGHT; + u16 i2s_pwr = SGTL5000_I2S_IN_POWERUP; - snd_soc_update_bits(codec, SGTL5000_CHIP_ADCDAC_CTRL, - adcdac_ctrl, mute ? adcdac_ctrl : 0); + /* + * During 'digital mute' do not mute DAC + * because LINE_IN would be muted aswell. We want to mute + * only I2S block - this can be done by powering it off + */ + snd_soc_update_bits(codec, SGTL5000_CHIP_DIG_POWER, + i2s_pwr, mute ? 0 : i2s_pwr); return 0; } @@ -871,15 +876,26 @@ static int sgtl5000_pcm_hw_params(struct snd_pcm_substream *substream, static int sgtl5000_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { + struct sgtl5000_priv *sgtl = snd_soc_codec_get_drvdata(codec); + int ret; + switch (level) { case SND_SOC_BIAS_ON: case SND_SOC_BIAS_PREPARE: case SND_SOC_BIAS_STANDBY: + regcache_cache_only(sgtl->regmap, false); + ret = regcache_sync(sgtl->regmap); + if (ret) { + regcache_cache_only(sgtl->regmap, true); + return ret; + } + snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER, SGTL5000_REFTOP_POWERUP, SGTL5000_REFTOP_POWERUP); break; case SND_SOC_BIAS_OFF: + regcache_cache_only(sgtl->regmap, true); snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER, SGTL5000_REFTOP_POWERUP, 0); break; @@ -1237,6 +1253,10 @@ static int sgtl5000_probe(struct snd_soc_codec *codec) */ snd_soc_write(codec, SGTL5000_DAP_CTRL, 0); + /* Unmute DAC after start */ + snd_soc_update_bits(codec, SGTL5000_CHIP_ADCDAC_CTRL, + SGTL5000_DAC_MUTE_LEFT | SGTL5000_DAC_MUTE_RIGHT, 0); + return 0; err: diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c index 9b341c23f62b..5e80867d09ef 100644 --- a/sound/soc/codecs/ssm2602.c +++ b/sound/soc/codecs/ssm2602.c @@ -54,10 +54,17 @@ struct ssm2602_priv { * using 2 wire for device control, so we cache them instead. * There is no point in caching the reset register */ -static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = { - 0x0097, 0x0097, 0x0079, 0x0079, - 0x000a, 0x0008, 0x009f, 0x000a, - 0x0000, 0x0000 +static const struct reg_default ssm2602_reg[SSM2602_CACHEREGNUM] = { + { .reg = 0x00, .def = 0x0097 }, + { .reg = 0x01, .def = 0x0097 }, + { .reg = 0x02, .def = 0x0079 }, + { .reg = 0x03, .def = 0x0079 }, + { .reg = 0x04, .def = 0x000a }, + { .reg = 0x05, .def = 0x0008 }, + { .reg = 0x06, .def = 0x009f }, + { .reg = 0x07, .def = 0x000a }, + { .reg = 0x08, .def = 0x0000 }, + { .reg = 0x09, .def = 0x0000 } }; @@ -620,8 +627,8 @@ const struct regmap_config ssm2602_regmap_config = { .volatile_reg = ssm2602_register_volatile, .cache_type = REGCACHE_RBTREE, - .reg_defaults_raw = ssm2602_reg, - .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg), + .reg_defaults = ssm2602_reg, + .num_reg_defaults = ARRAY_SIZE(ssm2602_reg), }; EXPORT_SYMBOL_GPL(ssm2602_regmap_config); diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c index fc066caa1918..a568050090ad 100644 --- a/sound/soc/codecs/wm5102.c +++ b/sound/soc/codecs/wm5102.c @@ -34,6 +34,8 @@ #include "wm5102.h" #include "wm_adsp.h" +#define DRV_NAME "wm5102-codec" + struct wm5102_priv { struct arizona_priv core; struct arizona_fll fll[2]; @@ -1910,7 +1912,8 @@ static struct snd_soc_dai_driver wm5102_dai[] = { static int wm5102_open(struct snd_compr_stream *stream) { struct snd_soc_pcm_runtime *rtd = stream->private_data; - struct wm5102_priv *priv = snd_soc_platform_get_drvdata(rtd->platform); + struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); + struct wm5102_priv *priv = snd_soc_component_get_drvdata(component); return wm_adsp_compr_open(&priv->core.adsp[0], stream); } @@ -1992,6 +1995,16 @@ static unsigned int wm5102_digital_vu[] = { ARIZONA_DAC_DIGITAL_VOLUME_5R, }; +static struct snd_compr_ops wm5102_compr_ops = { + .open = wm5102_open, + .free = wm_adsp_compr_free, + .set_params = wm_adsp_compr_set_params, + .get_caps = wm_adsp_compr_get_caps, + .trigger = wm_adsp_compr_trigger, + .pointer = wm_adsp_compr_pointer, + .copy = wm_adsp_compr_copy, +}; + static const struct snd_soc_codec_driver soc_codec_dev_wm5102 = { .probe = wm5102_codec_probe, .remove = wm5102_codec_remove, @@ -2002,6 +2015,8 @@ static const struct snd_soc_codec_driver soc_codec_dev_wm5102 = { .set_pll = wm5102_set_fll, .component_driver = { + .name = DRV_NAME, + .compr_ops = &wm5102_compr_ops, .controls = wm5102_snd_controls, .num_controls = ARRAY_SIZE(wm5102_snd_controls), .dapm_widgets = wm5102_dapm_widgets, @@ -2011,20 +2026,6 @@ static const struct snd_soc_codec_driver soc_codec_dev_wm5102 = { }, }; -static const struct snd_compr_ops wm5102_compr_ops = { - .open = wm5102_open, - .free = wm_adsp_compr_free, - .set_params = wm_adsp_compr_set_params, - .get_caps = wm_adsp_compr_get_caps, - .trigger = wm_adsp_compr_trigger, - .pointer = wm_adsp_compr_pointer, - .copy = wm_adsp_compr_copy, -}; - -static const struct snd_soc_platform_driver wm5102_compr_platform = { - .compr_ops = &wm5102_compr_ops, -}; - static int wm5102_probe(struct platform_device *pdev) { struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); @@ -2109,23 +2110,15 @@ static int wm5102_probe(struct platform_device *pdev) if (ret < 0) goto err_dsp_irq; - ret = snd_soc_register_platform(&pdev->dev, &wm5102_compr_platform); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to register platform: %d\n", ret); - goto err_spk_irqs; - } - ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm5102, wm5102_dai, ARRAY_SIZE(wm5102_dai)); if (ret < 0) { dev_err(&pdev->dev, "Failed to register codec: %d\n", ret); - goto err_platform; + goto err_spk_irqs; } return ret; -err_platform: - snd_soc_unregister_platform(&pdev->dev); err_spk_irqs: arizona_free_spk_irqs(arizona); err_dsp_irq: @@ -2139,7 +2132,6 @@ static int wm5102_remove(struct platform_device *pdev) struct wm5102_priv *wm5102 = platform_get_drvdata(pdev); struct arizona *arizona = wm5102->core.arizona; - snd_soc_unregister_platform(&pdev->dev); snd_soc_unregister_codec(&pdev->dev); pm_runtime_disable(&pdev->dev); diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c index fb0cf9c61f48..d5ece6c6fcb6 100644 --- a/sound/soc/codecs/wm5110.c +++ b/sound/soc/codecs/wm5110.c @@ -35,6 +35,8 @@ #define WM5110_NUM_ADSP 4 +#define DRV_NAME "wm5110-codec" + struct wm5110_priv { struct arizona_priv core; struct arizona_fll fll[2]; @@ -2229,7 +2231,8 @@ static struct snd_soc_dai_driver wm5110_dai[] = { static int wm5110_open(struct snd_compr_stream *stream) { struct snd_soc_pcm_runtime *rtd = stream->private_data; - struct wm5110_priv *priv = snd_soc_platform_get_drvdata(rtd->platform); + struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); + struct wm5110_priv *priv = snd_soc_component_get_drvdata(component); struct arizona *arizona = priv->core.arizona; int n_adsp; @@ -2346,6 +2349,16 @@ static unsigned int wm5110_digital_vu[] = { ARIZONA_DAC_DIGITAL_VOLUME_6R, }; +static struct snd_compr_ops wm5110_compr_ops = { + .open = wm5110_open, + .free = wm_adsp_compr_free, + .set_params = wm_adsp_compr_set_params, + .get_caps = wm_adsp_compr_get_caps, + .trigger = wm_adsp_compr_trigger, + .pointer = wm_adsp_compr_pointer, + .copy = wm_adsp_compr_copy, +}; + static const struct snd_soc_codec_driver soc_codec_dev_wm5110 = { .probe = wm5110_codec_probe, .remove = wm5110_codec_remove, @@ -2356,6 +2369,8 @@ static const struct snd_soc_codec_driver soc_codec_dev_wm5110 = { .set_pll = wm5110_set_fll, .component_driver = { + .name = DRV_NAME, + .compr_ops = &wm5110_compr_ops, .controls = wm5110_snd_controls, .num_controls = ARRAY_SIZE(wm5110_snd_controls), .dapm_widgets = wm5110_dapm_widgets, @@ -2365,20 +2380,6 @@ static const struct snd_soc_codec_driver soc_codec_dev_wm5110 = { }, }; -static const struct snd_compr_ops wm5110_compr_ops = { - .open = wm5110_open, - .free = wm_adsp_compr_free, - .set_params = wm_adsp_compr_set_params, - .get_caps = wm_adsp_compr_get_caps, - .trigger = wm_adsp_compr_trigger, - .pointer = wm_adsp_compr_pointer, - .copy = wm_adsp_compr_copy, -}; - -static const struct snd_soc_platform_driver wm5110_compr_platform = { - .compr_ops = &wm5110_compr_ops, -}; - static int wm5110_probe(struct platform_device *pdev) { struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); @@ -2464,23 +2465,15 @@ static int wm5110_probe(struct platform_device *pdev) if (ret < 0) goto err_dsp_irq; - ret = snd_soc_register_platform(&pdev->dev, &wm5110_compr_platform); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to register platform: %d\n", ret); - goto err_spk_irqs; - } - ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm5110, wm5110_dai, ARRAY_SIZE(wm5110_dai)); if (ret < 0) { dev_err(&pdev->dev, "Failed to register codec: %d\n", ret); - goto err_platform; + goto err_spk_irqs; } return ret; -err_platform: - snd_soc_unregister_platform(&pdev->dev); err_spk_irqs: arizona_free_spk_irqs(arizona); err_dsp_irq: @@ -2495,7 +2488,6 @@ static int wm5110_remove(struct platform_device *pdev) struct arizona *arizona = wm5110->core.arizona; int i; - snd_soc_unregister_platform(&pdev->dev); snd_soc_unregister_codec(&pdev->dev); pm_runtime_disable(&pdev->dev); diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c index 66e32f5d2917..989d093abda7 100644 --- a/sound/soc/codecs/wm_adsp.c +++ b/sound/soc/codecs/wm_adsp.c @@ -1204,12 +1204,14 @@ static int wmfw_add_ctl(struct wm_adsp *dsp, struct wm_coeff_ctl *ctl) kcontrol->put = wm_coeff_put_acked; break; default: - kcontrol->get = wm_coeff_get; - kcontrol->put = wm_coeff_put; - - ctl->bytes_ext.max = ctl->len; - ctl->bytes_ext.get = wm_coeff_tlv_get; - ctl->bytes_ext.put = wm_coeff_tlv_put; + if (kcontrol->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { + ctl->bytes_ext.max = ctl->len; + ctl->bytes_ext.get = wm_coeff_tlv_get; + ctl->bytes_ext.put = wm_coeff_tlv_put; + } else { + kcontrol->get = wm_coeff_get; + kcontrol->put = wm_coeff_put; + } break; } |