diff options
Diffstat (limited to 'sound/soc/codecs/rt5514.c')
-rw-r--r-- | sound/soc/codecs/rt5514.c | 128 |
1 files changed, 60 insertions, 68 deletions
diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index 198df016802f..e8a66b03faab 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -327,14 +327,13 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol, { struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); - struct snd_soc_codec *codec = rt5514->codec; const struct firmware *fw = NULL; u8 buf[8]; if (ucontrol->value.integer.value[0] == rt5514->dsp_enabled) return 0; - if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) { + if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { rt5514->dsp_enabled = ucontrol->value.integer.value[0]; if (rt5514->dsp_enabled) { @@ -342,11 +341,11 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol, !IS_ERR(rt5514->dsp_calib_clk)) { if (clk_set_rate(rt5514->dsp_calib_clk, rt5514->pdata.dsp_calib_clk_rate)) - dev_err(codec->dev, + dev_err(component->dev, "Can't set rate for mclk"); if (clk_prepare_enable(rt5514->dsp_calib_clk)) - dev_err(codec->dev, + dev_err(component->dev, "Can't enable dsp_calib_clk"); rt5514_calibration(rt5514, true); @@ -354,11 +353,11 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol, msleep(20); #if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI) rt5514_spi_burst_read(RT5514_PLL3_CALIB_CTRL6 | - RT5514_DSP_MAPPING, - (u8 *)&buf, sizeof(buf)); + RT5514_DSP_MAPPING, buf, sizeof(buf)); #else - dev_err(codec->dev, "There is no SPI driver for" + dev_err(component->dev, "There is no SPI driver for" " loading the firmware\n"); + memset(buf, 0, sizeof(buf)); #endif rt5514->pll3_cal_value = buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24; @@ -369,26 +368,26 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol, rt5514_enable_dsp_prepare(rt5514); - request_firmware(&fw, RT5514_FIRMWARE1, codec->dev); + request_firmware(&fw, RT5514_FIRMWARE1, component->dev); if (fw) { #if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI) rt5514_spi_burst_write(0x4ff60000, fw->data, ((fw->size/8)+1)*8); #else - dev_err(codec->dev, "There is no SPI driver for" + dev_err(component->dev, "There is no SPI driver for" " loading the firmware\n"); #endif release_firmware(fw); fw = NULL; } - request_firmware(&fw, RT5514_FIRMWARE2, codec->dev); + request_firmware(&fw, RT5514_FIRMWARE2, component->dev); if (fw) { #if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI) rt5514_spi_burst_write(0x4ffc0000, fw->data, ((fw->size/8)+1)*8); #else - dev_err(codec->dev, "There is no SPI driver for" + dev_err(component->dev, "There is no SPI driver for" " loading the firmware\n"); #endif release_firmware(fw); @@ -492,7 +491,7 @@ static const struct snd_kcontrol_new rt5514_sto2_dmic_mux = * Choose divider parameter that gives the highest possible DMIC frequency in * 1MHz - 3MHz range. */ -static int rt5514_calc_dmic_clk(struct snd_soc_codec *codec, int rate) +static int rt5514_calc_dmic_clk(struct snd_soc_component *component, int rate) { int div[] = {2, 3, 4, 8, 12, 16, 24, 32}; int i; @@ -508,20 +507,20 @@ static int rt5514_calc_dmic_clk(struct snd_soc_codec *codec, int rate) return i; } - dev_warn(codec->dev, "Base clock rate %d is too high\n", rate); + dev_warn(component->dev, "Base clock rate %d is too high\n", rate); return -EINVAL; } static int rt5514_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 rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); int idx; - idx = rt5514_calc_dmic_clk(codec, rt5514->sysclk); + idx = rt5514_calc_dmic_clk(component, rt5514->sysclk); if (idx < 0) - dev_err(codec->dev, "Failed to set DMIC clock\n"); + dev_err(component->dev, "Failed to set DMIC clock\n"); else regmap_update_bits(rt5514->regmap, RT5514_CLK_CTRL1, RT5514_CLK_DMIC_OUT_SEL_MASK, @@ -536,8 +535,8 @@ static int rt5514_set_dmic_clk(struct snd_soc_dapm_widget *w, static int rt5514_is_sys_clk_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); - struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); if (rt5514->sysclk_src == RT5514_SCLK_S_PLL1) return 1; @@ -548,8 +547,8 @@ static int rt5514_is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, static int rt5514_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 rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); return (rt5514->sysclk > rt5514->lrck * 384); } @@ -751,21 +750,21 @@ static const struct snd_soc_dapm_route rt5514_dapm_routes[] = { static int rt5514_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 rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); int pre_div, bclk_ms, frame_size; unsigned int val_len = 0; rt5514->lrck = params_rate(params); pre_div = rl6231_get_clk_info(rt5514->sysclk, rt5514->lrck); 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; } @@ -808,8 +807,8 @@ static int rt5514_hw_params(struct snd_pcm_substream *substream, static int rt5514_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) { - struct snd_soc_codec *codec = dai->codec; - struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); unsigned int reg_val = 0; switch (fmt & SND_SOC_DAIFMT_INV_MASK) { @@ -862,8 +861,8 @@ static int rt5514_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) static int rt5514_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { - struct snd_soc_codec *codec = dai->codec; - struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); unsigned int reg_val = 0; if (freq == rt5514->sysclk && clk_id == rt5514->sysclk_src) @@ -879,7 +878,7 @@ static int rt5514_set_dai_sysclk(struct snd_soc_dai *dai, 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; } @@ -897,13 +896,13 @@ static int rt5514_set_dai_sysclk(struct snd_soc_dai *dai, static int rt5514_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 rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); struct rl6231_pll_code pll_code; int ret; if (!freq_in || !freq_out) { - dev_dbg(codec->dev, "PLL disabled\n"); + dev_dbg(component->dev, "PLL disabled\n"); rt5514->pll_in = 0; rt5514->pll_out = 0; @@ -930,17 +929,17 @@ static int rt5514_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, 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); @@ -961,8 +960,8 @@ static int rt5514_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, static int rt5514_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 rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); unsigned int val = 0, val2 = 0; if (rx_mask || tx_mask) @@ -1047,10 +1046,10 @@ static int rt5514_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, return 0; } -static int rt5514_set_bias_level(struct snd_soc_codec *codec, +static int rt5514_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); int ret; switch (level) { @@ -1058,7 +1057,7 @@ static int rt5514_set_bias_level(struct snd_soc_codec *codec, if (IS_ERR(rt5514->mclk)) break; - if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) { + if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { clk_disable_unprepare(rt5514->mclk); } else { ret = clk_prepare_enable(rt5514->mclk); @@ -1068,7 +1067,7 @@ static int rt5514_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 the DSP is enabled in start of recording, the DSP * should be disabled, and sync back to normal recording @@ -1092,13 +1091,13 @@ static int rt5514_set_bias_level(struct snd_soc_codec *codec, return 0; } -static int rt5514_probe(struct snd_soc_codec *codec) +static int rt5514_probe(struct snd_soc_component *component) { - struct rt5514_priv *rt5514 = snd_soc_codec_get_drvdata(codec); - struct platform_device *pdev = container_of(codec->dev, + struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component); + struct platform_device *pdev = container_of(component->dev, struct platform_device, dev); - rt5514->mclk = devm_clk_get(codec->dev, "mclk"); + rt5514->mclk = devm_clk_get(component->dev, "mclk"); if (PTR_ERR(rt5514->mclk) == -EPROBE_DEFER) return -EPROBE_DEFER; @@ -1109,7 +1108,7 @@ static int rt5514_probe(struct snd_soc_codec *codec) return -EPROBE_DEFER; } - rt5514->codec = codec; + rt5514->component = component; rt5514->pll3_cal_value = 0x0078b000; return 0; @@ -1162,18 +1161,18 @@ static struct snd_soc_dai_driver rt5514_dai[] = { } }; -static const struct snd_soc_codec_driver soc_codec_dev_rt5514 = { - .probe = rt5514_probe, - .idle_bias_off = true, - .set_bias_level = rt5514_set_bias_level, - .component_driver = { - .controls = rt5514_snd_controls, - .num_controls = ARRAY_SIZE(rt5514_snd_controls), - .dapm_widgets = rt5514_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(rt5514_dapm_widgets), - .dapm_routes = rt5514_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(rt5514_dapm_routes), - }, +static const struct snd_soc_component_driver soc_component_dev_rt5514 = { + .probe = rt5514_probe, + .set_bias_level = rt5514_set_bias_level, + .controls = rt5514_snd_controls, + .num_controls = ARRAY_SIZE(rt5514_snd_controls), + .dapm_widgets = rt5514_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rt5514_dapm_widgets), + .dapm_routes = rt5514_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(rt5514_dapm_routes), + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static const struct regmap_config rt5514_i2c_regmap = { @@ -1313,17 +1312,11 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, if (ret != 0) dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); - return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5514, + return devm_snd_soc_register_component(&i2c->dev, + &soc_component_dev_rt5514, rt5514_dai, ARRAY_SIZE(rt5514_dai)); } -static int rt5514_i2c_remove(struct i2c_client *i2c) -{ - snd_soc_unregister_codec(&i2c->dev); - - return 0; -} - static const struct dev_pm_ops rt5514_i2_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(NULL, rt5514_i2c_resume) }; @@ -1336,7 +1329,6 @@ static struct i2c_driver rt5514_i2c_driver = { .pm = &rt5514_i2_pm_ops, }, .probe = rt5514_i2c_probe, - .remove = rt5514_i2c_remove, .id_table = rt5514_i2c_id, }; module_i2c_driver(rt5514_i2c_driver); |