max98390.c (a108772d03d8bdb43258218b00bfe43bbe1e8800) | max98390.c (9dd28b467c35eef320a2974f6b1f209343ad8704) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * max98390.c -- MAX98390 ALSA Soc Audio driver 4 * 5 * Copyright (C) 2020 Maxim Integrated Products 6 * 7 */ 8 --- 147 unchanged lines hidden (view full) --- 156 {DSMIG_DEBUZZER_ALPHA_COEF_TEST_ONLY, 0x08}, 157 {DSM_VOL_ENA, 0x20}, 158 {DSM_VOL_CTRL, 0xa0}, 159 {DSMIG_EN, 0x00}, 160 {MAX98390_R23E1_DSP_GLOBAL_EN, 0x00}, 161 {MAX98390_R23FF_GLOBAL_EN, 0x00}, 162}; 163 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * max98390.c -- MAX98390 ALSA Soc Audio driver 4 * 5 * Copyright (C) 2020 Maxim Integrated Products 6 * 7 */ 8 --- 147 unchanged lines hidden (view full) --- 156 {DSMIG_DEBUZZER_ALPHA_COEF_TEST_ONLY, 0x08}, 157 {DSM_VOL_ENA, 0x20}, 158 {DSM_VOL_CTRL, 0xa0}, 159 {DSMIG_EN, 0x00}, 160 {MAX98390_R23E1_DSP_GLOBAL_EN, 0x00}, 161 {MAX98390_R23FF_GLOBAL_EN, 0x00}, 162}; 163 |
164static int max98390_dsm_calibrate(struct snd_soc_component *component); 165 | |
166static int max98390_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) 167{ 168 struct snd_soc_component *component = codec_dai->component; 169 struct max98390_priv *max98390 = 170 snd_soc_component_get_drvdata(component); 171 unsigned int mode; 172 unsigned int format; 173 unsigned int invert = 0; --- 456 unchanged lines hidden (view full) --- 630{ 631 /* Do nothing */ 632 return 0; 633} 634 635static int max98390_dsm_calib_put(struct snd_kcontrol *kcontrol, 636 struct snd_ctl_elem_value *ucontrol) 637{ | 164static int max98390_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) 165{ 166 struct snd_soc_component *component = codec_dai->component; 167 struct max98390_priv *max98390 = 168 snd_soc_component_get_drvdata(component); 169 unsigned int mode; 170 unsigned int format; 171 unsigned int invert = 0; --- 456 unchanged lines hidden (view full) --- 628{ 629 /* Do nothing */ 630 return 0; 631} 632 633static int max98390_dsm_calib_put(struct snd_kcontrol *kcontrol, 634 struct snd_ctl_elem_value *ucontrol) 635{ |
638 struct snd_soc_component *component = 639 snd_soc_kcontrol_component(kcontrol); | 636 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 637 struct max98390_priv *max98390 = snd_soc_component_get_drvdata(component); 638 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 639 unsigned int rdc, rdc_cal_result, rdc_integer, rdc_factor, temp, val; |
640 | 640 |
641 max98390_dsm_calibrate(component); | 641 snd_soc_dapm_mutex_lock(dapm); |
642 | 642 |
643 regmap_read(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, &val); 644 if (!val) { 645 /* Enable the codec for the duration of calibration readout */ 646 regmap_update_bits(max98390->regmap, MAX98390_R203A_AMP_EN, 647 MAX98390_AMP_EN_MASK, 1); 648 regmap_update_bits(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, 649 MAX98390_GLOBAL_EN_MASK, 1); 650 } 651 652 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE1, &rdc); 653 regmap_read(max98390->regmap, THERMAL_RDC_RD_BACK_BYTE0, &rdc_cal_result); 654 regmap_read(max98390->regmap, MAX98390_MEAS_ADC_CH2_READ, &temp); 655 656 if (!val) { 657 /* Disable the codec if it was disabled */ 658 regmap_update_bits(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, 659 MAX98390_GLOBAL_EN_MASK, 0); 660 regmap_update_bits(max98390->regmap, MAX98390_R203A_AMP_EN, 661 MAX98390_AMP_EN_MASK, 0); 662 } 663 664 snd_soc_dapm_mutex_unlock(dapm); 665 666 rdc_cal_result |= (rdc << 8) & 0x0000FFFF; 667 if (rdc_cal_result) 668 max98390->ref_rdc_value = 268435456U / rdc_cal_result; 669 670 max98390->ambient_temp_value = temp * 52 - 1188; 671 672 rdc_integer = rdc_cal_result * 937 / 65536; 673 rdc_factor = ((rdc_cal_result * 937 * 100) / 65536) - (rdc_integer * 100); 674 675 dev_info(component->dev, 676 "rdc resistance about %d.%02d ohm, reg=0x%X temp reg=0x%X\n", 677 rdc_integer, rdc_factor, rdc_cal_result, temp); 678 |
|
643 return 0; 644} 645 646static const struct snd_kcontrol_new max98390_snd_controls[] = { 647 SOC_SINGLE_TLV("Digital Volume", DSM_VOL_CTRL, 648 0, 184, 0, 649 max98390_digital_tlv), 650 SOC_SINGLE_TLV("Speaker Volume", MAX98390_R203D_SPK_GAIN, --- 163 unchanged lines hidden (view full) --- 814 regmap_write(max98390->regmap, MAX98390_R23E1_DSP_GLOBAL_EN, 0x01); 815 816err_alloc: 817 release_firmware(fw); 818err: 819 return ret; 820} 821 | 679 return 0; 680} 681 682static const struct snd_kcontrol_new max98390_snd_controls[] = { 683 SOC_SINGLE_TLV("Digital Volume", DSM_VOL_CTRL, 684 0, 184, 0, 685 max98390_digital_tlv), 686 SOC_SINGLE_TLV("Speaker Volume", MAX98390_R203D_SPK_GAIN, --- 163 unchanged lines hidden (view full) --- 850 regmap_write(max98390->regmap, MAX98390_R23E1_DSP_GLOBAL_EN, 0x01); 851 852err_alloc: 853 release_firmware(fw); 854err: 855 return ret; 856} 857 |
822static int max98390_dsm_calibrate(struct snd_soc_component *component) 823{ 824 unsigned int rdc, rdc_cal_result, temp; 825 unsigned int rdc_integer, rdc_factor; 826 struct max98390_priv *max98390 = 827 snd_soc_component_get_drvdata(component); 828 829 regmap_write(max98390->regmap, MAX98390_R203A_AMP_EN, 0x81); 830 regmap_write(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, 0x01); 831 832 regmap_read(max98390->regmap, 833 THERMAL_RDC_RD_BACK_BYTE1, &rdc); 834 regmap_read(max98390->regmap, 835 THERMAL_RDC_RD_BACK_BYTE0, &rdc_cal_result); 836 rdc_cal_result |= (rdc << 8) & 0x0000FFFF; 837 if (rdc_cal_result) 838 max98390->ref_rdc_value = 268435456U / rdc_cal_result; 839 840 regmap_read(max98390->regmap, MAX98390_MEAS_ADC_CH2_READ, &temp); 841 max98390->ambient_temp_value = temp * 52 - 1188; 842 843 rdc_integer = rdc_cal_result * 937 / 65536; 844 rdc_factor = ((rdc_cal_result * 937 * 100) / 65536) 845 - (rdc_integer * 100); 846 847 dev_info(component->dev, "rdc resistance about %d.%02d ohm, reg=0x%X temp reg=0x%X\n", 848 rdc_integer, rdc_factor, rdc_cal_result, temp); 849 850 regmap_write(max98390->regmap, MAX98390_R23FF_GLOBAL_EN, 0x00); 851 regmap_write(max98390->regmap, MAX98390_R203A_AMP_EN, 0x80); 852 853 return 0; 854} 855 | |
856static void max98390_init_regs(struct snd_soc_component *component) 857{ 858 struct max98390_priv *max98390 = 859 snd_soc_component_get_drvdata(component); 860 861 regmap_write(max98390->regmap, MAX98390_CLK_MON, 0x6f); 862 regmap_write(max98390->regmap, MAX98390_DAT_MON, 0x00); 863 regmap_write(max98390->regmap, MAX98390_PWR_GATE_CTL, 0x00); --- 279 unchanged lines hidden --- | 858static void max98390_init_regs(struct snd_soc_component *component) 859{ 860 struct max98390_priv *max98390 = 861 snd_soc_component_get_drvdata(component); 862 863 regmap_write(max98390->regmap, MAX98390_CLK_MON, 0x6f); 864 regmap_write(max98390->regmap, MAX98390_DAT_MON, 0x00); 865 regmap_write(max98390->regmap, MAX98390_PWR_GATE_CTL, 0x00); --- 279 unchanged lines hidden --- |