Lines Matching +full:codec +full:- +full:aif1 +full:- +full:lrclk
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * max98390.c -- MAX98390 ALSA Soc Audio driver
165 struct snd_soc_component *component = codec_dai->component; in max98390_dai_set_fmt()
172 dev_dbg(component->dev, "%s: fmt 0x%08X\n", __func__, fmt); in max98390_dai_set_fmt()
179 max98390->provider = true; in max98390_dai_set_fmt()
183 dev_err(component->dev, "DAI clock mode unsupported\n"); in max98390_dai_set_fmt()
184 return -EINVAL; in max98390_dai_set_fmt()
187 regmap_update_bits(max98390->regmap, in max98390_dai_set_fmt()
199 dev_err(component->dev, "DAI invert mode unsupported\n"); in max98390_dai_set_fmt()
200 return -EINVAL; in max98390_dai_set_fmt()
203 regmap_update_bits(max98390->regmap, in max98390_dai_set_fmt()
223 return -EINVAL; in max98390_dai_set_fmt()
226 regmap_update_bits(max98390->regmap, in max98390_dai_set_fmt()
237 /* BCLKs per LRCLK */ in max98390_get_bclk_sel()
241 /* match BCLKs per LRCLK */ in max98390_get_bclk_sel()
254 /* codec MCLK rate in master mode */ in max98390_set_clock()
260 /* BCLK/LRCLK ratio calculation */ in max98390_set_clock()
265 if (max98390->provider) { in max98390_set_clock()
269 if (rate_table[i] >= max98390->sysclk) in max98390_set_clock()
273 dev_err(component->dev, "failed to find proper clock rate.\n"); in max98390_set_clock()
274 return -EINVAL; in max98390_set_clock()
277 regmap_update_bits(max98390->regmap, in max98390_set_clock()
283 if (!max98390->tdm_mode) { in max98390_set_clock()
287 dev_err(component->dev, "format unsupported %d\n", in max98390_set_clock()
289 return -EINVAL; in max98390_set_clock()
292 regmap_update_bits(max98390->regmap, in max98390_set_clock()
305 dai->component; in max98390_dai_hw_params()
324 dev_err(component->dev, "format unsupported %d\n", in max98390_dai_hw_params()
329 regmap_update_bits(max98390->regmap, in max98390_dai_hw_params()
333 dev_dbg(component->dev, "format supported %d", in max98390_dai_hw_params()
366 dev_err(component->dev, "rate %d not supported\n", in max98390_dai_hw_params()
371 /* set DAI_SR to correct LRCLK frequency */ in max98390_dai_hw_params()
372 regmap_update_bits(max98390->regmap, in max98390_dai_hw_params()
379 return -EINVAL; in max98390_dai_hw_params()
386 struct snd_soc_component *component = dai->component; in max98390_dai_tdm_slot()
394 max98390->tdm_mode = false; in max98390_dai_tdm_slot()
396 max98390->tdm_mode = true; in max98390_dai_tdm_slot()
398 dev_dbg(component->dev, in max98390_dai_tdm_slot()
399 "Tdm mode : %d\n", max98390->tdm_mode); in max98390_dai_tdm_slot()
404 dev_err(component->dev, "BCLK %d not supported\n", in max98390_dai_tdm_slot()
406 return -EINVAL; in max98390_dai_tdm_slot()
409 regmap_update_bits(max98390->regmap, in max98390_dai_tdm_slot()
426 dev_err(component->dev, "format unsupported %d\n", in max98390_dai_tdm_slot()
428 return -EINVAL; in max98390_dai_tdm_slot()
431 regmap_update_bits(max98390->regmap, in max98390_dai_tdm_slot()
436 regmap_write(max98390->regmap, in max98390_dai_tdm_slot()
439 regmap_write(max98390->regmap, in max98390_dai_tdm_slot()
443 /* Tx slot Hi-Z configuration */ in max98390_dai_tdm_slot()
444 regmap_write(max98390->regmap, in max98390_dai_tdm_slot()
447 regmap_write(max98390->regmap, in max98390_dai_tdm_slot()
457 struct snd_soc_component *component = dai->component; in max98390_dai_set_sysclk()
461 max98390->sysclk = freq; in max98390_dai_set_sysclk()
476 snd_soc_dapm_to_component(w->dapm); in max98390_dac_event()
482 regmap_update_bits(max98390->regmap, in max98390_dac_event()
485 regmap_update_bits(max98390->regmap, in max98390_dac_event()
490 regmap_update_bits(max98390->regmap, in max98390_dac_event()
493 regmap_update_bits(max98390->regmap, in max98390_dac_event()
516 static DECLARE_TLV_DB_SCALE(max98390_digital_tlv, -8000, 50, 0);
542 max98390->ref_rdc_value = ucontrol->value.integer.value[0]; in max98390_ref_rdc_put()
544 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE0, in max98390_ref_rdc_put()
545 max98390->ref_rdc_value & 0x000000ff); in max98390_ref_rdc_put()
546 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE1, in max98390_ref_rdc_put()
547 (max98390->ref_rdc_value >> 8) & 0x000000ff); in max98390_ref_rdc_put()
548 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE2, in max98390_ref_rdc_put()
549 (max98390->ref_rdc_value >> 16) & 0x000000ff); in max98390_ref_rdc_put()
562 ucontrol->value.integer.value[0] = max98390->ref_rdc_value; in max98390_ref_rdc_get()
575 max98390->ambient_temp_value = ucontrol->value.integer.value[0]; in max98390_ambient_temp_put()
577 regmap_write(max98390->regmap, DSM_TPROT_ROOM_TEMPERATURE_BYTE1, in max98390_ambient_temp_put()
578 (max98390->ambient_temp_value >> 8) & 0x000000ff); in max98390_ambient_temp_put()
579 regmap_write(max98390->regmap, DSM_TPROT_ROOM_TEMPERATURE_BYTE0, in max98390_ambient_temp_put()
580 (max98390->ambient_temp_value) & 0x000000ff); in max98390_ambient_temp_put()
593 ucontrol->value.integer.value[0] = max98390->ambient_temp_value; in max98390_ambient_temp_get()
604 dev_warn(component->dev, "Put adaptive rdc not supported\n"); in max98390_adaptive_rdc_put()
618 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE1, &rdc); in max98390_adaptive_rdc_get()
619 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE0, &rdc0); in max98390_adaptive_rdc_get()
620 ucontrol->value.integer.value[0] = rdc0 | rdc << 8; in max98390_adaptive_rdc_get()
642 regmap_read(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, &val); in max98390_dsm_calib_put()
644 /* Enable the codec for the duration of calibration readout */ in max98390_dsm_calib_put()
645 regmap_update_bits(max98390->regmap, MAX98390_R203A_AMP_EN, in max98390_dsm_calib_put()
647 regmap_update_bits(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, in max98390_dsm_calib_put()
651 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE1, &rdc); in max98390_dsm_calib_put()
652 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE0, &rdc_cal_result); in max98390_dsm_calib_put()
653 regmap_read(max98390->regmap, MAX98390_MEAS_ADC_CH2_READ, &temp); in max98390_dsm_calib_put()
656 /* Disable the codec if it was disabled */ in max98390_dsm_calib_put()
657 regmap_update_bits(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, in max98390_dsm_calib_put()
659 regmap_update_bits(max98390->regmap, MAX98390_R203A_AMP_EN, in max98390_dsm_calib_put()
667 max98390->ref_rdc_value = 268435456U / rdc_cal_result; in max98390_dsm_calib_put()
669 max98390->ambient_temp_value = temp * 52 - 1188; in max98390_dsm_calib_put()
672 rdc_factor = ((rdc_cal_result * 937 * 100) / 65536) - (rdc_integer * 100); in max98390_dsm_calib_put()
674 dev_info(component->dev, in max98390_dsm_calib_put()
770 .name = "max98390-aif1",
803 if (!strcmp(max98390->dsm_param_name, "default")) { in max98390_dsm_init()
812 max98390->dsm_param_name); in max98390_dsm_init()
814 ret = request_firmware(&fw, filename, component->dev); in max98390_dsm_init()
816 ret = request_firmware(&fw, "dsm_param.bin", component->dev); in max98390_dsm_init()
819 component->dev); in max98390_dsm_init()
825 dev_dbg(component->dev, in max98390_dsm_init()
827 fw->size); in max98390_dsm_init()
828 if (fw->size < MAX98390_DSM_PARAM_MIN_SIZE) { in max98390_dsm_init()
829 dev_err(component->dev, in max98390_dsm_init()
831 ret = -EINVAL; in max98390_dsm_init()
834 dsm_param = (char *)fw->data; in max98390_dsm_init()
839 fw->size < param_size + MAX98390_DSM_PAYLOAD_OFFSET) { in max98390_dsm_init()
840 dev_err(component->dev, in max98390_dsm_init()
842 ret = -EINVAL; in max98390_dsm_init()
845 regmap_write(max98390->regmap, MAX98390_R203A_AMP_EN, 0x80); in max98390_dsm_init()
847 regmap_bulk_write(max98390->regmap, param_start_addr, in max98390_dsm_init()
849 regmap_write(max98390->regmap, MAX98390_R23E1_DSP_GLOBAL_EN, 0x01); in max98390_dsm_init()
862 regmap_write(max98390->regmap, MAX98390_CLK_MON, 0x6f); in max98390_init_regs()
863 regmap_write(max98390->regmap, MAX98390_DAT_MON, 0x00); in max98390_init_regs()
864 regmap_write(max98390->regmap, MAX98390_PWR_GATE_CTL, 0x00); in max98390_init_regs()
865 regmap_write(max98390->regmap, MAX98390_PCM_RX_EN_A, 0x03); in max98390_init_regs()
866 regmap_write(max98390->regmap, MAX98390_ENV_TRACK_VOUT_HEADROOM, 0x0e); in max98390_init_regs()
867 regmap_write(max98390->regmap, MAX98390_BOOST_BYPASS1, 0x46); in max98390_init_regs()
868 regmap_write(max98390->regmap, MAX98390_FET_SCALING3, 0x03); in max98390_init_regs()
871 regmap_write(max98390->regmap, in max98390_init_regs()
873 (max98390->i_l_slot << 4 | in max98390_init_regs()
874 max98390->v_l_slot)&0xFF); in max98390_init_regs()
876 if (max98390->v_l_slot < 8) { in max98390_init_regs()
877 regmap_update_bits(max98390->regmap, in max98390_init_regs()
879 1 << max98390->v_l_slot, 0); in max98390_init_regs()
880 regmap_update_bits(max98390->regmap, in max98390_init_regs()
882 1 << max98390->v_l_slot, in max98390_init_regs()
883 1 << max98390->v_l_slot); in max98390_init_regs()
885 regmap_update_bits(max98390->regmap, in max98390_init_regs()
887 1 << (max98390->v_l_slot - 8), 0); in max98390_init_regs()
888 regmap_update_bits(max98390->regmap, in max98390_init_regs()
890 1 << (max98390->v_l_slot - 8), in max98390_init_regs()
891 1 << (max98390->v_l_slot - 8)); in max98390_init_regs()
894 if (max98390->i_l_slot < 8) { in max98390_init_regs()
895 regmap_update_bits(max98390->regmap, in max98390_init_regs()
897 1 << max98390->i_l_slot, 0); in max98390_init_regs()
898 regmap_update_bits(max98390->regmap, in max98390_init_regs()
900 1 << max98390->i_l_slot, in max98390_init_regs()
901 1 << max98390->i_l_slot); in max98390_init_regs()
903 regmap_update_bits(max98390->regmap, in max98390_init_regs()
905 1 << (max98390->i_l_slot - 8), 0); in max98390_init_regs()
906 regmap_update_bits(max98390->regmap, in max98390_init_regs()
908 1 << (max98390->i_l_slot - 8), in max98390_init_regs()
909 1 << (max98390->i_l_slot - 8)); in max98390_init_regs()
918 regmap_write(max98390->regmap, MAX98390_SOFTWARE_RESET, 0x01); in max98390_probe()
928 if (max98390->ref_rdc_value) { in max98390_probe()
929 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE0, in max98390_probe()
930 max98390->ref_rdc_value & 0x000000ff); in max98390_probe()
931 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE1, in max98390_probe()
932 (max98390->ref_rdc_value >> 8) & 0x000000ff); in max98390_probe()
933 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE2, in max98390_probe()
934 (max98390->ref_rdc_value >> 16) & 0x000000ff); in max98390_probe()
936 if (max98390->ambient_temp_value) { in max98390_probe()
937 regmap_write(max98390->regmap, DSM_TPROT_ROOM_TEMPERATURE_BYTE1, in max98390_probe()
938 (max98390->ambient_temp_value >> 8) & 0x000000ff); in max98390_probe()
939 regmap_write(max98390->regmap, DSM_TPROT_ROOM_TEMPERATURE_BYTE0, in max98390_probe()
940 (max98390->ambient_temp_value) & 0x000000ff); in max98390_probe()
953 regcache_cache_only(max98390->regmap, true); in max98390_suspend()
954 regcache_mark_dirty(max98390->regmap); in max98390_suspend()
965 regcache_cache_only(max98390->regmap, false); in max98390_resume()
966 regcache_sync(max98390->regmap); in max98390_resume()
1004 struct device *dev = &i2c->dev; in max98390_slot_config()
1006 if (!device_property_read_u32(dev, "maxim,vmon-slot-no", &value)) in max98390_slot_config()
1007 max98390->v_l_slot = value & 0xF; in max98390_slot_config()
1009 max98390->v_l_slot = 0; in max98390_slot_config()
1011 if (!device_property_read_u32(dev, "maxim,imon-slot-no", &value)) in max98390_slot_config()
1012 max98390->i_l_slot = value & 0xF; in max98390_slot_config()
1014 max98390->i_l_slot = 1; in max98390_slot_config()
1023 struct i2c_adapter *adapter = i2c->adapter; in max98390_i2c_probe()
1030 dev_err(&i2c->dev, "I2C check functionality failed\n"); in max98390_i2c_probe()
1031 return -ENXIO; in max98390_i2c_probe()
1034 max98390 = devm_kzalloc(&i2c->dev, sizeof(*max98390), GFP_KERNEL); in max98390_i2c_probe()
1036 ret = -ENOMEM; in max98390_i2c_probe()
1041 ret = device_property_read_u32(&i2c->dev, "maxim,temperature_calib", in max98390_i2c_probe()
1042 &max98390->ambient_temp_value); in max98390_i2c_probe()
1044 dev_info(&i2c->dev, in max98390_i2c_probe()
1047 ret = device_property_read_u32(&i2c->dev, "maxim,r0_calib", in max98390_i2c_probe()
1048 &max98390->ref_rdc_value); in max98390_i2c_probe()
1050 dev_info(&i2c->dev, in max98390_i2c_probe()
1054 dev_info(&i2c->dev, in max98390_i2c_probe()
1056 __func__, max98390->ref_rdc_value, in max98390_i2c_probe()
1057 max98390->ambient_temp_value); in max98390_i2c_probe()
1059 ret = device_property_read_string(&i2c->dev, "maxim,dsm_param_name", in max98390_i2c_probe()
1060 &max98390->dsm_param_name); in max98390_i2c_probe()
1062 max98390->dsm_param_name = "default"; in max98390_i2c_probe()
1068 max98390->regmap = devm_regmap_init_i2c(i2c, &max98390_regmap); in max98390_i2c_probe()
1069 if (IS_ERR(max98390->regmap)) { in max98390_i2c_probe()
1070 ret = PTR_ERR(max98390->regmap); in max98390_i2c_probe()
1071 dev_err(&i2c->dev, in max98390_i2c_probe()
1076 reset_gpio = devm_gpiod_get_optional(&i2c->dev, in max98390_i2c_probe()
1088 ret = regmap_read(max98390->regmap, in max98390_i2c_probe()
1091 dev_err(&i2c->dev, in max98390_i2c_probe()
1096 dev_info(&i2c->dev, "MAX98390 revisionID: 0x%02X\n", reg); in max98390_i2c_probe()
1098 ret = devm_snd_soc_register_component(&i2c->dev, in max98390_i2c_probe()