11 #include <linux/module.h>
13 #include <linux/kernel.h>
17 #include <linux/i2c.h>
24 #include <linux/slab.h>
25 #include <asm/div64.h>
611 return max98088_access[
reg].vol;
619 unsigned int band,
u16 *coefs)
643 static const char *max98088_exmode_texts[] = {
644 "Off",
"100Hz",
"400Hz",
"600Hz",
"800Hz",
"1000Hz",
"200-400Hz",
645 "400-600Hz",
"400-800Hz",
648 static const unsigned int max98088_exmode_values[] = {
649 0x00, 0x43, 0x10, 0x20, 0x30, 0x40, 0x11, 0x22, 0x32
652 static const struct soc_enum max98088_exmode_enum =
655 max98088_exmode_texts,
656 max98088_exmode_values);
658 static const char *max98088_ex_thresh[] = {
659 "0.6",
"1.2",
"1.8",
"2.4",
"3.0",
"3.6",
"4.2",
"4.8"};
660 static const struct soc_enum max98088_ex_thresh_enum[] = {
665 static const char *max98088_fltr_mode[] = {
"Voice",
"Music" };
666 static const struct soc_enum max98088_filter_mode_enum[] = {
670 static const char *max98088_extmic_text[] = {
"None",
"MIC1",
"MIC2" };
672 static const struct soc_enum max98088_extmic_enum =
678 static const char *max98088_dai1_fltr[] = {
679 "Off",
"fc=258/fs=16k",
"fc=500/fs=16k",
680 "fc=258/fs=8k",
"fc=500/fs=8k",
"fc=200"};
681 static const struct soc_enum max98088_dai1_dac_filter_enum[] = {
684 static const struct soc_enum max98088_dai1_adc_filter_enum[] = {
688 static int max98088_mic1pre_set(
struct snd_kcontrol *kcontrol,
692 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
693 unsigned int sel = ucontrol->
value.integer.value[0];
702 static int max98088_mic1pre_get(
struct snd_kcontrol *kcontrol,
706 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
712 static int max98088_mic2pre_set(
struct snd_kcontrol *kcontrol,
716 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
717 unsigned int sel = ucontrol->
value.integer.value[0];
726 static int max98088_mic2pre_get(
struct snd_kcontrol *kcontrol,
730 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
736 static const unsigned int max98088_micboost_tlv[] = {
763 max98088_mic1pre_get, max98088_mic1pre_set,
764 max98088_micboost_tlv),
767 max98088_mic2pre_get, max98088_mic2pre_set,
768 max98088_micboost_tlv),
782 SOC_ENUM(
"EX Limiter Mode", max98088_exmode_enum),
783 SOC_ENUM(
"EX Limiter Threshold", max98088_ex_thresh_enum),
785 SOC_ENUM(
"DAI1 Filter Mode", max98088_filter_mode_enum),
786 SOC_ENUM(
"DAI1 DAC Filter", max98088_dai1_dac_filter_enum),
787 SOC_ENUM(
"DAI1 ADC Filter", max98088_dai1_adc_filter_enum),
807 static const struct snd_kcontrol_new max98088_left_speaker_mixer_controls[] = {
821 static const struct snd_kcontrol_new max98088_right_speaker_mixer_controls[] = {
877 static const struct snd_kcontrol_new max98088_right_rec_mixer_controls[] = {
901 static const struct snd_kcontrol_new max98088_right_ADC_mixer_controls[] = {
914 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
944 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
947 BUG_ON(!((channel == 1) || (channel == 2)));
983 return max98088_line_pga(w, event,
LINE_INA, 1);
989 return max98088_line_pga(w, event,
LINE_INA, 2);
995 return max98088_line_pga(w, event,
LINE_INB, 1);
1001 return max98088_line_pga(w, event,
LINE_INB, 2);
1034 &max98088_extmic_mux),
1037 &max98088_left_hp_mixer_controls[0],
1038 ARRAY_SIZE(max98088_left_hp_mixer_controls)),
1041 &max98088_right_hp_mixer_controls[0],
1042 ARRAY_SIZE(max98088_right_hp_mixer_controls)),
1045 &max98088_left_speaker_mixer_controls[0],
1046 ARRAY_SIZE(max98088_left_speaker_mixer_controls)),
1049 &max98088_right_speaker_mixer_controls[0],
1050 ARRAY_SIZE(max98088_right_speaker_mixer_controls)),
1053 &max98088_left_rec_mixer_controls[0],
1054 ARRAY_SIZE(max98088_left_rec_mixer_controls)),
1057 &max98088_right_rec_mixer_controls[0],
1058 ARRAY_SIZE(max98088_right_rec_mixer_controls)),
1061 &max98088_left_ADC_mixer_controls[0],
1062 ARRAY_SIZE(max98088_left_ADC_mixer_controls)),
1065 &max98088_right_ADC_mixer_controls[0],
1066 ARRAY_SIZE(max98088_right_ADC_mixer_controls)),
1069 5, 0,
NULL, 0, max98088_mic_event,
1073 5, 0,
NULL, 0, max98088_mic_event,
1077 7, 0,
NULL, 0, max98088_pga_ina1_event,
1081 7, 0,
NULL, 0, max98088_pga_ina2_event,
1085 6, 0,
NULL, 0, max98088_pga_inb1_event,
1089 6, 0,
NULL, 0, max98088_pga_inb2_event,
1111 {
"Left HP Mixer",
"Left DAC1 Switch",
"DACL1"},
1112 {
"Left HP Mixer",
"Left DAC2 Switch",
"DACL2"},
1113 {
"Left HP Mixer",
"Right DAC1 Switch",
"DACR1"},
1114 {
"Left HP Mixer",
"Right DAC2 Switch",
"DACR2"},
1115 {
"Left HP Mixer",
"MIC1 Switch",
"MIC1 Input"},
1116 {
"Left HP Mixer",
"MIC2 Switch",
"MIC2 Input"},
1117 {
"Left HP Mixer",
"INA1 Switch",
"INA1 Input"},
1118 {
"Left HP Mixer",
"INA2 Switch",
"INA2 Input"},
1119 {
"Left HP Mixer",
"INB1 Switch",
"INB1 Input"},
1120 {
"Left HP Mixer",
"INB2 Switch",
"INB2 Input"},
1123 {
"Right HP Mixer",
"Left DAC1 Switch",
"DACL1"},
1124 {
"Right HP Mixer",
"Left DAC2 Switch",
"DACL2" },
1125 {
"Right HP Mixer",
"Right DAC1 Switch",
"DACR1"},
1126 {
"Right HP Mixer",
"Right DAC2 Switch",
"DACR2"},
1127 {
"Right HP Mixer",
"MIC1 Switch",
"MIC1 Input"},
1128 {
"Right HP Mixer",
"MIC2 Switch",
"MIC2 Input"},
1129 {
"Right HP Mixer",
"INA1 Switch",
"INA1 Input"},
1130 {
"Right HP Mixer",
"INA2 Switch",
"INA2 Input"},
1131 {
"Right HP Mixer",
"INB1 Switch",
"INB1 Input"},
1132 {
"Right HP Mixer",
"INB2 Switch",
"INB2 Input"},
1135 {
"Left SPK Mixer",
"Left DAC1 Switch",
"DACL1"},
1136 {
"Left SPK Mixer",
"Left DAC2 Switch",
"DACL2"},
1137 {
"Left SPK Mixer",
"Right DAC1 Switch",
"DACR1"},
1138 {
"Left SPK Mixer",
"Right DAC2 Switch",
"DACR2"},
1139 {
"Left SPK Mixer",
"MIC1 Switch",
"MIC1 Input"},
1140 {
"Left SPK Mixer",
"MIC2 Switch",
"MIC2 Input"},
1141 {
"Left SPK Mixer",
"INA1 Switch",
"INA1 Input"},
1142 {
"Left SPK Mixer",
"INA2 Switch",
"INA2 Input"},
1143 {
"Left SPK Mixer",
"INB1 Switch",
"INB1 Input"},
1144 {
"Left SPK Mixer",
"INB2 Switch",
"INB2 Input"},
1147 {
"Right SPK Mixer",
"Left DAC1 Switch",
"DACL1"},
1148 {
"Right SPK Mixer",
"Left DAC2 Switch",
"DACL2"},
1149 {
"Right SPK Mixer",
"Right DAC1 Switch",
"DACR1"},
1150 {
"Right SPK Mixer",
"Right DAC2 Switch",
"DACR2"},
1151 {
"Right SPK Mixer",
"MIC1 Switch",
"MIC1 Input"},
1152 {
"Right SPK Mixer",
"MIC2 Switch",
"MIC2 Input"},
1153 {
"Right SPK Mixer",
"INA1 Switch",
"INA1 Input"},
1154 {
"Right SPK Mixer",
"INA2 Switch",
"INA2 Input"},
1155 {
"Right SPK Mixer",
"INB1 Switch",
"INB1 Input"},
1156 {
"Right SPK Mixer",
"INB2 Switch",
"INB2 Input"},
1159 {
"Left REC Mixer",
"Left DAC1 Switch",
"DACL1"},
1160 {
"Left REC Mixer",
"Left DAC2 Switch",
"DACL2"},
1161 {
"Left REC Mixer",
"Right DAC1 Switch",
"DACR1"},
1162 {
"Left REC Mixer",
"Right DAC2 Switch",
"DACR2"},
1163 {
"Left REC Mixer",
"MIC1 Switch",
"MIC1 Input"},
1164 {
"Left REC Mixer",
"MIC2 Switch",
"MIC2 Input"},
1165 {
"Left REC Mixer",
"INA1 Switch",
"INA1 Input"},
1166 {
"Left REC Mixer",
"INA2 Switch",
"INA2 Input"},
1167 {
"Left REC Mixer",
"INB1 Switch",
"INB1 Input"},
1168 {
"Left REC Mixer",
"INB2 Switch",
"INB2 Input"},
1171 {
"Right REC Mixer",
"Left DAC1 Switch",
"DACL1"},
1172 {
"Right REC Mixer",
"Left DAC2 Switch",
"DACL2"},
1173 {
"Right REC Mixer",
"Right DAC1 Switch",
"DACR1"},
1174 {
"Right REC Mixer",
"Right DAC2 Switch",
"DACR2"},
1175 {
"Right REC Mixer",
"MIC1 Switch",
"MIC1 Input"},
1176 {
"Right REC Mixer",
"MIC2 Switch",
"MIC2 Input"},
1177 {
"Right REC Mixer",
"INA1 Switch",
"INA1 Input"},
1178 {
"Right REC Mixer",
"INA2 Switch",
"INA2 Input"},
1179 {
"Right REC Mixer",
"INB1 Switch",
"INB1 Input"},
1180 {
"Right REC Mixer",
"INB2 Switch",
"INB2 Input"},
1182 {
"HP Left Out",
NULL,
"Left HP Mixer"},
1183 {
"HP Right Out",
NULL,
"Right HP Mixer"},
1184 {
"SPK Left Out",
NULL,
"Left SPK Mixer"},
1185 {
"SPK Right Out",
NULL,
"Right SPK Mixer"},
1186 {
"REC Left Out",
NULL,
"Left REC Mixer"},
1187 {
"REC Right Out",
NULL,
"Right REC Mixer"},
1189 {
"HPL",
NULL,
"HP Left Out"},
1190 {
"HPR",
NULL,
"HP Right Out"},
1191 {
"SPKL",
NULL,
"SPK Left Out"},
1192 {
"SPKR",
NULL,
"SPK Right Out"},
1193 {
"RECL",
NULL,
"REC Left Out"},
1194 {
"RECR",
NULL,
"REC Right Out"},
1197 {
"Left ADC Mixer",
"MIC1 Switch",
"MIC1 Input"},
1198 {
"Left ADC Mixer",
"MIC2 Switch",
"MIC2 Input"},
1199 {
"Left ADC Mixer",
"INA1 Switch",
"INA1 Input"},
1200 {
"Left ADC Mixer",
"INA2 Switch",
"INA2 Input"},
1201 {
"Left ADC Mixer",
"INB1 Switch",
"INB1 Input"},
1202 {
"Left ADC Mixer",
"INB2 Switch",
"INB2 Input"},
1205 {
"Right ADC Mixer",
"MIC1 Switch",
"MIC1 Input"},
1206 {
"Right ADC Mixer",
"MIC2 Switch",
"MIC2 Input"},
1207 {
"Right ADC Mixer",
"INA1 Switch",
"INA1 Input"},
1208 {
"Right ADC Mixer",
"INA2 Switch",
"INA2 Input"},
1209 {
"Right ADC Mixer",
"INB1 Switch",
"INB1 Input"},
1210 {
"Right ADC Mixer",
"INB2 Switch",
"INB2 Input"},
1213 {
"ADCL",
NULL,
"Left ADC Mixer"},
1214 {
"ADCR",
NULL,
"Right ADC Mixer"},
1215 {
"INA1 Input",
NULL,
"INA1"},
1216 {
"INA2 Input",
NULL,
"INA2"},
1217 {
"INB1 Input",
NULL,
"INB1"},
1218 {
"INB2 Input",
NULL,
"INB2"},
1219 {
"MIC1 Input",
NULL,
"MIC1"},
1220 {
"MIC2 Input",
NULL,
"MIC2"},
1224 static const struct {
1259 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1261 unsigned long long ni;
1265 cdata = &max98088->
dai[0];
1284 if (rate_value(rate, ®val))
1294 if (max98088->
sysclk == 0) {
1295 dev_err(codec->
dev,
"Invalid system clock frequency\n");
1298 ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL)
1299 * (
unsigned long long int)
rate;
1326 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1328 unsigned long long ni;
1332 cdata = &max98088->
dai[1];
1351 if (rate_value(rate, ®val))
1361 if (max98088->
sysclk == 0) {
1362 dev_err(codec->
dev,
"Invalid system clock frequency\n");
1365 ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL)
1366 * (
unsigned long long int)
rate;
1388 static int max98088_dai_set_sysclk(
struct snd_soc_dai *dai,
1389 int clk_id,
unsigned int freq,
int dir)
1392 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1395 if (freq == max98088->
sysclk)
1402 if ((freq >= 10000000) && (freq < 20000000)) {
1404 }
else if ((freq >= 20000000) && (freq < 30000000)) {
1407 dev_err(codec->
dev,
"Invalid master clock frequency\n");
1415 M98088_SHDNRUN, M98088_SHDNRUN);
1418 dev_dbg(dai->
dev,
"Clock source is %d at %uHz\n", clk_id, freq);
1424 static int max98088_dai1_set_fmt(
struct snd_soc_dai *codec_dai,
1428 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1433 cdata = &max98088->
dai[0];
1435 if (fmt != cdata->
fmt) {
1453 dev_err(codec->
dev,
"Clock mode unsupported");
1496 static int max98088_dai2_set_fmt(
struct snd_soc_dai *codec_dai,
1500 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1504 cdata = &max98088->
dai[1];
1506 if (fmt != cdata->
fmt) {
1509 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1524 dev_err(codec->
dev,
"Clock mode unsupported");
1528 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1565 static int max98088_dai1_digital_mute(
struct snd_soc_dai *codec_dai,
int mute)
1580 static int max98088_dai2_digital_mute(
struct snd_soc_dai *codec_dai,
int mute)
1595 static void max98088_sync_cache(
struct snd_soc_codec *codec)
1608 for (i = 1; i < codec->
driver->reg_cache_size; i++) {
1612 if (reg_cache[i] == max98088_reg[i])
1621 static int max98088_set_bias_level(
struct snd_soc_codec *codec,
1633 max98088_sync_cache(codec);
1649 #define MAX98088_RATES SNDRV_PCM_RATE_8000_96000
1650 #define MAX98088_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
1653 .set_sysclk = max98088_dai_set_sysclk,
1654 .set_fmt = max98088_dai1_set_fmt,
1655 .hw_params = max98088_dai1_hw_params,
1656 .digital_mute = max98088_dai1_digital_mute,
1660 .set_sysclk = max98088_dai_set_sysclk,
1661 .set_fmt = max98088_dai2_set_fmt,
1662 .hw_params = max98088_dai2_hw_params,
1663 .digital_mute = max98088_dai2_digital_mute,
1670 .stream_name =
"HiFi Playback",
1677 .stream_name =
"HiFi Capture",
1683 .ops = &max98088_dai1_ops,
1688 .stream_name =
"Aux Playback",
1694 .ops = &max98088_dai2_ops,
1698 static const char *eq_mode_name[] = {
"EQ1 Mode",
"EQ2 Mode"};
1704 for (i = 0; i <
ARRAY_SIZE(eq_mode_name); i++)
1705 if (
strcmp(name, eq_mode_name[i]) == 0)
1709 dev_err(codec->
dev,
"Bad EQ channel name '%s'\n", name);
1715 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1718 int best, best_val, save,
i,
sel,
fs;
1721 cdata = &max98088->
dai[0];
1732 for (i = 0; i < pdata->
eq_cfgcnt; i++) {
1734 abs(pdata->
eq_cfg[i].rate - fs) < best_val) {
1736 best_val =
abs(pdata->
eq_cfg[i].rate - fs);
1740 dev_dbg(codec->
dev,
"Selected %s/%dHz for %dHz sample rate\n",
1741 pdata->
eq_cfg[best].name,
1742 pdata->
eq_cfg[best].rate, fs);
1750 m98088_eq_band(codec, 0, 0, coef_set->
band1);
1751 m98088_eq_band(codec, 0, 1, coef_set->
band2);
1752 m98088_eq_band(codec, 0, 2, coef_set->
band3);
1753 m98088_eq_band(codec, 0, 3, coef_set->
band4);
1754 m98088_eq_band(codec, 0, 4, coef_set->
band5);
1762 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1765 int best, best_val, save,
i,
sel,
fs;
1768 cdata = &max98088->
dai[1];
1779 for (i = 0; i < pdata->
eq_cfgcnt; i++) {
1781 abs(pdata->
eq_cfg[i].rate - fs) < best_val) {
1783 best_val =
abs(pdata->
eq_cfg[i].rate - fs);
1787 dev_dbg(codec->
dev,
"Selected %s/%dHz for %dHz sample rate\n",
1788 pdata->
eq_cfg[best].name,
1789 pdata->
eq_cfg[best].rate, fs);
1797 m98088_eq_band(codec, 1, 0, coef_set->
band1);
1798 m98088_eq_band(codec, 1, 1, coef_set->
band2);
1799 m98088_eq_band(codec, 1, 2, coef_set->
band3);
1800 m98088_eq_band(codec, 1, 3, coef_set->
band4);
1801 m98088_eq_band(codec, 1, 4, coef_set->
band5);
1808 static int max98088_put_eq_enum(
struct snd_kcontrol *kcontrol,
1812 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1814 int channel = max98088_get_channel(codec, kcontrol->
id.name);
1816 int sel = ucontrol->
value.integer.value[0];
1830 max98088_setup_eq1(codec);
1833 max98088_setup_eq2(codec);
1840 static int max98088_get_eq_enum(
struct snd_kcontrol *kcontrol,
1844 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1845 int channel = max98088_get_channel(codec, kcontrol->
id.name);
1852 ucontrol->
value.enumerated.item[0] = cdata->
eq_sel;
1856 static void max98088_handle_eq_pdata(
struct snd_soc_codec *codec)
1858 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1861 unsigned int cfgcnt;
1868 max98088_get_eq_enum,
1869 max98088_put_eq_enum),
1872 max98088_get_eq_enum,
1873 max98088_put_eq_enum),
1885 for (i = 0; i < cfgcnt; i++) {
1913 dev_err(codec->
dev,
"Failed to add EQ control: %d\n", ret);
1916 static void max98088_handle_pdata(
struct snd_soc_codec *codec)
1918 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1934 max98088->
digmic = (regval ? 1 : 0);
1945 max98088_handle_eq_pdata(codec);
1963 #define max98088_suspend NULL
1964 #define max98088_resume NULL
1969 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1977 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
1983 max98088->
sysclk = (unsigned)-1;
1986 cdata = &max98088->
dai[0];
1987 cdata->
rate = (unsigned)-1;
1988 cdata->
fmt = (unsigned)-1;
1991 cdata = &max98088->
dai[1];
1992 cdata->
rate = (unsigned)-1;
1993 cdata->
fmt = (unsigned)-1;
2005 dev_err(codec->
dev,
"Failed to read device revision: %d\n",
2031 max98088_handle_pdata(codec);
2042 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
2051 .probe = max98088_probe,
2052 .remove = max98088_remove,
2055 .set_bias_level = max98088_set_bias_level,
2057 .reg_word_size =
sizeof(
u8),
2062 .dapm_routes = max98088_audio_map,
2063 .num_dapm_routes =
ARRAY_SIZE(max98088_audio_map),
2066 static int max98088_i2c_probe(
struct i2c_client *i2c,
2074 if (max98088 ==
NULL)
2077 max98088->
devtype =
id->driver_data;
2079 i2c_set_clientdata(i2c, max98088);
2080 max98088->
pdata = i2c->
dev.platform_data;
2083 &soc_codec_dev_max98088, &max98088_dai[0], 2);
2100 static struct i2c_driver max98088_i2c_driver = {
2105 .probe = max98088_i2c_probe,
2107 .id_table = max98088_i2c_id,