Lines Matching +full:imon +full:- +full:slot +full:- +full:no
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * max98390.c -- MAX98390 ALSA Soc Audio driver
166 struct snd_soc_component *component = codec_dai->component; in max98390_dai_set_fmt()
173 dev_dbg(component->dev, "%s: fmt 0x%08X\n", __func__, fmt); in max98390_dai_set_fmt()
180 max98390->provider = true; in max98390_dai_set_fmt()
184 dev_err(component->dev, "DAI clock mode unsupported\n"); in max98390_dai_set_fmt()
185 return -EINVAL; in max98390_dai_set_fmt()
188 regmap_update_bits(max98390->regmap, in max98390_dai_set_fmt()
200 dev_err(component->dev, "DAI invert mode unsupported\n"); in max98390_dai_set_fmt()
201 return -EINVAL; in max98390_dai_set_fmt()
204 regmap_update_bits(max98390->regmap, in max98390_dai_set_fmt()
224 return -EINVAL; in max98390_dai_set_fmt()
227 regmap_update_bits(max98390->regmap, in max98390_dai_set_fmt()
266 if (max98390->provider) { in max98390_set_clock()
270 if (rate_table[i] >= max98390->sysclk) in max98390_set_clock()
274 dev_err(component->dev, "failed to find proper clock rate.\n"); in max98390_set_clock()
275 return -EINVAL; in max98390_set_clock()
278 regmap_update_bits(max98390->regmap, in max98390_set_clock()
284 if (!max98390->tdm_mode) { in max98390_set_clock()
288 dev_err(component->dev, "format unsupported %d\n", in max98390_set_clock()
290 return -EINVAL; in max98390_set_clock()
293 regmap_update_bits(max98390->regmap, in max98390_set_clock()
306 dai->component; in max98390_dai_hw_params()
325 dev_err(component->dev, "format unsupported %d\n", in max98390_dai_hw_params()
330 regmap_update_bits(max98390->regmap, in max98390_dai_hw_params()
334 dev_dbg(component->dev, "format supported %d", in max98390_dai_hw_params()
367 dev_err(component->dev, "rate %d not supported\n", in max98390_dai_hw_params()
373 regmap_update_bits(max98390->regmap, in max98390_dai_hw_params()
380 return -EINVAL; in max98390_dai_hw_params()
387 struct snd_soc_component *component = dai->component; in max98390_dai_tdm_slot()
395 max98390->tdm_mode = false; in max98390_dai_tdm_slot()
397 max98390->tdm_mode = true; in max98390_dai_tdm_slot()
399 dev_dbg(component->dev, in max98390_dai_tdm_slot()
400 "Tdm mode : %d\n", max98390->tdm_mode); in max98390_dai_tdm_slot()
405 dev_err(component->dev, "BCLK %d not supported\n", in max98390_dai_tdm_slot()
407 return -EINVAL; in max98390_dai_tdm_slot()
410 regmap_update_bits(max98390->regmap, in max98390_dai_tdm_slot()
427 dev_err(component->dev, "format unsupported %d\n", in max98390_dai_tdm_slot()
429 return -EINVAL; in max98390_dai_tdm_slot()
432 regmap_update_bits(max98390->regmap, in max98390_dai_tdm_slot()
436 /* Rx slot configuration */ in max98390_dai_tdm_slot()
437 regmap_write(max98390->regmap, in max98390_dai_tdm_slot()
440 regmap_write(max98390->regmap, in max98390_dai_tdm_slot()
444 /* Tx slot Hi-Z configuration */ in max98390_dai_tdm_slot()
445 regmap_write(max98390->regmap, in max98390_dai_tdm_slot()
448 regmap_write(max98390->regmap, in max98390_dai_tdm_slot()
458 struct snd_soc_component *component = dai->component; in max98390_dai_set_sysclk()
462 max98390->sysclk = freq; in max98390_dai_set_sysclk()
477 snd_soc_dapm_to_component(w->dapm); in max98390_dac_event()
483 regmap_update_bits(max98390->regmap, in max98390_dac_event()
486 regmap_update_bits(max98390->regmap, in max98390_dac_event()
491 regmap_update_bits(max98390->regmap, in max98390_dac_event()
494 regmap_update_bits(max98390->regmap, in max98390_dac_event()
517 static DECLARE_TLV_DB_SCALE(max98390_digital_tlv, -8000, 50, 0);
543 max98390->ref_rdc_value = ucontrol->value.integer.value[0]; in max98390_ref_rdc_put()
545 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE0, in max98390_ref_rdc_put()
546 max98390->ref_rdc_value & 0x000000ff); in max98390_ref_rdc_put()
547 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE1, in max98390_ref_rdc_put()
548 (max98390->ref_rdc_value >> 8) & 0x000000ff); in max98390_ref_rdc_put()
549 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE2, in max98390_ref_rdc_put()
550 (max98390->ref_rdc_value >> 16) & 0x000000ff); in max98390_ref_rdc_put()
563 ucontrol->value.integer.value[0] = max98390->ref_rdc_value; in max98390_ref_rdc_get()
576 max98390->ambient_temp_value = ucontrol->value.integer.value[0]; in max98390_ambient_temp_put()
578 regmap_write(max98390->regmap, DSM_TPROT_ROOM_TEMPERATURE_BYTE1, in max98390_ambient_temp_put()
579 (max98390->ambient_temp_value >> 8) & 0x000000ff); in max98390_ambient_temp_put()
580 regmap_write(max98390->regmap, DSM_TPROT_ROOM_TEMPERATURE_BYTE0, in max98390_ambient_temp_put()
581 (max98390->ambient_temp_value) & 0x000000ff); in max98390_ambient_temp_put()
594 ucontrol->value.integer.value[0] = max98390->ambient_temp_value; in max98390_ambient_temp_get()
605 dev_warn(component->dev, "Put adaptive rdc not supported\n"); in max98390_adaptive_rdc_put()
619 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE1, &rdc); in max98390_adaptive_rdc_get()
620 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE0, &rdc0); in max98390_adaptive_rdc_get()
621 ucontrol->value.integer.value[0] = rdc0 | rdc << 8; in max98390_adaptive_rdc_get()
643 regmap_read(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, &val); in max98390_dsm_calib_put()
646 regmap_update_bits(max98390->regmap, MAX98390_R203A_AMP_EN, in max98390_dsm_calib_put()
648 regmap_update_bits(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, in max98390_dsm_calib_put()
652 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE1, &rdc); in max98390_dsm_calib_put()
653 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE0, &rdc_cal_result); in max98390_dsm_calib_put()
654 regmap_read(max98390->regmap, MAX98390_MEAS_ADC_CH2_READ, &temp); in max98390_dsm_calib_put()
658 regmap_update_bits(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, in max98390_dsm_calib_put()
660 regmap_update_bits(max98390->regmap, MAX98390_R203A_AMP_EN, in max98390_dsm_calib_put()
668 max98390->ref_rdc_value = 268435456U / rdc_cal_result; in max98390_dsm_calib_put()
670 max98390->ambient_temp_value = temp * 52 - 1188; in max98390_dsm_calib_put()
673 rdc_factor = ((rdc_cal_result * 937 * 100) / 65536) - (rdc_integer * 100); in max98390_dsm_calib_put()
675 dev_info(component->dev, in max98390_dsm_calib_put()
771 .name = "max98390-aif1",
804 if (!strcmp(max98390->dsm_param_name, "default")) { in max98390_dsm_init()
813 max98390->dsm_param_name); in max98390_dsm_init()
815 ret = request_firmware(&fw, filename, component->dev); in max98390_dsm_init()
817 ret = request_firmware(&fw, "dsm_param.bin", component->dev); in max98390_dsm_init()
820 component->dev); in max98390_dsm_init()
826 dev_dbg(component->dev, in max98390_dsm_init()
828 fw->size); in max98390_dsm_init()
829 if (fw->size < MAX98390_DSM_PARAM_MIN_SIZE) { in max98390_dsm_init()
830 dev_err(component->dev, in max98390_dsm_init()
832 ret = -EINVAL; in max98390_dsm_init()
835 dsm_param = (char *)fw->data; in max98390_dsm_init()
840 fw->size < param_size + MAX98390_DSM_PAYLOAD_OFFSET) { in max98390_dsm_init()
841 dev_err(component->dev, in max98390_dsm_init()
843 ret = -EINVAL; in max98390_dsm_init()
846 regmap_write(max98390->regmap, MAX98390_R203A_AMP_EN, 0x80); in max98390_dsm_init()
848 regmap_bulk_write(max98390->regmap, param_start_addr, in max98390_dsm_init()
850 regmap_write(max98390->regmap, MAX98390_R23E1_DSP_GLOBAL_EN, 0x01); in max98390_dsm_init()
863 regmap_write(max98390->regmap, MAX98390_CLK_MON, 0x6f); in max98390_init_regs()
864 regmap_write(max98390->regmap, MAX98390_DAT_MON, 0x00); in max98390_init_regs()
865 regmap_write(max98390->regmap, MAX98390_PWR_GATE_CTL, 0x00); in max98390_init_regs()
866 regmap_write(max98390->regmap, MAX98390_PCM_RX_EN_A, 0x03); in max98390_init_regs()
867 regmap_write(max98390->regmap, MAX98390_ENV_TRACK_VOUT_HEADROOM, 0x0e); in max98390_init_regs()
868 regmap_write(max98390->regmap, MAX98390_BOOST_BYPASS1, 0x46); in max98390_init_regs()
869 regmap_write(max98390->regmap, MAX98390_FET_SCALING3, 0x03); in max98390_init_regs()
871 /* voltage, current slot configuration */ in max98390_init_regs()
872 regmap_write(max98390->regmap, in max98390_init_regs()
874 (max98390->i_l_slot << 4 | in max98390_init_regs()
875 max98390->v_l_slot)&0xFF); in max98390_init_regs()
877 if (max98390->v_l_slot < 8) { in max98390_init_regs()
878 regmap_update_bits(max98390->regmap, in max98390_init_regs()
880 1 << max98390->v_l_slot, 0); in max98390_init_regs()
881 regmap_update_bits(max98390->regmap, in max98390_init_regs()
883 1 << max98390->v_l_slot, in max98390_init_regs()
884 1 << max98390->v_l_slot); in max98390_init_regs()
886 regmap_update_bits(max98390->regmap, in max98390_init_regs()
888 1 << (max98390->v_l_slot - 8), 0); in max98390_init_regs()
889 regmap_update_bits(max98390->regmap, in max98390_init_regs()
891 1 << (max98390->v_l_slot - 8), in max98390_init_regs()
892 1 << (max98390->v_l_slot - 8)); in max98390_init_regs()
895 if (max98390->i_l_slot < 8) { in max98390_init_regs()
896 regmap_update_bits(max98390->regmap, in max98390_init_regs()
898 1 << max98390->i_l_slot, 0); in max98390_init_regs()
899 regmap_update_bits(max98390->regmap, in max98390_init_regs()
901 1 << max98390->i_l_slot, in max98390_init_regs()
902 1 << max98390->i_l_slot); in max98390_init_regs()
904 regmap_update_bits(max98390->regmap, in max98390_init_regs()
906 1 << (max98390->i_l_slot - 8), 0); in max98390_init_regs()
907 regmap_update_bits(max98390->regmap, in max98390_init_regs()
909 1 << (max98390->i_l_slot - 8), in max98390_init_regs()
910 1 << (max98390->i_l_slot - 8)); in max98390_init_regs()
919 regmap_write(max98390->regmap, MAX98390_SOFTWARE_RESET, 0x01); in max98390_probe()
929 if (max98390->ref_rdc_value) { in max98390_probe()
930 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE0, in max98390_probe()
931 max98390->ref_rdc_value & 0x000000ff); in max98390_probe()
932 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE1, in max98390_probe()
933 (max98390->ref_rdc_value >> 8) & 0x000000ff); in max98390_probe()
934 regmap_write(max98390->regmap, DSM_TPROT_RECIP_RDC_ROOM_BYTE2, in max98390_probe()
935 (max98390->ref_rdc_value >> 16) & 0x000000ff); in max98390_probe()
937 if (max98390->ambient_temp_value) { in max98390_probe()
938 regmap_write(max98390->regmap, DSM_TPROT_ROOM_TEMPERATURE_BYTE1, in max98390_probe()
939 (max98390->ambient_temp_value >> 8) & 0x000000ff); in max98390_probe()
940 regmap_write(max98390->regmap, DSM_TPROT_ROOM_TEMPERATURE_BYTE0, in max98390_probe()
941 (max98390->ambient_temp_value) & 0x000000ff); in max98390_probe()
954 regcache_cache_only(max98390->regmap, true); in max98390_suspend()
955 regcache_mark_dirty(max98390->regmap); in max98390_suspend()
966 regcache_cache_only(max98390->regmap, false); in max98390_resume()
967 regcache_sync(max98390->regmap); in max98390_resume()
1005 struct device *dev = &i2c->dev; in max98390_slot_config()
1007 if (!device_property_read_u32(dev, "maxim,vmon-slot-no", &value)) in max98390_slot_config()
1008 max98390->v_l_slot = value & 0xF; in max98390_slot_config()
1010 max98390->v_l_slot = 0; in max98390_slot_config()
1012 if (!device_property_read_u32(dev, "maxim,imon-slot-no", &value)) in max98390_slot_config()
1013 max98390->i_l_slot = value & 0xF; in max98390_slot_config()
1015 max98390->i_l_slot = 1; in max98390_slot_config()
1024 struct i2c_adapter *adapter = i2c->adapter; in max98390_i2c_probe()
1031 dev_err(&i2c->dev, "I2C check functionality failed\n"); in max98390_i2c_probe()
1032 return -ENXIO; in max98390_i2c_probe()
1035 max98390 = devm_kzalloc(&i2c->dev, sizeof(*max98390), GFP_KERNEL); in max98390_i2c_probe()
1037 ret = -ENOMEM; in max98390_i2c_probe()
1042 ret = device_property_read_u32(&i2c->dev, "maxim,temperature_calib", in max98390_i2c_probe()
1043 &max98390->ambient_temp_value); in max98390_i2c_probe()
1045 dev_info(&i2c->dev, in max98390_i2c_probe()
1046 "no optional property 'temperature_calib' found, default:\n"); in max98390_i2c_probe()
1048 ret = device_property_read_u32(&i2c->dev, "maxim,r0_calib", in max98390_i2c_probe()
1049 &max98390->ref_rdc_value); in max98390_i2c_probe()
1051 dev_info(&i2c->dev, in max98390_i2c_probe()
1052 "no optional property 'r0_calib' found, default:\n"); in max98390_i2c_probe()
1055 dev_info(&i2c->dev, in max98390_i2c_probe()
1057 __func__, max98390->ref_rdc_value, in max98390_i2c_probe()
1058 max98390->ambient_temp_value); in max98390_i2c_probe()
1060 ret = device_property_read_string(&i2c->dev, "maxim,dsm_param_name", in max98390_i2c_probe()
1061 &max98390->dsm_param_name); in max98390_i2c_probe()
1063 max98390->dsm_param_name = "default"; in max98390_i2c_probe()
1065 /* voltage/current slot configuration */ in max98390_i2c_probe()
1069 max98390->regmap = devm_regmap_init_i2c(i2c, &max98390_regmap); in max98390_i2c_probe()
1070 if (IS_ERR(max98390->regmap)) { in max98390_i2c_probe()
1071 ret = PTR_ERR(max98390->regmap); in max98390_i2c_probe()
1072 dev_err(&i2c->dev, in max98390_i2c_probe()
1077 reset_gpio = devm_gpiod_get_optional(&i2c->dev, in max98390_i2c_probe()
1089 ret = regmap_read(max98390->regmap, in max98390_i2c_probe()
1092 dev_err(&i2c->dev, in max98390_i2c_probe()
1097 dev_info(&i2c->dev, "MAX98390 revisionID: 0x%02X\n", reg); in max98390_i2c_probe()
1099 ret = devm_snd_soc_register_component(&i2c->dev, in max98390_i2c_probe()