Lines Matching +full:dmon +full:- +full:stuck +full:- +full:threshold +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0
350 struct snd_soc_component *component = codec_dai->component; in max98396_dai_set_fmt()
361 dev_dbg(component->dev, "%s: fmt 0x%08X\n", __func__, fmt); in max98396_dai_set_fmt()
378 dev_err(component->dev, "DAI invert mode %d unsupported\n", in max98396_dai_set_fmt()
380 return -EINVAL; in max98396_dai_set_fmt()
398 dev_err(component->dev, "DAI format %d unsupported\n", in max98396_dai_set_fmt()
400 return -EINVAL; in max98396_dai_set_fmt()
403 ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status); in max98396_dai_set_fmt()
405 return -EINVAL; in max98396_dai_set_fmt()
408 ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, ®); in max98396_dai_set_fmt()
410 return -EINVAL; in max98396_dai_set_fmt()
414 ret = regmap_read(max98396->regmap, in max98396_dai_set_fmt()
417 return -EINVAL; in max98396_dai_set_fmt()
423 max98396_global_enable_onoff(max98396->regmap, false); in max98396_dai_set_fmt()
426 regmap_update_bits(max98396->regmap, in max98396_dai_set_fmt()
430 regmap_update_bits(max98396->regmap, in max98396_dai_set_fmt()
436 max98396_global_enable_onoff(max98396->regmap, true); in max98396_dai_set_fmt()
498 if (in_slots == c->in && out_slots <= c->out && width == c->width) in max98396_pcm_config_index()
502 return -1; in max98396_pcm_config_index()
509 struct snd_soc_component *component = dai->component; in max98396_dai_hw_params()
528 dev_err(component->dev, "format unsupported %d\n", in max98396_dai_hw_params()
533 dev_dbg(component->dev, "format supported %d", in max98396_dai_hw_params()
575 dev_err(component->dev, "rate %d not supported\n", in max98396_dai_hw_params()
580 if (max98396->tdm_mode) { in max98396_dai_hw_params()
581 if (params_rate(params) > max98396->tdm_max_samplerate) { in max98396_dai_hw_params()
582 dev_err(component->dev, "TDM sample rate %d too high", in max98396_dai_hw_params()
592 dev_err(component->dev, in max98396_dai_hw_params()
601 dev_err(component->dev, "sample rate %d too high", in max98396_dai_hw_params()
607 ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status); in max98396_dai_hw_params()
612 ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, ®); in max98396_dai_hw_params()
618 ret = regmap_read(max98396->regmap, MAX98396_R2043_PCM_SR_SETUP, ®); in max98396_dai_hw_params()
627 max98396_global_enable_onoff(max98396->regmap, false); in max98396_dai_hw_params()
631 regmap_update_bits(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, in max98396_dai_hw_params()
635 regmap_update_bits(max98396->regmap, MAX98396_R2043_PCM_SR_SETUP, in max98396_dai_hw_params()
639 if (max98396->interleave_mode && in max98396_dai_hw_params()
641 regmap_update_bits(max98396->regmap, in max98396_dai_hw_params()
644 (sampling_rate - 3) in max98396_dai_hw_params()
647 regmap_update_bits(max98396->regmap, in max98396_dai_hw_params()
653 regmap_update_bits(max98396->regmap, in max98396_dai_hw_params()
659 max98396_global_enable_onoff(max98396->regmap, true); in max98396_dai_hw_params()
664 return -EINVAL; in max98396_dai_hw_params()
671 struct snd_soc_component *component = dai->component; in max98396_dai_tdm_slot()
681 max98396->tdm_mode = false; in max98396_dai_tdm_slot()
683 max98396->tdm_mode = true; in max98396_dai_tdm_slot()
688 dev_err(component->dev, "no TDM config for %d slots %d bits\n", in max98396_dai_tdm_slot()
690 return -EINVAL; in max98396_dai_tdm_slot()
694 max98396->tdm_max_samplerate = max98396_pcm_configs[ret].max_sr; in max98396_dai_tdm_slot()
708 dev_err(component->dev, "slot width %d unsupported\n", in max98396_dai_tdm_slot()
710 return -EINVAL; in max98396_dai_tdm_slot()
713 ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status); in max98396_dai_tdm_slot()
715 return -EINVAL; in max98396_dai_tdm_slot()
718 ret = regmap_read(max98396->regmap, MAX98396_R2042_PCM_CLK_SETUP, ®); in max98396_dai_tdm_slot()
720 return -EINVAL; in max98396_dai_tdm_slot()
724 ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, ®); in max98396_dai_tdm_slot()
726 return -EINVAL; in max98396_dai_tdm_slot()
733 max98396_global_enable_onoff(max98396->regmap, false); in max98396_dai_tdm_slot()
736 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
741 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
746 if (max98396->device_id == CODEC_TYPE_MAX98396) { in max98396_dai_tdm_slot()
747 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
751 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
756 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
760 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
766 /* Tx slot Hi-Z configuration */ in max98396_dai_tdm_slot()
767 if (max98396->device_id == CODEC_TYPE_MAX98396) { in max98396_dai_tdm_slot()
768 regmap_write(max98396->regmap, in max98396_dai_tdm_slot()
771 regmap_write(max98396->regmap, in max98396_dai_tdm_slot()
775 regmap_write(max98396->regmap, in max98396_dai_tdm_slot()
778 regmap_write(max98396->regmap, in max98396_dai_tdm_slot()
784 max98396_global_enable_onoff(max98396->regmap, true); in max98396_dai_tdm_slot()
804 snd_soc_dapm_to_component(w->dapm); in max98396_dac_event()
810 max98396_global_enable_onoff(max98396->regmap, true); in max98396_dac_event()
813 max98396_global_enable_onoff(max98396->regmap, false); in max98396_dac_event()
815 max98396->tdm_mode = false; in max98396_dac_event()
942 static DECLARE_TLV_DB_SCALE(max98396_digital_tlv, -6350, 50, 1);
948 0x4B, 0xFF, TLV_DB_SCALE_ITEM(-9000, 50, 0),
962 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_mux_get()
967 regmap_read(max98396->regmap, reg, &val); in max98396_mux_get()
969 ucontrol->value.enumerated.item[0] = val; in max98396_mux_get()
981 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in max98396_mux_put()
982 unsigned int *item = ucontrol->value.enumerated.item; in max98396_mux_put()
986 if (item[0] >= e->items) in max98396_mux_put()
987 return -EINVAL; in max98396_mux_put()
989 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; in max98396_mux_put()
991 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_mux_put()
1000 regmap_update_bits(max98396->regmap, reg, in max98396_mux_put()
1112 (struct soc_mixer_control *)kcontrol->private_value; in max98396_adc_value_get()
1116 int reg = mc->reg; in max98396_adc_value_get()
1122 if (max98396->device_id == CODEC_TYPE_MAX98397) { in max98396_adc_value_get()
1123 switch (mc->reg) { in max98396_adc_value_get()
1138 ret = regmap_raw_read(max98396->regmap, reg, &val, 2); in max98396_adc_value_get()
1142 /* ADC readback bits[8:0] rearrangement */ in max98396_adc_value_get()
1143 ucontrol->value.integer.value[0] = (val[0] << 1) | (val[1] & 1); in max98396_adc_value_get()
1147 ucontrol->value.integer.value[0] = 0; in max98396_adc_value_get()
1204 /* Thermal Threshold */
1277 /* Thermal Threshold */
1312 .name = "max98396-aif1",
1333 .name = "max98397-aif1",
1357 ret = regmap_write(max98396->regmap, in max98396_reset()
1366 ret = regmap_read(max98396->regmap, in max98396_reset()
1367 GET_REG_ADDR_REV_ID(max98396->device_id), ®); in max98396_reset()
1383 max98396_reset(max98396, component->dev); in max98396_probe()
1386 if (max98396->device_id == CODEC_TYPE_MAX98396) { in max98396_probe()
1387 regmap_write(max98396->regmap, in max98396_probe()
1389 regmap_write(max98396->regmap, in max98396_probe()
1392 regmap_write(max98396->regmap, in max98396_probe()
1394 regmap_write(max98396->regmap, in max98396_probe()
1398 regmap_update_bits(max98396->regmap, in max98396_probe()
1401 (max98396->vbat == NULL) ? in max98396_probe()
1404 regmap_update_bits(max98396->regmap, in max98396_probe()
1407 regmap_update_bits(max98396->regmap, in max98396_probe()
1412 regmap_write(max98396->regmap, in max98396_probe()
1415 regmap_update_bits(max98396->regmap, in max98396_probe()
1418 regmap_update_bits(max98396->regmap, in max98396_probe()
1422 regmap_write(max98396->regmap, in max98396_probe()
1424 max98396->bypass_slot); in max98396_probe()
1426 regmap_write(max98396->regmap, in max98396_probe()
1428 max98396->v_slot); in max98396_probe()
1429 regmap_write(max98396->regmap, in max98396_probe()
1431 max98396->i_slot); in max98396_probe()
1432 regmap_write(max98396->regmap, in max98396_probe()
1434 max98396->spkfb_slot); in max98396_probe()
1436 if (max98396->v_slot < 8) in max98396_probe()
1437 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_probe()
1438 regmap_update_bits(max98396->regmap, in max98396_probe()
1440 1 << max98396->v_slot, 0); in max98396_probe()
1442 regmap_update_bits(max98396->regmap, in max98396_probe()
1444 1 << max98396->v_slot, 0); in max98396_probe()
1446 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_probe()
1447 regmap_update_bits(max98396->regmap, in max98396_probe()
1449 1 << (max98396->v_slot - 8), 0); in max98396_probe()
1451 regmap_update_bits(max98396->regmap, in max98396_probe()
1453 1 << (max98396->v_slot - 8), 0); in max98396_probe()
1455 if (max98396->i_slot < 8) in max98396_probe()
1456 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_probe()
1457 regmap_update_bits(max98396->regmap, in max98396_probe()
1459 1 << max98396->i_slot, 0); in max98396_probe()
1461 regmap_update_bits(max98396->regmap, in max98396_probe()
1463 1 << max98396->i_slot, 0); in max98396_probe()
1465 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_probe()
1466 regmap_update_bits(max98396->regmap, in max98396_probe()
1468 1 << (max98396->i_slot - 8), 0); in max98396_probe()
1470 regmap_update_bits(max98396->regmap, in max98396_probe()
1472 1 << (max98396->i_slot - 8), 0); in max98396_probe()
1475 if (max98396->interleave_mode) in max98396_probe()
1476 regmap_update_bits(max98396->regmap, in max98396_probe()
1481 regmap_update_bits(max98396->regmap, in max98396_probe()
1486 regmap_update_bits(max98396->regmap, in max98396_probe()
1489 max98396->dmon_stuck_enable ? in max98396_probe()
1492 regmap_update_bits(max98396->regmap, in max98396_probe()
1495 max98396->dmon_mag_enable ? in max98396_probe()
1498 switch (max98396->dmon_duration) { in max98396_probe()
1500 regmap_update_bits(max98396->regmap, in max98396_probe()
1505 regmap_update_bits(max98396->regmap, in max98396_probe()
1510 regmap_update_bits(max98396->regmap, in max98396_probe()
1515 regmap_update_bits(max98396->regmap, in max98396_probe()
1520 dev_err(component->dev, "Invalid DMON duration %d\n", in max98396_probe()
1521 max98396->dmon_duration); in max98396_probe()
1524 switch (max98396->dmon_stuck_threshold) { in max98396_probe()
1526 regmap_update_bits(max98396->regmap, in max98396_probe()
1532 regmap_update_bits(max98396->regmap, in max98396_probe()
1538 regmap_update_bits(max98396->regmap, in max98396_probe()
1544 regmap_update_bits(max98396->regmap, in max98396_probe()
1550 dev_err(component->dev, "Invalid DMON stuck threshold %d\n", in max98396_probe()
1551 max98396->dmon_stuck_threshold); in max98396_probe()
1554 switch (max98396->dmon_mag_threshold) { in max98396_probe()
1556 regmap_update_bits(max98396->regmap, in max98396_probe()
1559 (5 - max98396->dmon_mag_threshold) in max98396_probe()
1563 dev_err(component->dev, "Invalid DMON magnitude threshold %d\n", in max98396_probe()
1564 max98396->dmon_mag_threshold); in max98396_probe()
1568 regmap_update_bits(max98396->regmap, in max98396_probe()
1580 regcache_cache_only(max98396->regmap, true); in max98396_suspend()
1581 regcache_mark_dirty(max98396->regmap); in max98396_suspend()
1583 max98396->core_supplies); in max98396_suspend()
1584 if (max98396->pvdd) in max98396_suspend()
1585 regulator_disable(max98396->pvdd); in max98396_suspend()
1587 if (max98396->vbat) in max98396_suspend()
1588 regulator_disable(max98396->vbat); in max98396_suspend()
1599 max98396->core_supplies); in max98396_resume()
1603 if (max98396->pvdd) { in max98396_resume()
1604 ret = regulator_enable(max98396->pvdd); in max98396_resume()
1609 if (max98396->vbat) { in max98396_resume()
1610 ret = regulator_enable(max98396->vbat); in max98396_resume()
1615 regcache_cache_only(max98396->regmap, false); in max98396_resume()
1617 regcache_sync(max98396->regmap); in max98396_resume()
1679 if (!device_property_read_u32(dev, "adi,vmon-slot-no", &value)) in max98396_read_device_property()
1680 max98396->v_slot = value & 0xF; in max98396_read_device_property()
1682 max98396->v_slot = 0; in max98396_read_device_property()
1684 if (!device_property_read_u32(dev, "adi,imon-slot-no", &value)) in max98396_read_device_property()
1685 max98396->i_slot = value & 0xF; in max98396_read_device_property()
1687 max98396->i_slot = 1; in max98396_read_device_property()
1689 if (!device_property_read_u32(dev, "adi,spkfb-slot-no", &value)) in max98396_read_device_property()
1690 max98396->spkfb_slot = value & 0xF; in max98396_read_device_property()
1692 max98396->spkfb_slot = 2; in max98396_read_device_property()
1694 if (!device_property_read_u32(dev, "adi,bypass-slot-no", &value)) in max98396_read_device_property()
1695 max98396->bypass_slot = value & 0xF; in max98396_read_device_property()
1697 max98396->bypass_slot = 0; in max98396_read_device_property()
1699 max98396->dmon_stuck_enable = in max98396_read_device_property()
1700 device_property_read_bool(dev, "adi,dmon-stuck-enable"); in max98396_read_device_property()
1702 if (!device_property_read_u32(dev, "adi,dmon-stuck-threshold-bits", &value)) in max98396_read_device_property()
1703 max98396->dmon_stuck_threshold = value; in max98396_read_device_property()
1705 max98396->dmon_stuck_threshold = 15; in max98396_read_device_property()
1707 max98396->dmon_mag_enable = in max98396_read_device_property()
1708 device_property_read_bool(dev, "adi,dmon-magnitude-enable"); in max98396_read_device_property()
1710 if (!device_property_read_u32(dev, "adi,dmon-magnitude-threshold-bits", &value)) in max98396_read_device_property()
1711 max98396->dmon_mag_threshold = value; in max98396_read_device_property()
1713 max98396->dmon_mag_threshold = 5; in max98396_read_device_property()
1715 if (!device_property_read_u32(dev, "adi,dmon-duration-ms", &value)) in max98396_read_device_property()
1716 max98396->dmon_duration = value; in max98396_read_device_property()
1718 max98396->dmon_duration = 64; in max98396_read_device_property()
1726 max98396->core_supplies); in max98396_core_supplies_disable()
1740 max98396 = devm_kzalloc(&i2c->dev, sizeof(*max98396), GFP_KERNEL); in max98396_i2c_probe()
1743 ret = -ENOMEM; in max98396_i2c_probe()
1748 max98396->device_id = id->driver_data; in max98396_i2c_probe()
1751 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_i2c_probe()
1752 max98396->regmap = devm_regmap_init_i2c(i2c, &max98396_regmap); in max98396_i2c_probe()
1755 max98396->regmap = devm_regmap_init_i2c(i2c, &max98397_regmap); in max98396_i2c_probe()
1757 if (IS_ERR(max98396->regmap)) { in max98396_i2c_probe()
1758 ret = PTR_ERR(max98396->regmap); in max98396_i2c_probe()
1759 dev_err(&i2c->dev, in max98396_i2c_probe()
1766 max98396->core_supplies[i].supply = max98396_core_supplies[i]; in max98396_i2c_probe()
1768 ret = devm_regulator_bulk_get(&i2c->dev, MAX98396_NUM_CORE_SUPPLIES, in max98396_i2c_probe()
1769 max98396->core_supplies); in max98396_i2c_probe()
1771 dev_err(&i2c->dev, "Failed to request core supplies: %d\n", ret); in max98396_i2c_probe()
1775 max98396->vbat = devm_regulator_get_optional(&i2c->dev, "vbat"); in max98396_i2c_probe()
1776 if (IS_ERR(max98396->vbat)) { in max98396_i2c_probe()
1777 if (PTR_ERR(max98396->vbat) == -EPROBE_DEFER) in max98396_i2c_probe()
1778 return -EPROBE_DEFER; in max98396_i2c_probe()
1780 max98396->vbat = NULL; in max98396_i2c_probe()
1783 max98396->pvdd = devm_regulator_get_optional(&i2c->dev, "pvdd"); in max98396_i2c_probe()
1784 if (IS_ERR(max98396->pvdd)) { in max98396_i2c_probe()
1785 if (PTR_ERR(max98396->pvdd) == -EPROBE_DEFER) in max98396_i2c_probe()
1786 return -EPROBE_DEFER; in max98396_i2c_probe()
1788 max98396->pvdd = NULL; in max98396_i2c_probe()
1792 max98396->core_supplies); in max98396_i2c_probe()
1794 dev_err(&i2c->dev, "Unable to enable core supplies: %d", ret); in max98396_i2c_probe()
1798 ret = devm_add_action_or_reset(&i2c->dev, max98396_core_supplies_disable, in max98396_i2c_probe()
1803 if (max98396->pvdd) { in max98396_i2c_probe()
1804 ret = regulator_enable(max98396->pvdd); in max98396_i2c_probe()
1808 ret = devm_add_action_or_reset(&i2c->dev, in max98396_i2c_probe()
1810 max98396->pvdd); in max98396_i2c_probe()
1815 if (max98396->vbat) { in max98396_i2c_probe()
1816 ret = regulator_enable(max98396->vbat); in max98396_i2c_probe()
1820 ret = devm_add_action_or_reset(&i2c->dev, in max98396_i2c_probe()
1822 max98396->vbat); in max98396_i2c_probe()
1828 if (device_property_read_bool(&i2c->dev, "adi,interleave_mode")) in max98396_i2c_probe()
1829 max98396->interleave_mode = true; in max98396_i2c_probe()
1831 max98396->interleave_mode = false; in max98396_i2c_probe()
1834 max98396_read_device_property(&i2c->dev, max98396); in max98396_i2c_probe()
1837 max98396->reset_gpio = devm_gpiod_get_optional(&i2c->dev, in max98396_i2c_probe()
1839 if (IS_ERR(max98396->reset_gpio)) { in max98396_i2c_probe()
1840 ret = PTR_ERR(max98396->reset_gpio); in max98396_i2c_probe()
1841 dev_err(&i2c->dev, "Unable to request GPIO pin: %d.\n", ret); in max98396_i2c_probe()
1845 if (max98396->reset_gpio) { in max98396_i2c_probe()
1847 gpiod_set_value_cansleep(max98396->reset_gpio, 0); in max98396_i2c_probe()
1852 ret = regmap_read(max98396->regmap, in max98396_i2c_probe()
1853 GET_REG_ADDR_REV_ID(max98396->device_id), ®); in max98396_i2c_probe()
1855 dev_err(&i2c->dev, "%s: failed to read revision of the device.\n", id->name); in max98396_i2c_probe()
1858 dev_info(&i2c->dev, "%s revision ID: 0x%02X\n", id->name, reg); in max98396_i2c_probe()
1861 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_i2c_probe()
1862 ret = devm_snd_soc_register_component(&i2c->dev, in max98396_i2c_probe()
1867 ret = devm_snd_soc_register_component(&i2c->dev, in max98396_i2c_probe()
1872 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret); in max98396_i2c_probe()