Lines Matching +full:codec +full:- +full:aif1 +full:- +full:lrclk
1 // SPDX-License-Identifier: GPL-2.0
3 // MAX9867 ALSA SoC codec driver
5 // Copyright 2013-2015 Maxim Integrated Products
6 // Copyright 2018 Ladislav Michl <ladis@linux-mips.org>
42 "Butterworth/8-24"
55 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in max9867_adc_dac_event()
71 max9867->adc_dac_active |= BIT(adc_dac); in max9867_adc_dac_event()
73 max9867->adc_dac_active &= ~BIT(adc_dac); in max9867_adc_dac_event()
86 ret = regmap_read(max9867->regmap, MAX9867_CODECFLTR, ®); in max9867_filter_get()
88 return -EINVAL; in max9867_filter_get()
91 ucontrol->value.enumerated.item[0] = 1; in max9867_filter_get()
93 ucontrol->value.enumerated.item[0] = 0; in max9867_filter_get()
103 unsigned int reg, mode = ucontrol->value.enumerated.item[0]; in max9867_filter_set()
107 return -EINVAL; in max9867_filter_set()
110 if (max9867->adc_dac_active) in max9867_filter_set()
111 return -EBUSY; in max9867_filter_set()
114 ret = regmap_read(max9867->regmap, MAX9867_CODECFLTR, ®); in max9867_filter_set()
116 return -EINVAL; in max9867_filter_set()
125 /* shutdown codec before switching filter mode */ in max9867_filter_set()
126 regmap_update_bits(max9867->regmap, MAX9867_PWRMAN, in max9867_filter_set()
130 regmap_update_bits(max9867->regmap, MAX9867_CODECFLTR, in max9867_filter_set()
134 regmap_update_bits(max9867->regmap, MAX9867_PWRMAN, in max9867_filter_set()
148 0, 2, TLV_DB_SCALE_ITEM(-8600, 200, 1),
149 3, 17, TLV_DB_SCALE_ITEM(-7800, 400, 0),
150 18, 25, TLV_DB_SCALE_ITEM(-2000, 200, 0),
151 26, 34, TLV_DB_SCALE_ITEM( -500, 100, 0),
155 static DECLARE_TLV_DB_SCALE(max9867_line_tlv, -600, 200, 0);
156 static DECLARE_TLV_DB_SCALE(max9867_adc_tlv, -1200, 100, 0);
157 static DECLARE_TLV_DB_SCALE(max9867_dac_tlv, -1500, 100, 0);
160 0, 2, TLV_DB_SCALE_ITEM(-2000, 2000, 1),
316 snd_soc_component_get_drvdata(dai->component); in max9867_startup()
318 if (max9867->constraints) in max9867_startup()
319 snd_pcm_hw_constraint_list(substream->runtime, 0, in max9867_startup()
320 SNDRV_PCM_HW_PARAM_RATE, max9867->constraints); in max9867_startup()
330 struct snd_soc_component *component = dai->component; in max9867_dai_hw_params()
333 max9867->pclk); in max9867_dai_hw_params()
336 regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKHIGH, in max9867_dai_hw_params()
338 regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKLOW, in max9867_dai_hw_params()
340 if (max9867->provider) { in max9867_dai_hw_params()
341 if (max9867->dsp_a) { in max9867_dai_hw_params()
345 ratio = max9867->pclk / rate; in max9867_dai_hw_params()
363 return -EINVAL; in max9867_dai_hw_params()
373 return -EINVAL; in max9867_dai_hw_params()
376 regmap_update_bits(max9867->regmap, MAX9867_IFC1B, in max9867_dai_hw_params()
384 switch (max9867->pclk) { in max9867_dai_hw_params()
405 regmap_update_bits(max9867->regmap, MAX9867_SYSCLK, in max9867_dai_hw_params()
409 * digital pll locks on to any externally supplied LRCLK signal in max9867_dai_hw_params()
412 regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKLOW, in max9867_dai_hw_params()
414 regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKHIGH, in max9867_dai_hw_params()
422 struct snd_soc_component *component = dai->component; in max9867_mute()
425 return regmap_update_bits(max9867->regmap, MAX9867_DACLEVEL, in max9867_mute()
432 struct snd_soc_component *component = codec_dai->component; in max9867_set_dai_sysclk()
439 max9867->pclk = freq; in max9867_set_dai_sysclk()
442 max9867->pclk = freq / 2; in max9867_set_dai_sysclk()
445 max9867->pclk = freq / 4; in max9867_set_dai_sysclk()
447 dev_err(component->dev, in max9867_set_dai_sysclk()
448 "Invalid clock frequency %uHz (required 10-60MHz)\n", in max9867_set_dai_sysclk()
450 return -EINVAL; in max9867_set_dai_sysclk()
453 max9867->constraints = &max9867_constraints_48k; in max9867_set_dai_sysclk()
455 max9867->constraints = &max9867_constraints_44k1; in max9867_set_dai_sysclk()
457 dev_warn(component->dev, in max9867_set_dai_sysclk()
460 max9867->sysclk = freq; in max9867_set_dai_sysclk()
462 regmap_update_bits(max9867->regmap, MAX9867_SYSCLK, in max9867_set_dai_sysclk()
470 struct snd_soc_component *component = codec_dai->component; in max9867_dai_set_fmt()
476 max9867->provider = true; in max9867_dai_set_fmt()
481 max9867->provider = false; in max9867_dai_set_fmt()
485 return -EINVAL; in max9867_dai_set_fmt()
490 max9867->dsp_a = false; in max9867_dai_set_fmt()
494 max9867->dsp_a = true; in max9867_dai_set_fmt()
498 return -EINVAL; in max9867_dai_set_fmt()
515 return -EINVAL; in max9867_dai_set_fmt()
518 regmap_write(max9867->regmap, MAX9867_IFC1A, iface1A); in max9867_dai_set_fmt()
519 regmap_update_bits(max9867->regmap, MAX9867_IFC1B, in max9867_dai_set_fmt()
536 .name = "max9867-aif1",
583 err = clk_prepare_enable(max9867->mclk); in max9867_set_bias_level()
589 err = regcache_sync(max9867->regmap); in max9867_set_bias_level()
593 err = regmap_write(max9867->regmap, in max9867_set_bias_level()
600 err = regmap_write(max9867->regmap, MAX9867_PWRMAN, 0); in max9867_set_bias_level()
604 regcache_mark_dirty(max9867->regmap); in max9867_set_bias_level()
605 clk_disable_unprepare(max9867->mclk); in max9867_set_bias_level()
655 max9867 = devm_kzalloc(&i2c->dev, sizeof(*max9867), GFP_KERNEL); in max9867_i2c_probe()
657 return -ENOMEM; in max9867_i2c_probe()
660 max9867->regmap = devm_regmap_init_i2c(i2c, &max9867_regmap); in max9867_i2c_probe()
661 if (IS_ERR(max9867->regmap)) { in max9867_i2c_probe()
662 ret = PTR_ERR(max9867->regmap); in max9867_i2c_probe()
663 dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret); in max9867_i2c_probe()
666 ret = regmap_read(max9867->regmap, MAX9867_REVISION, ®); in max9867_i2c_probe()
668 dev_err(&i2c->dev, "Failed to read: %d\n", ret); in max9867_i2c_probe()
671 dev_info(&i2c->dev, "device revision: %x\n", reg); in max9867_i2c_probe()
672 ret = devm_snd_soc_register_component(&i2c->dev, &max9867_component, in max9867_i2c_probe()
675 dev_err(&i2c->dev, "Failed to register component: %d\n", ret); in max9867_i2c_probe()
679 max9867->mclk = devm_clk_get(&i2c->dev, NULL); in max9867_i2c_probe()
680 if (IS_ERR(max9867->mclk)) in max9867_i2c_probe()
681 return PTR_ERR(max9867->mclk); in max9867_i2c_probe()
711 MODULE_AUTHOR("Ladislav Michl <ladis@linux-mips.org>");