Lines Matching +full:pdm +full:- +full:fmt
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * max98927.c -- MAX98927 ALSA Soc Audio driver
5 * Copyright (C) 2016-2017 Maxim Integrated Products
140 static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) in max98927_dai_set_fmt() argument
142 struct snd_soc_component *component = codec_dai->component; in max98927_dai_set_fmt()
149 dev_dbg(component->dev, "%s: fmt 0x%08X\n", __func__, fmt); in max98927_dai_set_fmt()
151 switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { in max98927_dai_set_fmt()
153 max98927->provider = false; in max98927_dai_set_fmt()
157 max98927->provider = true; in max98927_dai_set_fmt()
161 dev_err(component->dev, "DAI clock mode unsupported\n"); in max98927_dai_set_fmt()
162 return -EINVAL; in max98927_dai_set_fmt()
165 regmap_update_bits(max98927->regmap, MAX98927_R0021_PCM_MASTER_MODE, in max98927_dai_set_fmt()
168 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { in max98927_dai_set_fmt()
175 dev_err(component->dev, "DAI invert mode unsupported\n"); in max98927_dai_set_fmt()
176 return -EINVAL; in max98927_dai_set_fmt()
179 regmap_update_bits(max98927->regmap, MAX98927_R0020_PCM_MODE_CFG, in max98927_dai_set_fmt()
183 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { in max98927_dai_set_fmt()
200 return -EINVAL; in max98927_dai_set_fmt()
202 max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK; in max98927_dai_set_fmt()
206 regmap_update_bits(max98927->regmap, MAX98927_R0018_PCM_RX_EN_A, in max98927_dai_set_fmt()
210 regmap_update_bits(max98927->regmap, in max98927_dai_set_fmt()
215 regmap_update_bits(max98927->regmap, MAX98927_R003B_SPK_SRC_SEL, in max98927_dai_set_fmt()
218 regmap_update_bits(max98927->regmap, MAX98927_R0035_PDM_RX_CTRL, in max98927_dai_set_fmt()
221 /* pdm channel configuration */ in max98927_dai_set_fmt()
222 regmap_update_bits(max98927->regmap, MAX98927_R0035_PDM_RX_CTRL, in max98927_dai_set_fmt()
225 regmap_update_bits(max98927->regmap, MAX98927_R003B_SPK_SRC_SEL, in max98927_dai_set_fmt()
228 regmap_update_bits(max98927->regmap, MAX98927_R0018_PCM_RX_EN_A, in max98927_dai_set_fmt()
260 struct snd_soc_component *component = max98927->component; in max98927_set_clock()
262 int blr_clk_ratio = params_channels(params) * max98927->ch_size; in max98927_set_clock()
265 if (max98927->provider) { in max98927_set_clock()
269 if (rate_table[i] >= max98927->sysclk) in max98927_set_clock()
273 dev_err(component->dev, "failed to find proper clock rate.\n"); in max98927_set_clock()
274 return -EINVAL; in max98927_set_clock()
276 regmap_update_bits(max98927->regmap, in max98927_set_clock()
282 if (!max98927->tdm_mode) { in max98927_set_clock()
286 dev_err(component->dev, "format unsupported %d\n", in max98927_set_clock()
288 return -EINVAL; in max98927_set_clock()
291 regmap_update_bits(max98927->regmap, in max98927_set_clock()
302 struct snd_soc_component *component = dai->component; in max98927_dai_hw_params()
319 dev_err(component->dev, "format unsupported %d\n", in max98927_dai_hw_params()
324 max98927->ch_size = snd_pcm_format_width(params_format(params)); in max98927_dai_hw_params()
326 regmap_update_bits(max98927->regmap, MAX98927_R0020_PCM_MODE_CFG, in max98927_dai_hw_params()
329 dev_dbg(component->dev, "format supported %d", in max98927_dai_hw_params()
362 dev_err(component->dev, "rate %d not supported\n", in max98927_dai_hw_params()
367 regmap_update_bits(max98927->regmap, MAX98927_R0023_PCM_SR_SETUP1, in max98927_dai_hw_params()
369 regmap_update_bits(max98927->regmap, MAX98927_R0024_PCM_SR_SETUP2, in max98927_dai_hw_params()
374 if (max98927->interleave_mode && in max98927_dai_hw_params()
376 regmap_update_bits(max98927->regmap, in max98927_dai_hw_params()
379 sampling_rate - 3); in max98927_dai_hw_params()
381 regmap_update_bits(max98927->regmap, in max98927_dai_hw_params()
387 return -EINVAL; in max98927_dai_hw_params()
394 struct snd_soc_component *component = dai->component; in max98927_dai_tdm_slot()
399 max98927->tdm_mode = true; in max98927_dai_tdm_slot()
404 dev_err(component->dev, "BCLK %d not supported\n", in max98927_dai_tdm_slot()
406 return -EINVAL; in max98927_dai_tdm_slot()
409 regmap_update_bits(max98927->regmap, MAX98927_R0022_PCM_CLK_SETUP, in max98927_dai_tdm_slot()
424 dev_err(component->dev, "format unsupported %d\n", in max98927_dai_tdm_slot()
426 return -EINVAL; in max98927_dai_tdm_slot()
429 regmap_update_bits(max98927->regmap, MAX98927_R0020_PCM_MODE_CFG, in max98927_dai_tdm_slot()
433 regmap_write(max98927->regmap, MAX98927_R0018_PCM_RX_EN_A, in max98927_dai_tdm_slot()
435 regmap_write(max98927->regmap, MAX98927_R0019_PCM_RX_EN_B, in max98927_dai_tdm_slot()
439 regmap_write(max98927->regmap, MAX98927_R001A_PCM_TX_EN_A, in max98927_dai_tdm_slot()
441 regmap_write(max98927->regmap, MAX98927_R001B_PCM_TX_EN_B, in max98927_dai_tdm_slot()
444 /* Tx slot Hi-Z configuration */ in max98927_dai_tdm_slot()
445 regmap_write(max98927->regmap, MAX98927_R001C_PCM_TX_HIZ_CTRL_A, in max98927_dai_tdm_slot()
447 regmap_write(max98927->regmap, MAX98927_R001D_PCM_TX_HIZ_CTRL_B, in max98927_dai_tdm_slot()
461 struct snd_soc_component *component = dai->component; in max98927_dai_set_sysclk()
464 max98927->sysclk = freq; in max98927_dai_set_sysclk()
478 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in max98927_dac_event()
483 max98927->tdm_mode = false; in max98927_dac_event()
486 regmap_update_bits(max98927->regmap, MAX98927_R003A_AMP_EN, in max98927_dac_event()
488 regmap_update_bits(max98927->regmap, MAX98927_R00FF_GLOBAL_SHDN, in max98927_dac_event()
492 regmap_update_bits(max98927->regmap, MAX98927_R00FF_GLOBAL_SHDN, in max98927_dac_event()
494 regmap_update_bits(max98927->regmap, MAX98927_R003A_AMP_EN, in max98927_dac_event()
535 static DECLARE_TLV_DB_SCALE(max98927_digital_tlv, -1600, 25, 0);
602 0, (1 << MAX98927_AMP_VOL_WIDTH) - 1, 0,
631 .name = "max98927-aif1",
654 max98927->component = component; in max98927_probe()
657 regmap_write(max98927->regmap, MAX98927_R0100_SOFT_RESET, in max98927_probe()
661 regmap_write(max98927->regmap, MAX98927_R001C_PCM_TX_HIZ_CTRL_A, 0xFF); in max98927_probe()
662 regmap_write(max98927->regmap, MAX98927_R001D_PCM_TX_HIZ_CTRL_B, 0xFF); in max98927_probe()
663 regmap_write(max98927->regmap, MAX98927_R0025_PCM_TO_SPK_MONOMIX_A, in max98927_probe()
665 regmap_write(max98927->regmap, MAX98927_R0026_PCM_TO_SPK_MONOMIX_B, in max98927_probe()
668 regmap_write(max98927->regmap, MAX98927_R0036_AMP_VOL_CTRL, 0x38); in max98927_probe()
669 regmap_write(max98927->regmap, MAX98927_R003C_SPK_GAIN, 0x05); in max98927_probe()
671 regmap_write(max98927->regmap, MAX98927_R0037_AMP_DSP_CFG, 0x03); in max98927_probe()
673 regmap_write(max98927->regmap, MAX98927_R003F_MEAS_DSP_CFG, 0xF7); in max98927_probe()
675 regmap_write(max98927->regmap, MAX98927_R0040_BOOST_CTRL0, 0x1C); in max98927_probe()
676 regmap_write(max98927->regmap, MAX98927_R0042_BOOST_CTRL1, 0x3E); in max98927_probe()
678 regmap_write(max98927->regmap, MAX98927_R0043_MEAS_ADC_CFG, 0x04); in max98927_probe()
679 regmap_write(max98927->regmap, MAX98927_R0044_MEAS_ADC_BASE_MSB, 0x00); in max98927_probe()
680 regmap_write(max98927->regmap, MAX98927_R0045_MEAS_ADC_BASE_LSB, 0x24); in max98927_probe()
682 regmap_write(max98927->regmap, MAX98927_R007F_BROWNOUT_LVL4_AMP1_CTRL1, in max98927_probe()
685 regmap_write(max98927->regmap, MAX98927_R0082_ENV_TRACK_VOUT_HEADROOM, in max98927_probe()
687 regmap_write(max98927->regmap, MAX98927_R0086_ENV_TRACK_CTRL, 0x01); in max98927_probe()
688 regmap_write(max98927->regmap, MAX98927_R0087_ENV_TRACK_BOOST_VOUT_READ, in max98927_probe()
692 regmap_write(max98927->regmap, MAX98927_R001E_PCM_TX_CH_SRC_A, in max98927_probe()
693 (max98927->i_l_slot << MAX98927_PCM_TX_CH_SRC_A_I_SHIFT | max98927->v_l_slot) & 0xFF); in max98927_probe()
695 if (max98927->v_l_slot < 8) { in max98927_probe()
696 regmap_update_bits(max98927->regmap, in max98927_probe()
698 1 << max98927->v_l_slot, 0); in max98927_probe()
699 regmap_update_bits(max98927->regmap, MAX98927_R001A_PCM_TX_EN_A, in max98927_probe()
700 1 << max98927->v_l_slot, in max98927_probe()
701 1 << max98927->v_l_slot); in max98927_probe()
703 regmap_update_bits(max98927->regmap, in max98927_probe()
705 1 << (max98927->v_l_slot - 8), 0); in max98927_probe()
706 regmap_update_bits(max98927->regmap, MAX98927_R001B_PCM_TX_EN_B, in max98927_probe()
707 1 << (max98927->v_l_slot - 8), in max98927_probe()
708 1 << (max98927->v_l_slot - 8)); in max98927_probe()
711 if (max98927->i_l_slot < 8) { in max98927_probe()
712 regmap_update_bits(max98927->regmap, in max98927_probe()
714 1 << max98927->i_l_slot, 0); in max98927_probe()
715 regmap_update_bits(max98927->regmap, MAX98927_R001A_PCM_TX_EN_A, in max98927_probe()
716 1 << max98927->i_l_slot, in max98927_probe()
717 1 << max98927->i_l_slot); in max98927_probe()
719 regmap_update_bits(max98927->regmap, in max98927_probe()
721 1 << (max98927->i_l_slot - 8), 0); in max98927_probe()
722 regmap_update_bits(max98927->regmap, MAX98927_R001B_PCM_TX_EN_B, in max98927_probe()
723 1 << (max98927->i_l_slot - 8), in max98927_probe()
724 1 << (max98927->i_l_slot - 8)); in max98927_probe()
728 if (max98927->interleave_mode) in max98927_probe()
729 regmap_update_bits(max98927->regmap, in max98927_probe()
741 regcache_cache_only(max98927->regmap, true); in max98927_suspend()
742 regcache_mark_dirty(max98927->regmap); in max98927_suspend()
749 regmap_write(max98927->regmap, MAX98927_R0100_SOFT_RESET, in max98927_resume()
751 regcache_cache_only(max98927->regmap, false); in max98927_resume()
752 regcache_sync(max98927->regmap); in max98927_resume()
789 struct device *dev = &i2c->dev; in max98927_slot_config()
791 if (!device_property_read_u32(dev, "vmon-slot-no", &value)) in max98927_slot_config()
792 max98927->v_l_slot = value & 0xF; in max98927_slot_config()
794 max98927->v_l_slot = 0; in max98927_slot_config()
796 if (!device_property_read_u32(dev, "imon-slot-no", &value)) in max98927_slot_config()
797 max98927->i_l_slot = value & 0xF; in max98927_slot_config()
799 max98927->i_l_slot = 1; in max98927_slot_config()
809 max98927 = devm_kzalloc(&i2c->dev, sizeof(*max98927), GFP_KERNEL); in max98927_i2c_probe()
811 ret = -ENOMEM; in max98927_i2c_probe()
817 if (of_property_read_bool(i2c->dev.of_node, "maxim,interleave-mode")) { in max98927_i2c_probe()
818 max98927->interleave_mode = true; in max98927_i2c_probe()
820 if (!of_property_read_u32(i2c->dev.of_node, "interleave_mode", in max98927_i2c_probe()
823 max98927->interleave_mode = true; in max98927_i2c_probe()
827 max98927->regmap in max98927_i2c_probe()
829 if (IS_ERR(max98927->regmap)) { in max98927_i2c_probe()
830 ret = PTR_ERR(max98927->regmap); in max98927_i2c_probe()
831 dev_err(&i2c->dev, in max98927_i2c_probe()
836 max98927->reset_gpio = devm_gpiod_get_optional(&i2c->dev, "reset", in max98927_i2c_probe()
838 if (IS_ERR(max98927->reset_gpio)) { in max98927_i2c_probe()
839 ret = PTR_ERR(max98927->reset_gpio); in max98927_i2c_probe()
840 return dev_err_probe(&i2c->dev, ret, "failed to request GPIO reset pin"); in max98927_i2c_probe()
843 if (max98927->reset_gpio) { in max98927_i2c_probe()
844 gpiod_set_value_cansleep(max98927->reset_gpio, 0); in max98927_i2c_probe()
850 ret = regmap_read(max98927->regmap, MAX98927_R01FF_REV_ID, ®); in max98927_i2c_probe()
852 dev_err(&i2c->dev, in max98927_i2c_probe()
856 dev_info(&i2c->dev, "MAX98927 revisionID: 0x%02X\n", reg); in max98927_i2c_probe()
862 ret = devm_snd_soc_register_component(&i2c->dev, in max98927_i2c_probe()
866 dev_err(&i2c->dev, "Failed to register component: %d\n", ret); in max98927_i2c_probe()
875 if (max98927->reset_gpio) in max98927_i2c_remove()
876 gpiod_set_value_cansleep(max98927->reset_gpio, 1); in max98927_i2c_remove()