13 #include <linux/module.h>
18 #include <linux/i2c.h>
21 #include <linux/slab.h>
30 #include <asm/div64.h>
259 static const char *da732x_hpf_mode[] = {
260 "Disable",
"Music",
"Voice",
263 static const char *da732x_hpf_music[] = {
264 "1.8Hz",
"3.75Hz",
"7.5Hz",
"15Hz",
267 static const char *da732x_hpf_voice[] = {
268 "2.5Hz",
"25Hz",
"50Hz",
"100Hz",
269 "150Hz",
"200Hz",
"300Hz",
"400Hz"
272 static const struct soc_enum da732x_dac1_hpf_mode_enum[] = {
277 static const struct soc_enum da732x_dac2_hpf_mode_enum[] = {
282 static const struct soc_enum da732x_dac3_hpf_mode_enum[] = {
287 static const struct soc_enum da732x_adc1_hpf_mode_enum[] = {
292 static const struct soc_enum da732x_adc2_hpf_mode_enum[] = {
297 static const struct soc_enum da732x_dac1_hp_filter_enum[] = {
302 static const struct soc_enum da732x_dac2_hp_filter_enum[] = {
307 static const struct soc_enum da732x_dac3_hp_filter_enum[] = {
312 static const struct soc_enum da732x_adc1_hp_filter_enum[] = {
317 static const struct soc_enum da732x_adc2_hp_filter_enum[] = {
322 static const struct soc_enum da732x_dac1_voice_filter_enum[] = {
327 static const struct soc_enum da732x_dac2_voice_filter_enum[] = {
332 static const struct soc_enum da732x_dac3_voice_filter_enum[] = {
337 static const struct soc_enum da732x_adc1_voice_filter_enum[] = {
342 static const struct soc_enum da732x_adc2_voice_filter_enum[] = {
348 static int da732x_hpf_set(
struct snd_kcontrol *kcontrol,
353 unsigned int reg = enum_ctrl->
reg;
354 unsigned int sel = ucontrol->
value.integer.value[0];
376 static int da732x_hpf_get(
struct snd_kcontrol *kcontrol,
381 unsigned int reg = enum_ctrl->
reg;
476 da732x_dac1_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
477 SOC_ENUM(
"DAC1 High Pass Filter", da732x_dac1_hp_filter_enum),
478 SOC_ENUM(
"DAC1 Voice Filter", da732x_dac1_voice_filter_enum),
481 da732x_dac2_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
482 SOC_ENUM(
"DAC2 High Pass Filter", da732x_dac2_hp_filter_enum),
483 SOC_ENUM(
"DAC2 Voice Filter", da732x_dac2_voice_filter_enum),
486 da732x_dac3_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
487 SOC_ENUM(
"DAC3 High Pass Filter", da732x_dac3_hp_filter_enum),
488 SOC_ENUM(
"DAC3 Filter Mode", da732x_dac3_voice_filter_enum),
491 da732x_adc1_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
492 SOC_ENUM(
"ADC1 High Pass Filter", da732x_adc1_hp_filter_enum),
493 SOC_ENUM(
"ADC1 Voice Filter", da732x_adc1_voice_filter_enum),
496 da732x_adc2_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
497 SOC_ENUM(
"ADC2 High Pass Filter", da732x_adc2_hp_filter_enum),
498 SOC_ENUM(
"ADC2 Voice Filter", da732x_adc2_voice_filter_enum),
703 static const char *adcl_text[] = {
707 static const char *adcr_text[] = {
708 "AUX1R",
"MIC2",
"MIC3"
711 static const char *enable_text[] = {
717 static const struct soc_enum adc1l_enum =
724 static const struct soc_enum adc1r_enum =
731 static const struct soc_enum adc2l_enum =
738 static const struct soc_enum adc2r_enum =
745 static const struct soc_enum da732x_hp_left_output =
752 static const struct soc_enum da732x_hp_right_output =
759 static const struct soc_enum da732x_speaker_output =
766 static const struct soc_enum da732x_lout4_output =
773 static const struct soc_enum da732x_lout2_output =
855 0,
NULL, 0, da732x_out_pga_event,
858 0,
NULL, 0, da732x_out_pga_event,
861 0,
NULL, 0, da732x_out_pga_event,
864 0,
NULL, 0, da732x_out_pga_event,
867 0,
NULL, 0, da732x_out_pga_event,
896 {
"AUX1L PGA",
"NULL",
"AUX1L"},
897 {
"AUX1R PGA",
"NULL",
"AUX1R"},
898 {
"MIC1 PGA",
NULL,
"MIC1"},
899 {
"MIC2 PGA",
"NULL",
"MIC2"},
900 {
"MIC3 PGA",
"NULL",
"MIC3"},
903 {
"ADC1 Left MUX",
"MIC1",
"MIC1 PGA"},
904 {
"ADC1 Left MUX",
"AUX1L",
"AUX1L PGA"},
906 {
"ADC1 Right MUX",
"AUX1R",
"AUX1R PGA"},
907 {
"ADC1 Right MUX",
"MIC2",
"MIC2 PGA"},
908 {
"ADC1 Right MUX",
"MIC3",
"MIC3 PGA"},
910 {
"ADC2 Left MUX",
"AUX1L",
"AUX1L PGA"},
911 {
"ADC2 Left MUX",
"MIC1",
"MIC1 PGA"},
913 {
"ADC2 Right MUX",
"AUX1R",
"AUX1R PGA"},
914 {
"ADC2 Right MUX",
"MIC2",
"MIC2 PGA"},
915 {
"ADC2 Right MUX",
"MIC3",
"MIC3 PGA"},
917 {
"ADC1L",
NULL,
"ADC1 Supply"},
918 {
"ADC1R",
NULL,
"ADC1 Supply"},
919 {
"ADC2L",
NULL,
"ADC2 Supply"},
920 {
"ADC2R",
NULL,
"ADC2 Supply"},
922 {
"ADC1L",
NULL,
"ADC1 Left MUX"},
923 {
"ADC1R",
NULL,
"ADC1 Right MUX"},
924 {
"ADC2L",
NULL,
"ADC2 Left MUX"},
925 {
"ADC2R",
NULL,
"ADC2 Right MUX"},
927 {
"AIFA Output",
NULL,
"ADC1L"},
928 {
"AIFA Output",
NULL,
"ADC1R"},
929 {
"AIFB Output",
NULL,
"ADC2L"},
930 {
"AIFB Output",
NULL,
"ADC2R"},
932 {
"HP Left MUX",
"Enabled",
"AIFA Input"},
933 {
"HP Right MUX",
"Enabled",
"AIFA Input"},
934 {
"Speaker MUX",
"Enabled",
"AIFB Input"},
935 {
"LOUT2 MUX",
"Enabled",
"AIFB Input"},
936 {
"LOUT4 MUX",
"Enabled",
"AIFB Input"},
938 {
"DAC1L",
NULL,
"DAC1 CLK"},
939 {
"DAC1R",
NULL,
"DAC1 CLK"},
940 {
"DAC2L",
NULL,
"DAC2 CLK"},
941 {
"DAC2R",
NULL,
"DAC2 CLK"},
942 {
"DAC3",
NULL,
"DAC3 CLK"},
944 {
"DAC1L",
NULL,
"HP Left MUX"},
945 {
"DAC1R",
NULL,
"HP Right MUX"},
946 {
"DAC2L",
NULL,
"Speaker MUX"},
947 {
"DAC2R",
NULL,
"LOUT4 MUX"},
948 {
"DAC3",
NULL,
"LOUT2 MUX"},
951 {
"HP Left",
NULL,
"DAC1L"},
952 {
"HP Right",
NULL,
"DAC1R"},
953 {
"LIN3",
NULL,
"DAC2L"},
954 {
"LIN4",
NULL,
"DAC2R"},
955 {
"LIN2",
NULL,
"DAC3"},
958 {
"ClassD",
NULL,
"LIN3"},
959 {
"LOUTL",
NULL,
"LIN2"},
960 {
"LOUTR",
NULL,
"LIN4"},
961 {
"HPL",
NULL,
"HP Left"},
962 {
"HPR",
NULL,
"HP Right"},
974 reg_aif = dai->
driver->base;
1040 u32 aif_mclk, pc_count;
1092 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1107 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1138 static int da732x_set_dai_pll(
struct snd_soc_codec *codec,
int pll_id,
1139 int source,
unsigned int freq_in,
1140 unsigned int freq_out)
1142 struct da732x_priv *da732x = snd_soc_codec_get_drvdata(codec);
1144 u8 div_lo, div_mid, div_hi;
1148 if (freq_out == 0) {
1160 switch (da732x->
sysclk) {
1172 "Cannot use PLL Bypass, invalid SYSCLK rate\n");
1177 indiv = da732x_get_input_div(codec, da732x->
sysclk);
1181 fref = (da732x->
sysclk / indiv);
1182 div_hi = freq_out / fref;
1183 frac_div = (
u64)(freq_out % fref) * 8192ULL;
1200 static int da732x_set_dai_sysclk(
struct snd_soc_dai *dai,
int clk_id,
1201 unsigned int freq,
int dir)
1204 struct da732x_priv *da732x = snd_soc_codec_get_drvdata(codec);
1211 #define DA732X_RATES SNDRV_PCM_RATE_8000_96000
1213 #define DA732X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1214 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1217 .hw_params = da732x_hw_params,
1218 .set_fmt = da732x_set_dai_fmt,
1219 .set_sysclk = da732x_set_dai_sysclk,
1223 .hw_params = da732x_hw_params,
1224 .set_fmt = da732x_set_dai_fmt,
1225 .set_sysclk = da732x_set_dai_sysclk,
1230 .name =
"DA732X_AIFA",
1234 .stream_name =
"AIFA Playback",
1241 .stream_name =
"AIFA Capture",
1247 .ops = &da732x_dai1_ops,
1250 .name =
"DA732X_AIFB",
1254 .stream_name =
"AIFB Playback",
1261 .stream_name =
"AIFB Capture",
1267 .ops = &da732x_dai2_ops,
1271 static const struct regmap_config da732x_regmap = {
1276 .reg_defaults = da732x_reg_cache,
1277 .num_reg_defaults =
ARRAY_SIZE(da732x_reg_cache),
1282 static void da732x_dac_offset_adjust(
struct snd_soc_codec *codec)
1346 static void da732x_output_offset_adjust(
struct snd_soc_codec *codec)
1405 static void da732x_hp_dc_offset_cancellation(
struct snd_soc_codec *codec)
1418 da732x_dac_offset_adjust(codec);
1419 da732x_output_offset_adjust(codec);
1426 static int da732x_set_bias_level(
struct snd_soc_codec *codec,
1429 struct da732x_priv *da732x = snd_soc_codec_get_drvdata(codec);
1488 da732x_hp_dc_offset_cancellation(codec);
1517 struct da732x_priv *da732x = snd_soc_codec_get_drvdata(codec);
1529 dev_err(codec->
dev,
"Failed to register codec.\n");
1547 .probe = da732x_probe,
1548 .remove = da732x_remove,
1549 .set_bias_level = da732x_set_bias_level,
1550 .controls = da732x_snd_controls,
1551 .num_controls =
ARRAY_SIZE(da732x_snd_controls),
1552 .dapm_widgets = da732x_dapm_widgets,
1553 .num_dapm_widgets =
ARRAY_SIZE(da732x_dapm_widgets),
1554 .dapm_routes = da732x_dapm_routes,
1555 .num_dapm_routes =
ARRAY_SIZE(da732x_dapm_routes),
1556 .set_pll = da732x_set_dai_pll,
1557 .reg_cache_size =
ARRAY_SIZE(da732x_reg_cache),
1572 i2c_set_clientdata(i2c, da732x);
1575 if (IS_ERR(da732x->
regmap)) {
1576 ret = PTR_ERR(da732x->
regmap);
1577 dev_err(&i2c->
dev,
"Failed to initialize regmap\n");
1583 dev_err(&i2c->
dev,
"Failed to read ID register: %d\n", ret);
1593 dev_err(&i2c->
dev,
"Failed to register codec.\n");
1612 static struct i2c_driver da732x_i2c_driver = {
1617 .probe = da732x_i2c_probe,
1619 .id_table = da732x_i2c_id,