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()
339 regmap_update_bits(rt298->regmap, RT298_IRQ_CTRL, 0x2, 0x0); in rt298_mic_detect()
346 rt298->jack = jack; in rt298_mic_detect()
347 regmap_update_bits(rt298->regmap, RT298_IRQ_CTRL, 0x2, 0x2); in rt298_mic_detect()
356 snd_soc_jack_report(rt298->jack, status, in rt298_mic_detect()
366 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); in is_mclk_mode()
369 if (rt298->clk_id == RT298_SCLK_S_MCLK) in is_mclk_mode()
375 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6350, 50, 0);
447 /* HP-OUT source */
454 /* SPK-OUT source */
464 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt298_spk_event()
486 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt298_set_dmic1_event()
505 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt298_adc_event()
508 nid = (w->reg >> 20) & 0xff; in rt298_adc_event()
551 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rt298_mic1_event()
575 SND_SOC_DAPM_SUPPLY_S("HV", 1, RT298_POWER_CTRL1,
684 {"MIC1", NULL, "HV"},
693 {"SPO", NULL, "HV"},
751 struct snd_soc_component *component = dai->component; in rt298_hw_params()
762 dev_err(component->dev, "Unsupported sample rate %d\n", in rt298_hw_params()
764 return -EINVAL; in rt298_hw_params()
766 switch (rt298->sys_clk) { in rt298_hw_params()
770 dev_err(component->dev, "Sys_clk is not matched (%d %d)\n", in rt298_hw_params()
771 params_rate(params), rt298->sys_clk); in rt298_hw_params()
772 return -EINVAL; in rt298_hw_params()
778 dev_err(component->dev, "Sys_clk is not matched (%d %d)\n", in rt298_hw_params()
779 params_rate(params), rt298->sys_clk); in rt298_hw_params()
780 return -EINVAL; in rt298_hw_params()
787 val |= (params_channels(params) - 1); in rt298_hw_params()
789 dev_err(component->dev, "Unsupported channels %d\n", in rt298_hw_params()
791 return -EINVAL; in rt298_hw_params()
817 return -EINVAL; in rt298_hw_params()
822 dev_dbg(component->dev, "format val = 0x%x\n", val); in rt298_hw_params()
832 struct snd_soc_component *component = dai->component; in rt298_set_dai_fmt()
844 return -EINVAL; in rt298_set_dai_fmt()
865 return -EINVAL; in rt298_set_dai_fmt()
867 /* bit 15 Stream Type 0:PCM 1:Non-PCM */ in rt298_set_dai_fmt()
877 struct snd_soc_component *component = dai->component; in rt298_set_dai_sysclk()
880 dev_dbg(component->dev, "%s freq=%d\n", __func__, freq); in rt298_set_dai_sysclk()
897 dev_err(component->dev, "Should not use MCLK\n"); in rt298_set_dai_sysclk()
898 return -EINVAL; in rt298_set_dai_sysclk()
905 dev_err(component->dev, "Should not use MCLK\n"); in rt298_set_dai_sysclk()
906 return -EINVAL; in rt298_set_dai_sysclk()
926 dev_err(component->dev, "Unsupported system clock\n"); in rt298_set_dai_sysclk()
927 return -EINVAL; in rt298_set_dai_sysclk()
930 rt298->sys_clk = freq; in rt298_set_dai_sysclk()
931 rt298->clk_id = clk_id; in rt298_set_dai_sysclk()
938 struct snd_soc_component *component = dai->component; in rt298_set_bclk_ratio()
940 dev_dbg(component->dev, "%s ratio=%d\n", __func__, ratio); in rt298_set_bclk_ratio()
991 regmap_update_bits(rt298->regmap, RT298_IRQ_CTRL, 0x1, 0x1); in rt298_irq()
1000 snd_soc_jack_report(rt298->jack, status, in rt298_irq()
1003 pm_wakeup_event(&rt298->i2c->dev, 300); in rt298_irq()
1013 rt298->component = component; in rt298_probe()
1015 if (rt298->i2c->irq) { in rt298_probe()
1016 regmap_update_bits(rt298->regmap, in rt298_probe()
1019 INIT_DELAYED_WORK(&rt298->jack_detect_work, in rt298_probe()
1021 schedule_delayed_work(&rt298->jack_detect_work, in rt298_probe()
1032 cancel_delayed_work_sync(&rt298->jack_detect_work); in rt298_remove()
1040 rt298->is_hp_in = -1; in rt298_suspend()
1041 regcache_cache_only(rt298->regmap, true); in rt298_suspend()
1042 regcache_mark_dirty(rt298->regmap); in rt298_suspend()
1051 regcache_cache_only(rt298->regmap, false); in rt298_resume()
1053 regcache_sync(rt298->regmap); in rt298_resume()
1075 .name = "rt298-aif1",
1095 .name = "rt298-aif2",
1182 struct rt298_platform_data *pdata = dev_get_platdata(&i2c->dev); in rt298_i2c_probe()
1184 struct device *dev = &i2c->dev; in rt298_i2c_probe()
1188 rt298 = devm_kzalloc(&i2c->dev, sizeof(*rt298), in rt298_i2c_probe()
1191 return -ENOMEM; in rt298_i2c_probe()
1193 rt298->regmap = devm_regmap_init(&i2c->dev, NULL, i2c, &rt298_regmap); in rt298_i2c_probe()
1194 if (IS_ERR(rt298->regmap)) { in rt298_i2c_probe()
1195 ret = PTR_ERR(rt298->regmap); in rt298_i2c_probe()
1196 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in rt298_i2c_probe()
1201 regmap_read(rt298->regmap, in rt298_i2c_probe()
1204 dev_err(&i2c->dev, in rt298_i2c_probe()
1206 return -ENODEV; in rt298_i2c_probe()
1209 rt298->index_cache = devm_kmemdup(&i2c->dev, rt298_index_def, in rt298_i2c_probe()
1211 if (!rt298->index_cache) in rt298_i2c_probe()
1212 return -ENOMEM; in rt298_i2c_probe()
1214 rt298->index_cache_size = INDEX_CACHE_SIZE; in rt298_i2c_probe()
1215 rt298->i2c = i2c; in rt298_i2c_probe()
1220 regmap_write(rt298->regmap, rt298->index_cache[i].reg, in rt298_i2c_probe()
1221 rt298->index_cache[i].def); in rt298_i2c_probe()
1223 regmap_write(rt298->regmap, rt298_reg[i].reg, in rt298_i2c_probe()
1227 rt298->pdata = *pdata; in rt298_i2c_probe()
1230 acpiid = acpi_match_device(dev->driver->acpi_match_table, dev); in rt298_i2c_probe()
1231 if (acpiid && acpiid->driver_data) { in rt298_i2c_probe()
1232 rt298->pdata = *(struct rt298_platform_data *) in rt298_i2c_probe()
1233 acpiid->driver_data; in rt298_i2c_probe()
1237 rt298->pdata.cbj_en = true; in rt298_i2c_probe()
1238 rt298->pdata.gpio2_en = false; in rt298_i2c_probe()
1242 regmap_update_bits(rt298->regmap, 0x04, 0x80, 0x80); in rt298_i2c_probe()
1243 regmap_update_bits(rt298->regmap, 0x1b, 0x860, 0x860); in rt298_i2c_probe()
1245 regmap_update_bits(rt298->regmap, 0x08, 0x20, 0x20); in rt298_i2c_probe()
1247 regmap_write(rt298->regmap, RT298_SET_AUDIO_POWER, AC_PWRST_D3); in rt298_i2c_probe()
1250 regmap_write(rt298->regmap, in rt298_i2c_probe()
1254 if (!rt298->pdata.cbj_en) { in rt298_i2c_probe()
1255 regmap_write(rt298->regmap, RT298_CBJ_CTRL2, 0x0000); in rt298_i2c_probe()
1256 regmap_write(rt298->regmap, RT298_MIC1_DET_CTRL, 0x0816); in rt298_i2c_probe()
1257 regmap_update_bits(rt298->regmap, in rt298_i2c_probe()
1260 regmap_update_bits(rt298->regmap, in rt298_i2c_probe()
1266 if (!rt298->pdata.gpio2_en) in rt298_i2c_probe()
1267 regmap_write(rt298->regmap, RT298_SET_DMIC2_DEFAULT, 0x40); in rt298_i2c_probe()
1269 regmap_write(rt298->regmap, RT298_SET_DMIC2_DEFAULT, 0); in rt298_i2c_probe()
1273 regmap_write(rt298->regmap, RT298_MISC_CTRL1, 0x0000); in rt298_i2c_probe()
1274 regmap_update_bits(rt298->regmap, in rt298_i2c_probe()
1277 regmap_write(rt298->regmap, RT298_UNSOLICITED_INLINE_CMD, 0x81); in rt298_i2c_probe()
1278 regmap_write(rt298->regmap, RT298_UNSOLICITED_HP_OUT, 0x82); in rt298_i2c_probe()
1279 regmap_write(rt298->regmap, RT298_UNSOLICITED_MIC1, 0x84); in rt298_i2c_probe()
1280 regmap_update_bits(rt298->regmap, RT298_IRQ_FLAG_CTRL, 0x2, 0x2); in rt298_i2c_probe()
1282 rt298->is_hp_in = -1; in rt298_i2c_probe()
1284 if (rt298->i2c->irq) { in rt298_i2c_probe()
1285 ret = request_threaded_irq(rt298->i2c->irq, NULL, rt298_irq, in rt298_i2c_probe()
1288 dev_err(&i2c->dev, in rt298_i2c_probe()
1294 ret = devm_snd_soc_register_component(&i2c->dev, in rt298_i2c_probe()
1305 if (i2c->irq) in rt298_i2c_remove()
1306 free_irq(i2c->irq, rt298); in rt298_i2c_remove()