Lines Matching +full:codec +full:- +full:aif1 +full:- +full:bclk
1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5660.c -- RT5660 ALSA SoC audio codec driver
26 #include <sound/soc-dapm.h>
298 static const DECLARE_TLV_DB_SCALE(rt5660_out_vol_tlv, -4650, 150, 0);
299 static const DECLARE_TLV_DB_SCALE(rt5660_dac_vol_tlv, -6525, 75, 0);
300 static const DECLARE_TLV_DB_SCALE(rt5660_adc_vol_tlv, -1725, 75, 0);
302 static const DECLARE_TLV_DB_SCALE(rt5660_bst_tlv, -1200, 75, 0);
344 * rt5660_set_dmic_clk - Set parameter of dmic.
354 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5660_set_dmic_clk()
358 rate = rt5660->sysclk / rl6231_get_pre_div(rt5660->regmap, in rt5660_set_dmic_clk()
362 dev_err(component->dev, "Failed to set DMIC clock\n"); in rt5660_set_dmic_clk()
373 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in rt5660_is_sys_clk_from_pll()
541 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt5660_lout_event()
643 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
644 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
838 struct snd_soc_component *component = dai->component; in rt5660_hw_params()
843 rt5660->lrck[dai->id] = params_rate(params); in rt5660_hw_params()
844 pre_div = rl6231_get_clk_info(rt5660->sysclk, rt5660->lrck[dai->id]); in rt5660_hw_params()
846 dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n", in rt5660_hw_params()
847 rt5660->lrck[dai->id], dai->id); in rt5660_hw_params()
848 return -EINVAL; in rt5660_hw_params()
853 dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); in rt5660_hw_params()
862 rt5660->bclk[dai->id] = rt5660->lrck[dai->id] * (32 << bclk_ms); in rt5660_hw_params()
864 dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n", in rt5660_hw_params()
865 rt5660->bclk[dai->id], rt5660->lrck[dai->id]); in rt5660_hw_params()
866 dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", in rt5660_hw_params()
867 bclk_ms, pre_div, dai->id); in rt5660_hw_params()
882 return -EINVAL; in rt5660_hw_params()
885 switch (dai->id) { in rt5660_hw_params()
896 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5660_hw_params()
897 return -EINVAL; in rt5660_hw_params()
905 struct snd_soc_component *component = dai->component; in rt5660_set_dai_fmt()
911 rt5660->master[dai->id] = 1; in rt5660_set_dai_fmt()
916 rt5660->master[dai->id] = 0; in rt5660_set_dai_fmt()
920 return -EINVAL; in rt5660_set_dai_fmt()
932 return -EINVAL; in rt5660_set_dai_fmt()
952 return -EINVAL; in rt5660_set_dai_fmt()
955 switch (dai->id) { in rt5660_set_dai_fmt()
963 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); in rt5660_set_dai_fmt()
964 return -EINVAL; in rt5660_set_dai_fmt()
973 struct snd_soc_component *component = dai->component; in rt5660_set_dai_sysclk()
977 if (freq == rt5660->sysclk && clk_id == rt5660->sysclk_src) in rt5660_set_dai_sysclk()
994 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); in rt5660_set_dai_sysclk()
995 return -EINVAL; in rt5660_set_dai_sysclk()
1001 rt5660->sysclk = freq; in rt5660_set_dai_sysclk()
1002 rt5660->sysclk_src = clk_id; in rt5660_set_dai_sysclk()
1004 dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); in rt5660_set_dai_sysclk()
1012 struct snd_soc_component *component = dai->component; in rt5660_set_dai_pll()
1017 if (source == rt5660->pll_src && freq_in == rt5660->pll_in && in rt5660_set_dai_pll()
1018 freq_out == rt5660->pll_out) in rt5660_set_dai_pll()
1022 dev_dbg(component->dev, "PLL disabled\n"); in rt5660_set_dai_pll()
1024 rt5660->pll_in = 0; in rt5660_set_dai_pll()
1025 rt5660->pll_out = 0; in rt5660_set_dai_pll()
1043 dev_err(component->dev, "Unknown PLL source %d\n", source); in rt5660_set_dai_pll()
1044 return -EINVAL; in rt5660_set_dai_pll()
1049 dev_err(component->dev, "Unsupport input clock %d\n", freq_in); in rt5660_set_dai_pll()
1053 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", in rt5660_set_dai_pll()
1063 rt5660->pll_in = freq_in; in rt5660_set_dai_pll()
1064 rt5660->pll_out = freq_out; in rt5660_set_dai_pll()
1065 rt5660->pll_src = source; in rt5660_set_dai_pll()
1084 if (IS_ERR(rt5660->mclk)) in rt5660_set_bias_level()
1088 clk_disable_unprepare(rt5660->mclk); in rt5660_set_bias_level()
1090 ret = clk_prepare_enable(rt5660->mclk); in rt5660_set_bias_level()
1126 rt5660->component = component; in rt5660_probe()
1141 regcache_cache_only(rt5660->regmap, true); in rt5660_suspend()
1142 regcache_mark_dirty(rt5660->regmap); in rt5660_suspend()
1151 if (rt5660->pdata.poweroff_codec_in_suspend) in rt5660_resume()
1154 regcache_cache_only(rt5660->regmap, false); in rt5660_resume()
1155 regcache_sync(rt5660->regmap); in rt5660_resume()
1177 .name = "rt5660-aif1",
1180 .stream_name = "AIF1 Playback",
1187 .stream_name = "AIF1 Capture",
1255 rt5660->pdata.in1_diff = device_property_read_bool(dev, in rt5660_parse_dt()
1256 "realtek,in1-differential"); in rt5660_parse_dt()
1257 rt5660->pdata.in3_diff = device_property_read_bool(dev, in rt5660_parse_dt()
1258 "realtek,in3-differential"); in rt5660_parse_dt()
1259 rt5660->pdata.poweroff_codec_in_suspend = device_property_read_bool(dev, in rt5660_parse_dt()
1260 "realtek,poweroff-in-suspend"); in rt5660_parse_dt()
1261 device_property_read_u32(dev, "realtek,dmic1-data-pin", in rt5660_parse_dt()
1262 &rt5660->pdata.dmic1_data_pin); in rt5660_parse_dt()
1270 struct rt5660_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt5660_i2c_probe()
1275 rt5660 = devm_kzalloc(&i2c->dev, sizeof(struct rt5660_priv), in rt5660_i2c_probe()
1279 return -ENOMEM; in rt5660_i2c_probe()
1282 rt5660->mclk = devm_clk_get(&i2c->dev, "mclk"); in rt5660_i2c_probe()
1283 if (PTR_ERR(rt5660->mclk) == -EPROBE_DEFER) in rt5660_i2c_probe()
1284 return -EPROBE_DEFER; in rt5660_i2c_probe()
1289 rt5660->pdata = *pdata; in rt5660_i2c_probe()
1290 else if (i2c->dev.of_node) in rt5660_i2c_probe()
1291 rt5660_parse_dt(rt5660, &i2c->dev); in rt5660_i2c_probe()
1293 rt5660->regmap = devm_regmap_init_i2c(i2c, &rt5660_regmap); in rt5660_i2c_probe()
1294 if (IS_ERR(rt5660->regmap)) { in rt5660_i2c_probe()
1295 ret = PTR_ERR(rt5660->regmap); in rt5660_i2c_probe()
1296 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt5660_i2c_probe()
1301 regmap_read(rt5660->regmap, RT5660_VENDOR_ID2, &val); in rt5660_i2c_probe()
1303 dev_err(&i2c->dev, in rt5660_i2c_probe()
1305 return -ENODEV; in rt5660_i2c_probe()
1308 regmap_write(rt5660->regmap, RT5660_RESET, 0); in rt5660_i2c_probe()
1310 ret = regmap_register_patch(rt5660->regmap, rt5660_patch, in rt5660_i2c_probe()
1313 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); in rt5660_i2c_probe()
1315 regmap_update_bits(rt5660->regmap, RT5660_GEN_CTRL1, in rt5660_i2c_probe()
1319 if (rt5660->pdata.dmic1_data_pin) { in rt5660_i2c_probe()
1320 regmap_update_bits(rt5660->regmap, RT5660_GPIO_CTRL1, in rt5660_i2c_probe()
1323 if (rt5660->pdata.dmic1_data_pin == RT5660_DMIC1_DATA_GPIO2) in rt5660_i2c_probe()
1324 regmap_update_bits(rt5660->regmap, RT5660_DMIC_CTRL1, in rt5660_i2c_probe()
1327 else if (rt5660->pdata.dmic1_data_pin == RT5660_DMIC1_DATA_IN1P) in rt5660_i2c_probe()
1328 regmap_update_bits(rt5660->regmap, RT5660_DMIC_CTRL1, in rt5660_i2c_probe()
1333 return devm_snd_soc_register_component(&i2c->dev, in rt5660_i2c_probe()