Lines Matching +full:spi +full:- +full:hv

1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt298.c -- RT298 ALSA SoC audio codec driver
16 #include <linux/spi/spi.h>
23 #include <sound/soc-dapm.h>
200 snd_soc_component_write(component, rt298->index_cache[i].reg, in rt298_index_sync()
201 rt298->index_cache[i].def); in rt298_index_sync()
227 if (!rt298->component) in rt298_jack_detect()
228 return -EINVAL; in rt298_jack_detect()
230 dapm = snd_soc_component_get_dapm(rt298->component); in rt298_jack_detect()
232 if (rt298->pdata.cbj_en) { in rt298_jack_detect()
233 regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); in rt298_jack_detect()
235 if (*hp == rt298->is_hp_in) in rt298_jack_detect()
236 return -1; in rt298_jack_detect()
237 rt298->is_hp_in = *hp; in rt298_jack_detect()
239 /* power on HV,VERF */ in rt298_jack_detect()
240 regmap_update_bits(rt298->regmap, in rt298_jack_detect()
243 snd_soc_dapm_force_enable_pin(dapm, "HV"); in rt298_jack_detect()
249 regmap_update_bits(rt298->regmap, in rt298_jack_detect()
251 regmap_update_bits(rt298->regmap, in rt298_jack_detect()
254 regmap_write(rt298->regmap, RT298_SET_MIC1, 0x24); in rt298_jack_detect()
257 regmap_update_bits(rt298->regmap, in rt298_jack_detect()
260 regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); in rt298_jack_detect()
265 regmap_update_bits(rt298->regmap, in rt298_jack_detect()
268 regmap_read(rt298->regmap, in rt298_jack_detect()
274 regmap_update_bits(rt298->regmap, in rt298_jack_detect()
280 regmap_update_bits(rt298->regmap, in rt298_jack_detect()
285 regmap_write(rt298->regmap, RT298_SET_MIC1, 0x20); in rt298_jack_detect()
286 regmap_update_bits(rt298->regmap, in rt298_jack_detect()
290 regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); in rt298_jack_detect()
292 regmap_read(rt298->regmap, RT298_GET_MIC1_SENSE, &buf); in rt298_jack_detect()
296 snd_soc_dapm_disable_pin(dapm, "HV"); in rt298_jack_detect()
325 snd_soc_jack_report(rt298->jack, status, in rt298_jack_detect_work()
335 rt298->jack = jack; in rt298_mic_detect()
339 if (rt298->jack->status & SND_JACK_HEADPHONE) in rt298_mic_detect()
341 if (rt298->jack->status & SND_JACK_MICROPHONE) { in rt298_mic_detect()
342 snd_soc_dapm_force_enable_pin(dapm, "HV"); in rt298_mic_detect()
345 regmap_update_bits(rt298->regmap, RT298_IRQ_CTRL, 0x2, 0x2); in rt298_mic_detect()
347 snd_soc_jack_report(rt298->jack, rt298->jack->status, in rt298_mic_detect()
351 regmap_update_bits(rt298->regmap, RT298_IRQ_CTRL, 0x2, 0x0); in rt298_mic_detect()
352 snd_soc_dapm_disable_pin(dapm, "HV"); in rt298_mic_detect()
364 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in is_mclk_mode()
367 if (rt298->clk_id == RT298_SCLK_S_MCLK) in is_mclk_mode()
373 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6350, 50, 0);
445 /* HP-OUT source */
452 /* SPK-OUT source */
462 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt298_spk_event()
484 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt298_set_dmic1_event()
503 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt298_adc_event()
506 nid = (w->reg >> 20) & 0xff; in rt298_adc_event()
549 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt298_mic1_event()
573 SND_SOC_DAPM_SUPPLY_S("HV", 1, RT298_POWER_CTRL1,
682 {"MIC1", NULL, "HV"},
691 {"SPO", NULL, "HV"},
749 struct snd_soc_component *component = dai->component; in rt298_hw_params()
760 dev_err(component->dev, "Unsupported sample rate %d\n", in rt298_hw_params()
762 return -EINVAL; in rt298_hw_params()
764 switch (rt298->sys_clk) { in rt298_hw_params()
768 dev_err(component->dev, "Sys_clk is not matched (%d %d)\n", in rt298_hw_params()
769 params_rate(params), rt298->sys_clk); in rt298_hw_params()
770 return -EINVAL; in rt298_hw_params()
776 dev_err(component->dev, "Sys_clk is not matched (%d %d)\n", in rt298_hw_params()
777 params_rate(params), rt298->sys_clk); in rt298_hw_params()
778 return -EINVAL; in rt298_hw_params()
785 val |= (params_channels(params) - 1); in rt298_hw_params()
787 dev_err(component->dev, "Unsupported channels %d\n", in rt298_hw_params()
789 return -EINVAL; in rt298_hw_params()
814 return -EINVAL; in rt298_hw_params()
819 dev_dbg(component->dev, "format val = 0x%x\n", val); in rt298_hw_params()
829 struct snd_soc_component *component = dai->component; in rt298_set_dai_fmt()
841 return -EINVAL; in rt298_set_dai_fmt()
862 return -EINVAL; in rt298_set_dai_fmt()
864 /* bit 15 Stream Type 0:PCM 1:Non-PCM */ in rt298_set_dai_fmt()
874 struct snd_soc_component *component = dai->component; in rt298_set_dai_sysclk()
877 dev_dbg(component->dev, "%s freq=%d\n", __func__, freq); in rt298_set_dai_sysclk()
894 dev_err(component->dev, "Should not use MCLK\n"); in rt298_set_dai_sysclk()
895 return -EINVAL; in rt298_set_dai_sysclk()
902 dev_err(component->dev, "Should not use MCLK\n"); in rt298_set_dai_sysclk()
903 return -EINVAL; in rt298_set_dai_sysclk()
923 dev_err(component->dev, "Unsupported system clock\n"); in rt298_set_dai_sysclk()
924 return -EINVAL; in rt298_set_dai_sysclk()
927 rt298->sys_clk = freq; in rt298_set_dai_sysclk()
928 rt298->clk_id = clk_id; in rt298_set_dai_sysclk()
935 struct snd_soc_component *component = dai->component; in rt298_set_bclk_ratio()
937 dev_dbg(component->dev, "%s ratio=%d\n", __func__, ratio); in rt298_set_bclk_ratio()
988 regmap_update_bits(rt298->regmap, RT298_IRQ_CTRL, 0x1, 0x1); in rt298_irq()
997 snd_soc_jack_report(rt298->jack, status, in rt298_irq()
1000 pm_wakeup_event(&rt298->i2c->dev, 300); in rt298_irq()
1010 rt298->component = component; in rt298_probe()
1011 INIT_DELAYED_WORK(&rt298->jack_detect_work, rt298_jack_detect_work); in rt298_probe()
1013 if (rt298->i2c->irq) in rt298_probe()
1014 schedule_delayed_work(&rt298->jack_detect_work, in rt298_probe()
1023 cancel_delayed_work_sync(&rt298->jack_detect_work); in rt298_remove()
1024 rt298->component = NULL; in rt298_remove()
1032 rt298->is_hp_in = -1; in rt298_suspend()
1033 regcache_cache_only(rt298->regmap, true); in rt298_suspend()
1034 regcache_mark_dirty(rt298->regmap); in rt298_suspend()
1043 regcache_cache_only(rt298->regmap, false); in rt298_resume()
1045 regcache_sync(rt298->regmap); in rt298_resume()
1067 .name = "rt298-aif1",
1087 .name = "rt298-aif2",
1180 struct rt298_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt298_i2c_probe()
1182 struct device *dev = &i2c->dev; in rt298_i2c_probe()
1186 rt298 = devm_kzalloc(&i2c->dev, sizeof(*rt298), in rt298_i2c_probe()
1189 return -ENOMEM; in rt298_i2c_probe()
1191 rt298->regmap = devm_regmap_init(&i2c->dev, NULL, i2c, &rt298_regmap); in rt298_i2c_probe()
1192 if (IS_ERR(rt298->regmap)) { in rt298_i2c_probe()
1193 ret = PTR_ERR(rt298->regmap); in rt298_i2c_probe()
1194 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt298_i2c_probe()
1199 regmap_read(rt298->regmap, in rt298_i2c_probe()
1202 dev_err(&i2c->dev, in rt298_i2c_probe()
1204 return -ENODEV; in rt298_i2c_probe()
1207 rt298->index_cache = devm_kmemdup(&i2c->dev, rt298_index_def, in rt298_i2c_probe()
1209 if (!rt298->index_cache) in rt298_i2c_probe()
1210 return -ENOMEM; in rt298_i2c_probe()
1212 rt298->index_cache_size = INDEX_CACHE_SIZE; in rt298_i2c_probe()
1213 rt298->i2c = i2c; in rt298_i2c_probe()
1218 regmap_write(rt298->regmap, rt298->index_cache[i].reg, in rt298_i2c_probe()
1219 rt298->index_cache[i].def); in rt298_i2c_probe()
1221 regmap_write(rt298->regmap, rt298_reg[i].reg, in rt298_i2c_probe()
1225 rt298->pdata = *pdata; in rt298_i2c_probe()
1228 acpiid = acpi_match_device(dev->driver->acpi_match_table, dev); in rt298_i2c_probe()
1229 if (acpiid && acpiid->driver_data) { in rt298_i2c_probe()
1230 rt298->pdata = *(struct rt298_platform_data *) in rt298_i2c_probe()
1231 acpiid->driver_data; in rt298_i2c_probe()
1235 rt298->pdata.cbj_en = true; in rt298_i2c_probe()
1236 rt298->pdata.gpio2_en = false; in rt298_i2c_probe()
1240 regmap_update_bits(rt298->regmap, 0x04, 0x80, 0x80); in rt298_i2c_probe()
1241 regmap_update_bits(rt298->regmap, 0x1b, 0x860, 0x860); in rt298_i2c_probe()
1243 regmap_update_bits(rt298->regmap, 0x08, 0x20, 0x20); in rt298_i2c_probe()
1245 regmap_write(rt298->regmap, RT298_SET_AUDIO_POWER, AC_PWRST_D3); in rt298_i2c_probe()
1248 regmap_write(rt298->regmap, in rt298_i2c_probe()
1252 if (!rt298->pdata.cbj_en) { in rt298_i2c_probe()
1253 regmap_write(rt298->regmap, RT298_CBJ_CTRL2, 0x0000); in rt298_i2c_probe()
1254 regmap_write(rt298->regmap, RT298_MIC1_DET_CTRL, 0x0816); in rt298_i2c_probe()
1255 regmap_update_bits(rt298->regmap, in rt298_i2c_probe()
1258 regmap_update_bits(rt298->regmap, in rt298_i2c_probe()
1264 if (!rt298->pdata.gpio2_en) in rt298_i2c_probe()
1265 regmap_write(rt298->regmap, RT298_SET_DMIC2_DEFAULT, 0x40); in rt298_i2c_probe()
1267 regmap_write(rt298->regmap, RT298_SET_DMIC2_DEFAULT, 0); in rt298_i2c_probe()
1271 regmap_write(rt298->regmap, RT298_MISC_CTRL1, 0x0000); in rt298_i2c_probe()
1272 regmap_update_bits(rt298->regmap, in rt298_i2c_probe()
1275 regmap_write(rt298->regmap, RT298_UNSOLICITED_INLINE_CMD, 0x81); in rt298_i2c_probe()
1276 regmap_write(rt298->regmap, RT298_UNSOLICITED_HP_OUT, 0x82); in rt298_i2c_probe()
1277 regmap_write(rt298->regmap, RT298_UNSOLICITED_MIC1, 0x84); in rt298_i2c_probe()
1278 regmap_update_bits(rt298->regmap, RT298_IRQ_FLAG_CTRL, 0x2, 0x2); in rt298_i2c_probe()
1280 rt298->is_hp_in = -1; in rt298_i2c_probe()
1282 if (rt298->i2c->irq) { in rt298_i2c_probe()
1283 ret = request_threaded_irq(rt298->i2c->irq, NULL, rt298_irq, in rt298_i2c_probe()
1286 dev_err(&i2c->dev, in rt298_i2c_probe()
1292 ret = devm_snd_soc_register_component(&i2c->dev, in rt298_i2c_probe()
1303 if (i2c->irq) in rt298_i2c_remove()
1304 free_irq(i2c->irq, rt298); in rt298_i2c_remove()