Lines Matching +full:dmon +full:- +full:stuck +full:- +full:threshold +full:- +full:bits

1 // SPDX-License-Identifier: GPL-2.0
349 struct snd_soc_component *component = codec_dai->component; in max98396_dai_set_fmt()
360 dev_dbg(component->dev, "%s: fmt 0x%08X\n", __func__, fmt); in max98396_dai_set_fmt()
377 dev_err(component->dev, "DAI invert mode %d unsupported\n", in max98396_dai_set_fmt()
379 return -EINVAL; in max98396_dai_set_fmt()
397 dev_err(component->dev, "DAI format %d unsupported\n", in max98396_dai_set_fmt()
399 return -EINVAL; in max98396_dai_set_fmt()
402 ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status); in max98396_dai_set_fmt()
404 return -EINVAL; in max98396_dai_set_fmt()
407 ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, &reg); in max98396_dai_set_fmt()
409 return -EINVAL; in max98396_dai_set_fmt()
413 ret = regmap_read(max98396->regmap, in max98396_dai_set_fmt()
416 return -EINVAL; in max98396_dai_set_fmt()
422 max98396_global_enable_onoff(max98396->regmap, false); in max98396_dai_set_fmt()
425 regmap_update_bits(max98396->regmap, in max98396_dai_set_fmt()
429 regmap_update_bits(max98396->regmap, in max98396_dai_set_fmt()
435 max98396_global_enable_onoff(max98396->regmap, true); in max98396_dai_set_fmt()
497 if (in_slots == c->in && out_slots <= c->out && width == c->width) in max98396_pcm_config_index()
501 return -1; in max98396_pcm_config_index()
508 struct snd_soc_component *component = dai->component; in max98396_dai_hw_params()
527 dev_err(component->dev, "format unsupported %d\n", in max98396_dai_hw_params()
532 dev_dbg(component->dev, "format supported %d", in max98396_dai_hw_params()
574 dev_err(component->dev, "rate %d not supported\n", in max98396_dai_hw_params()
579 if (max98396->tdm_mode) { in max98396_dai_hw_params()
580 if (params_rate(params) > max98396->tdm_max_samplerate) { in max98396_dai_hw_params()
581 dev_err(component->dev, "TDM sample rate %d too high", in max98396_dai_hw_params()
591 dev_err(component->dev, in max98396_dai_hw_params()
600 dev_err(component->dev, "sample rate %d too high", in max98396_dai_hw_params()
606 ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status); in max98396_dai_hw_params()
611 ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, &reg); in max98396_dai_hw_params()
617 ret = regmap_read(max98396->regmap, MAX98396_R2043_PCM_SR_SETUP, &reg); in max98396_dai_hw_params()
626 max98396_global_enable_onoff(max98396->regmap, false); in max98396_dai_hw_params()
630 regmap_update_bits(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, in max98396_dai_hw_params()
634 regmap_update_bits(max98396->regmap, MAX98396_R2043_PCM_SR_SETUP, in max98396_dai_hw_params()
638 if (max98396->interleave_mode && in max98396_dai_hw_params()
640 regmap_update_bits(max98396->regmap, in max98396_dai_hw_params()
643 (sampling_rate - 3) in max98396_dai_hw_params()
646 regmap_update_bits(max98396->regmap, in max98396_dai_hw_params()
652 regmap_update_bits(max98396->regmap, in max98396_dai_hw_params()
658 max98396_global_enable_onoff(max98396->regmap, true); in max98396_dai_hw_params()
663 return -EINVAL; in max98396_dai_hw_params()
670 struct snd_soc_component *component = dai->component; in max98396_dai_tdm_slot()
680 max98396->tdm_mode = false; in max98396_dai_tdm_slot()
682 max98396->tdm_mode = true; in max98396_dai_tdm_slot()
687 dev_err(component->dev, "no TDM config for %d slots %d bits\n", in max98396_dai_tdm_slot()
689 return -EINVAL; in max98396_dai_tdm_slot()
693 max98396->tdm_max_samplerate = max98396_pcm_configs[ret].max_sr; in max98396_dai_tdm_slot()
707 dev_err(component->dev, "slot width %d unsupported\n", in max98396_dai_tdm_slot()
709 return -EINVAL; in max98396_dai_tdm_slot()
712 ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status); in max98396_dai_tdm_slot()
714 return -EINVAL; in max98396_dai_tdm_slot()
717 ret = regmap_read(max98396->regmap, MAX98396_R2042_PCM_CLK_SETUP, &reg); in max98396_dai_tdm_slot()
719 return -EINVAL; in max98396_dai_tdm_slot()
723 ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, &reg); in max98396_dai_tdm_slot()
725 return -EINVAL; in max98396_dai_tdm_slot()
732 max98396_global_enable_onoff(max98396->regmap, false); in max98396_dai_tdm_slot()
735 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
740 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
745 if (max98396->device_id == CODEC_TYPE_MAX98396) { in max98396_dai_tdm_slot()
746 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
750 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
755 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
759 regmap_update_bits(max98396->regmap, in max98396_dai_tdm_slot()
765 /* Tx slot Hi-Z configuration */ in max98396_dai_tdm_slot()
766 if (max98396->device_id == CODEC_TYPE_MAX98396) { in max98396_dai_tdm_slot()
767 regmap_write(max98396->regmap, in max98396_dai_tdm_slot()
770 regmap_write(max98396->regmap, in max98396_dai_tdm_slot()
774 regmap_write(max98396->regmap, in max98396_dai_tdm_slot()
777 regmap_write(max98396->regmap, in max98396_dai_tdm_slot()
783 max98396_global_enable_onoff(max98396->regmap, true); in max98396_dai_tdm_slot()
803 snd_soc_dapm_to_component(w->dapm); in max98396_dac_event()
809 max98396_global_enable_onoff(max98396->regmap, true); in max98396_dac_event()
812 max98396_global_enable_onoff(max98396->regmap, false); in max98396_dac_event()
814 max98396->tdm_mode = false; in max98396_dac_event()
941 static DECLARE_TLV_DB_SCALE(max98396_digital_tlv, -6350, 50, 1);
947 0x4B, 0xFF, TLV_DB_SCALE_ITEM(-9000, 50, 0),
961 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_mux_get()
966 regmap_read(max98396->regmap, reg, &val); in max98396_mux_get()
968 ucontrol->value.enumerated.item[0] = val; in max98396_mux_get()
980 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in max98396_mux_put()
981 unsigned int *item = ucontrol->value.enumerated.item; in max98396_mux_put()
985 if (item[0] >= e->items) in max98396_mux_put()
986 return -EINVAL; in max98396_mux_put()
988 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; in max98396_mux_put()
990 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_mux_put()
999 regmap_update_bits(max98396->regmap, reg, in max98396_mux_put()
1111 (struct soc_mixer_control *)kcontrol->private_value; in max98396_adc_value_get()
1115 int reg = mc->reg; in max98396_adc_value_get()
1121 if (max98396->device_id == CODEC_TYPE_MAX98397) { in max98396_adc_value_get()
1122 switch (mc->reg) { in max98396_adc_value_get()
1137 ret = regmap_raw_read(max98396->regmap, reg, &val, 2); in max98396_adc_value_get()
1141 /* ADC readback bits[8:0] rearrangement */ in max98396_adc_value_get()
1142 ucontrol->value.integer.value[0] = (val[0] << 1) | (val[1] & 1); in max98396_adc_value_get()
1146 ucontrol->value.integer.value[0] = 0; in max98396_adc_value_get()
1203 /* Thermal Threshold */
1276 /* Thermal Threshold */
1311 .name = "max98396-aif1",
1332 .name = "max98397-aif1",
1356 ret = regmap_write(max98396->regmap, in max98396_reset()
1365 ret = regmap_read(max98396->regmap, in max98396_reset()
1366 GET_REG_ADDR_REV_ID(max98396->device_id), &reg); in max98396_reset()
1382 max98396_reset(max98396, component->dev); in max98396_probe()
1385 if (max98396->device_id == CODEC_TYPE_MAX98396) { in max98396_probe()
1386 regmap_write(max98396->regmap, in max98396_probe()
1388 regmap_write(max98396->regmap, in max98396_probe()
1391 regmap_write(max98396->regmap, in max98396_probe()
1393 regmap_write(max98396->regmap, in max98396_probe()
1397 regmap_update_bits(max98396->regmap, in max98396_probe()
1400 (max98396->vbat == NULL) ? in max98396_probe()
1403 regmap_update_bits(max98396->regmap, in max98396_probe()
1406 regmap_update_bits(max98396->regmap, in max98396_probe()
1411 regmap_write(max98396->regmap, in max98396_probe()
1414 regmap_update_bits(max98396->regmap, in max98396_probe()
1417 regmap_update_bits(max98396->regmap, in max98396_probe()
1421 regmap_write(max98396->regmap, in max98396_probe()
1423 max98396->bypass_slot); in max98396_probe()
1425 regmap_write(max98396->regmap, in max98396_probe()
1427 max98396->v_slot); in max98396_probe()
1428 regmap_write(max98396->regmap, in max98396_probe()
1430 max98396->i_slot); in max98396_probe()
1431 regmap_write(max98396->regmap, in max98396_probe()
1433 max98396->spkfb_slot); in max98396_probe()
1435 if (max98396->v_slot < 8) in max98396_probe()
1436 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_probe()
1437 regmap_update_bits(max98396->regmap, in max98396_probe()
1439 1 << max98396->v_slot, 0); in max98396_probe()
1441 regmap_update_bits(max98396->regmap, in max98396_probe()
1443 1 << max98396->v_slot, 0); in max98396_probe()
1445 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_probe()
1446 regmap_update_bits(max98396->regmap, in max98396_probe()
1448 1 << (max98396->v_slot - 8), 0); in max98396_probe()
1450 regmap_update_bits(max98396->regmap, in max98396_probe()
1452 1 << (max98396->v_slot - 8), 0); in max98396_probe()
1454 if (max98396->i_slot < 8) in max98396_probe()
1455 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_probe()
1456 regmap_update_bits(max98396->regmap, in max98396_probe()
1458 1 << max98396->i_slot, 0); in max98396_probe()
1460 regmap_update_bits(max98396->regmap, in max98396_probe()
1462 1 << max98396->i_slot, 0); in max98396_probe()
1464 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_probe()
1465 regmap_update_bits(max98396->regmap, in max98396_probe()
1467 1 << (max98396->i_slot - 8), 0); in max98396_probe()
1469 regmap_update_bits(max98396->regmap, in max98396_probe()
1471 1 << (max98396->i_slot - 8), 0); in max98396_probe()
1474 if (max98396->interleave_mode) in max98396_probe()
1475 regmap_update_bits(max98396->regmap, in max98396_probe()
1480 regmap_update_bits(max98396->regmap, in max98396_probe()
1485 regmap_update_bits(max98396->regmap, in max98396_probe()
1488 max98396->dmon_stuck_enable ? in max98396_probe()
1491 regmap_update_bits(max98396->regmap, in max98396_probe()
1494 max98396->dmon_mag_enable ? in max98396_probe()
1497 switch (max98396->dmon_duration) { in max98396_probe()
1499 regmap_update_bits(max98396->regmap, in max98396_probe()
1504 regmap_update_bits(max98396->regmap, in max98396_probe()
1509 regmap_update_bits(max98396->regmap, in max98396_probe()
1514 regmap_update_bits(max98396->regmap, in max98396_probe()
1519 dev_err(component->dev, "Invalid DMON duration %d\n", in max98396_probe()
1520 max98396->dmon_duration); in max98396_probe()
1523 switch (max98396->dmon_stuck_threshold) { in max98396_probe()
1525 regmap_update_bits(max98396->regmap, in max98396_probe()
1531 regmap_update_bits(max98396->regmap, in max98396_probe()
1537 regmap_update_bits(max98396->regmap, in max98396_probe()
1543 regmap_update_bits(max98396->regmap, in max98396_probe()
1549 dev_err(component->dev, "Invalid DMON stuck threshold %d\n", in max98396_probe()
1550 max98396->dmon_stuck_threshold); in max98396_probe()
1553 switch (max98396->dmon_mag_threshold) { in max98396_probe()
1555 regmap_update_bits(max98396->regmap, in max98396_probe()
1558 (5 - max98396->dmon_mag_threshold) in max98396_probe()
1562 dev_err(component->dev, "Invalid DMON magnitude threshold %d\n", in max98396_probe()
1563 max98396->dmon_mag_threshold); in max98396_probe()
1567 regmap_update_bits(max98396->regmap, in max98396_probe()
1579 regcache_cache_only(max98396->regmap, true); in max98396_suspend()
1580 regcache_mark_dirty(max98396->regmap); in max98396_suspend()
1582 max98396->core_supplies); in max98396_suspend()
1583 if (max98396->pvdd) in max98396_suspend()
1584 regulator_disable(max98396->pvdd); in max98396_suspend()
1586 if (max98396->vbat) in max98396_suspend()
1587 regulator_disable(max98396->vbat); in max98396_suspend()
1598 max98396->core_supplies); in max98396_resume()
1602 if (max98396->pvdd) { in max98396_resume()
1603 ret = regulator_enable(max98396->pvdd); in max98396_resume()
1608 if (max98396->vbat) { in max98396_resume()
1609 ret = regulator_enable(max98396->vbat); in max98396_resume()
1614 regcache_cache_only(max98396->regmap, false); in max98396_resume()
1616 regcache_sync(max98396->regmap); in max98396_resume()
1678 if (!device_property_read_u32(dev, "adi,vmon-slot-no", &value)) in max98396_read_device_property()
1679 max98396->v_slot = value & 0xF; in max98396_read_device_property()
1681 max98396->v_slot = 0; in max98396_read_device_property()
1683 if (!device_property_read_u32(dev, "adi,imon-slot-no", &value)) in max98396_read_device_property()
1684 max98396->i_slot = value & 0xF; in max98396_read_device_property()
1686 max98396->i_slot = 1; in max98396_read_device_property()
1688 if (!device_property_read_u32(dev, "adi,spkfb-slot-no", &value)) in max98396_read_device_property()
1689 max98396->spkfb_slot = value & 0xF; in max98396_read_device_property()
1691 max98396->spkfb_slot = 2; in max98396_read_device_property()
1693 if (!device_property_read_u32(dev, "adi,bypass-slot-no", &value)) in max98396_read_device_property()
1694 max98396->bypass_slot = value & 0xF; in max98396_read_device_property()
1696 max98396->bypass_slot = 0; in max98396_read_device_property()
1698 max98396->dmon_stuck_enable = in max98396_read_device_property()
1699 device_property_read_bool(dev, "adi,dmon-stuck-enable"); in max98396_read_device_property()
1701 if (!device_property_read_u32(dev, "adi,dmon-stuck-threshold-bits", &value)) in max98396_read_device_property()
1702 max98396->dmon_stuck_threshold = value; in max98396_read_device_property()
1704 max98396->dmon_stuck_threshold = 15; in max98396_read_device_property()
1706 max98396->dmon_mag_enable = in max98396_read_device_property()
1707 device_property_read_bool(dev, "adi,dmon-magnitude-enable"); in max98396_read_device_property()
1709 if (!device_property_read_u32(dev, "adi,dmon-magnitude-threshold-bits", &value)) in max98396_read_device_property()
1710 max98396->dmon_mag_threshold = value; in max98396_read_device_property()
1712 max98396->dmon_mag_threshold = 5; in max98396_read_device_property()
1714 if (!device_property_read_u32(dev, "adi,dmon-duration-ms", &value)) in max98396_read_device_property()
1715 max98396->dmon_duration = value; in max98396_read_device_property()
1717 max98396->dmon_duration = 64; in max98396_read_device_property()
1725 max98396->core_supplies); in max98396_core_supplies_disable()
1739 max98396 = devm_kzalloc(&i2c->dev, sizeof(*max98396), GFP_KERNEL); in max98396_i2c_probe()
1742 ret = -ENOMEM; in max98396_i2c_probe()
1747 max98396->device_id = id->driver_data; in max98396_i2c_probe()
1750 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_i2c_probe()
1751 max98396->regmap = devm_regmap_init_i2c(i2c, &max98396_regmap); in max98396_i2c_probe()
1754 max98396->regmap = devm_regmap_init_i2c(i2c, &max98397_regmap); in max98396_i2c_probe()
1756 if (IS_ERR(max98396->regmap)) { in max98396_i2c_probe()
1757 ret = PTR_ERR(max98396->regmap); in max98396_i2c_probe()
1758 dev_err(&i2c->dev, in max98396_i2c_probe()
1765 max98396->core_supplies[i].supply = max98396_core_supplies[i]; in max98396_i2c_probe()
1767 ret = devm_regulator_bulk_get(&i2c->dev, MAX98396_NUM_CORE_SUPPLIES, in max98396_i2c_probe()
1768 max98396->core_supplies); in max98396_i2c_probe()
1770 dev_err(&i2c->dev, "Failed to request core supplies: %d\n", ret); in max98396_i2c_probe()
1774 max98396->vbat = devm_regulator_get_optional(&i2c->dev, "vbat"); in max98396_i2c_probe()
1775 if (IS_ERR(max98396->vbat)) { in max98396_i2c_probe()
1776 if (PTR_ERR(max98396->vbat) == -EPROBE_DEFER) in max98396_i2c_probe()
1777 return -EPROBE_DEFER; in max98396_i2c_probe()
1779 max98396->vbat = NULL; in max98396_i2c_probe()
1782 max98396->pvdd = devm_regulator_get_optional(&i2c->dev, "pvdd"); in max98396_i2c_probe()
1783 if (IS_ERR(max98396->pvdd)) { in max98396_i2c_probe()
1784 if (PTR_ERR(max98396->pvdd) == -EPROBE_DEFER) in max98396_i2c_probe()
1785 return -EPROBE_DEFER; in max98396_i2c_probe()
1787 max98396->pvdd = NULL; in max98396_i2c_probe()
1791 max98396->core_supplies); in max98396_i2c_probe()
1793 dev_err(&i2c->dev, "Unable to enable core supplies: %d", ret); in max98396_i2c_probe()
1797 ret = devm_add_action_or_reset(&i2c->dev, max98396_core_supplies_disable, in max98396_i2c_probe()
1802 if (max98396->pvdd) { in max98396_i2c_probe()
1803 ret = regulator_enable(max98396->pvdd); in max98396_i2c_probe()
1807 ret = devm_add_action_or_reset(&i2c->dev, in max98396_i2c_probe()
1809 max98396->pvdd); in max98396_i2c_probe()
1814 if (max98396->vbat) { in max98396_i2c_probe()
1815 ret = regulator_enable(max98396->vbat); in max98396_i2c_probe()
1819 ret = devm_add_action_or_reset(&i2c->dev, in max98396_i2c_probe()
1821 max98396->vbat); in max98396_i2c_probe()
1827 if (device_property_read_bool(&i2c->dev, "adi,interleave_mode")) in max98396_i2c_probe()
1828 max98396->interleave_mode = true; in max98396_i2c_probe()
1830 max98396->interleave_mode = false; in max98396_i2c_probe()
1833 max98396_read_device_property(&i2c->dev, max98396); in max98396_i2c_probe()
1836 max98396->reset_gpio = devm_gpiod_get_optional(&i2c->dev, in max98396_i2c_probe()
1838 if (IS_ERR(max98396->reset_gpio)) { in max98396_i2c_probe()
1839 ret = PTR_ERR(max98396->reset_gpio); in max98396_i2c_probe()
1840 dev_err(&i2c->dev, "Unable to request GPIO pin: %d.\n", ret); in max98396_i2c_probe()
1844 if (max98396->reset_gpio) { in max98396_i2c_probe()
1846 gpiod_set_value_cansleep(max98396->reset_gpio, 0); in max98396_i2c_probe()
1851 ret = regmap_read(max98396->regmap, in max98396_i2c_probe()
1852 GET_REG_ADDR_REV_ID(max98396->device_id), &reg); in max98396_i2c_probe()
1854 dev_err(&i2c->dev, "%s: failed to read revision of the device.\n", id->name); in max98396_i2c_probe()
1857 dev_info(&i2c->dev, "%s revision ID: 0x%02X\n", id->name, reg); in max98396_i2c_probe()
1860 if (max98396->device_id == CODEC_TYPE_MAX98396) in max98396_i2c_probe()
1861 ret = devm_snd_soc_register_component(&i2c->dev, in max98396_i2c_probe()
1866 ret = devm_snd_soc_register_component(&i2c->dev, in max98396_i2c_probe()
1871 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret); in max98396_i2c_probe()