diff --git a/sound/soc/codecs/es7210.c b/sound/soc/codecs/es7210.c index 402387ec6..8d5d3a245 100644 --- a/sound/soc/codecs/es7210.c +++ b/sound/soc/codecs/es7210.c @@ -46,11 +46,8 @@ #define MIC_CHN_2 2 #define ES7210_TDM_ENABLE ENABLE -//#define ES7210_CHANNELS_MAX MIC_CHN_8 +#define ES7210_CHANNELS_MAX MIC_CHN_2 -static int ADC_DEV_MAXNUM = 1; -static int ES7210_CHANNELS_MAX = 1; -#if 0 #if ES7210_CHANNELS_MAX == MIC_CHN_2 #define ADC_DEV_MAXNUM 1 #endif @@ -75,7 +72,6 @@ static int ES7210_CHANNELS_MAX = 1; #if ES7210_CHANNELS_MAX == MIC_CHN_16 #define ADC_DEV_MAXNUM 4 #endif -#endif #define ES7210_TDM_1LRCK_DSPA 0 #define ES7210_TDM_1LRCK_DSPB 1 @@ -87,7 +83,7 @@ static int ES7210_CHANNELS_MAX = 1; #define ES7210_TDM_NLRCK_LJ 7 #define ES7210_NORMAL_I2S 8 -#define ES7210_WORK_MODE ES7210_TDM_1LRCK_DSPB +#define ES7210_WORK_MODE ES7210_NORMAL_I2S #define ES7210_I2C_BUS_NUM 1 @@ -104,16 +100,26 @@ static int ES7210_CHANNELS_MAX = 1; #define RATIO_128 0x01 #define RATIO_64 0x41 /* mclk from bclk pin */ -#define ES7210_MCLK_LRCK_RATIO RATIO_256 // mclk=sclk. mclk/lrck = sclk / lrck = 16bit*4slot=RATIO_64. 32bit*4slot=16bit*8slot=RATIO_128 32bit*8slot=RATIO_256 +#define ES7210_MCLK_LRCK_RATIO RATIO_64 -struct i2c_client *i2c_clt1[4] = {0}; +struct i2c_client *i2c_clt1[ADC_DEV_MAXNUM]; struct es7210_priv *resume_es7210 = NULL; -struct snd_soc_component *tron_codec1[4]; +/* codec private data */ +struct es7210_priv { + struct regmap *regmap; + struct i2c_client *i2c_client; + unsigned int dmic_enable; + unsigned int sysclk; + struct clk *mclk; + struct snd_pcm_hw_constraint_list *sysclk_constraints; + unsigned int tdm_mode; + struct delayed_work pcm_pop_work; +}; +struct snd_soc_component *tron_codec1[ADC_DEV_MAXNUM]; int es7210_init_reg = 0; -int es7210_hw_param_reg = 0; static int es7210_codec_num = 0; static const struct regmap_config es7210_regmap_config = { @@ -156,6 +162,9 @@ static const struct es7210_reg_config es7210_tdm_reg_fmt_cfg[] = { }; static const struct es7210_reg_config es7210_tdm_reg_common_cfg2[] = { { 0x40, 0xC3 }, + { 0x14, 0x3C }, + { 0x15, 0x3C }, + { 0x17, 0x00 }, { 0x41, 0x70 }, { 0x42, 0x70 }, { 0x43, 0x1E }, @@ -277,150 +286,6 @@ static int es7210_set_dai_fmt(struct snd_soc_dai *codec_dai, { return 0; } -static void es7210_tdm_init_ratio(struct es7210_priv *priv) -{ - int cnt, channel, i; - - if (priv->tdm_mode == ES7210_TDM_1LRCK_DSPB) { - if (priv->pcm_format == SNDRV_PCM_FORMAT_S16_LE) { - priv->mclk_lrck_ratio = RATIO_128; - } else if (priv->pcm_format == SNDRV_PCM_FORMAT_S32_LE) { - priv->mclk_lrck_ratio = RATIO_256; - } else { - pr_err("unsupported format in es7210 tdm mode!"); - } - } else { // ratio remain default for i2s - priv->mclk_lrck_ratio = RATIO_768; - } - - switch (priv->tdm_mode) { - case ES7210_TDM_1LRCK_DSPA: - case ES7210_TDM_1LRCK_DSPB: - case ES7210_TDM_1LRCK_I2S: - case ES7210_TDM_1LRCK_LJ: - case ES7210_NORMAL_I2S: - /* - * to set internal mclk - * here, we assume that cpu/soc always provides - * 256FS i2s clock - * to es7210. - * dll bypassed, use clock doubler to get double - * frequency for - * internal modem which need - * 512FS clock. the clk divider ratio is 1. - * user must modify the setting of register0x02 - * according to FS - * ratio provided by CPU/SOC. - */ - - for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) { - es7210_write(ES7210_MCLK_CTL_REG02, - priv->mclk_lrck_ratio, i2c_clt1[cnt]); - } - // es7210_multi_chips_write(ES7210_MCLK_CTL_REG02, - // 0xc1); - break; - case ES7210_TDM_NLRCK_DSPA: - case ES7210_TDM_NLRCK_DSPB: - case ES7210_TDM_NLRCK_I2S: - case ES7210_TDM_NLRCK_LJ: - /* - * Here to set TDM format for DSP-A with - * multiple LRCK TDM mode - */ - channel = ES7210_CHANNELS_MAX; - /* - * Set the microphone numbers in array - */ - switch (channel) { - case 2: - /* ES7210_CHANNELS_MAX=2 */ - es7210_multi_chips_write( - ES7210_MODE_CFG_REG08, 0x10); - break; - case 4: - /* ES7210_CHANNELS_MAX=4 */ - es7210_multi_chips_write( - ES7210_MODE_CFG_REG08, 0x20); - break; - case 6: - /* ES7210_CHANNELS_MAX=6 */ - es7210_multi_chips_write( - ES7210_MODE_CFG_REG08, 0x30); - break; - case 8: - /* ES7210_CHANNELS_MAX=8 */ - es7210_multi_chips_write( - ES7210_MODE_CFG_REG08, 0x40); - break; - case 10: - /* ES7210_CHANNELS_MAX=10 */ - es7210_multi_chips_write( - ES7210_MODE_CFG_REG08, 0x50); - break; - case 12: - /* ES7210_CHANNELS_MAX=12 */ - es7210_multi_chips_write( - ES7210_MODE_CFG_REG08, 0x60); - break; - case 14: - /* ES7210_CHANNELS_MAX=14 */ - es7210_multi_chips_write( - ES7210_MODE_CFG_REG08, 0x70); - break; - case 16: - /* ES7210_CHANNELS_MAX=16 */ - es7210_multi_chips_write( - ES7210_MODE_CFG_REG08, 0x80); - break; - default: - break; - } - /* - * to set internal mclk - * here, we assume that cpu/soc always provides - * 256FS i2s clock - * to es7210 and there is four - * es7210 devices in tdm link. so the - * internal FS in es7210 - * is only FS/4; - * dll bypassed, clock doubler bypassed. the clk - * divider ratio is - * 2. so the clock of internal - * modem equals to (256FS / (FS/4) / 2) * FS - * = 512FS - * user must modify the setting of register0x02 - * according to FS - * ratio provided by CPU/SOC. - */ - - es7210_multi_chips_write(ES7210_MCLK_CTL_REG02, - priv->mclk_lrck_ratio);// NFS MODE:RATIO_768 ,12.288M/48K(16K 6 CH),12.288M/64K(16K 8 CH) - break; - default: - /* - * to set internal mclk for normal mode - * here, we assume that cpu/soc always provides - * 256FS i2s clock - * to es7210. - * dll bypassed, use clock doubler to get double - * frequency for - * internal modem which need - * 512FS clock. the clk divider ratio is 1. - * user must modify the setting of register0x02 - * according to FS - * ratio provided by CPU/SOC. - */ - for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) { - es7210_write(ES7210_MCLK_CTL_REG02, - priv->mclk_lrck_ratio, i2c_clt1[cnt]); - } - - break; - } - return; -} - /* * to initialize es7210 for tdm mode */ @@ -437,7 +302,9 @@ static void es7210_tdm_init_codec(u8 mode) es7210_tdm_reg_common_cfg1[cnt].reg_v); } if(DOUBLESPEED) - es7210_multi_chips_update_bits(ES7210_MODE_CFG_REG08, 0x02, 0x02); + es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x16); + else + es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x14); switch (mode) { case ES7210_TDM_1LRCK_DSPA: @@ -457,7 +324,7 @@ static void es7210_tdm_init_codec(u8 mode) */ for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) { es7210_write(ES7210_SDP_CFG1_REG11, - 0x73, i2c_clt1[cnt]); + 0x83, i2c_clt1[cnt]); es7210_write(ES7210_SDP_CFG2_REG12, 0x01, i2c_clt1[cnt]); } @@ -518,7 +385,7 @@ static void es7210_tdm_init_codec(u8 mode) */ for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) { es7210_write(ES7210_SDP_CFG1_REG11, - 0x73, i2c_clt1[cnt]); + 0x83, i2c_clt1[cnt]); } for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) { if (cnt == 0) { @@ -624,7 +491,134 @@ static void es7210_tdm_init_codec(u8 mode) es7210_tdm_reg_common_cfg2[cnt].reg_addr, es7210_tdm_reg_common_cfg2[cnt].reg_v); } + es7210_multi_chips_write(0x4, 0x00); + es7210_multi_chips_write(0x5, 0x40); + switch (mode) { + case ES7210_TDM_1LRCK_DSPA: + case ES7210_TDM_1LRCK_DSPB: + case ES7210_TDM_1LRCK_I2S: + case ES7210_TDM_1LRCK_LJ: + case ES7210_NORMAL_I2S: + /* + * to set internal mclk + * here, we assume that cpu/soc always provides + * 256FS i2s clock + * to es7210. + * dll bypassed, use clock doubler to get double + * frequency for + * internal modem which need + * 512FS clock. the clk divider ratio is 1. + * user must modify the setting of register0x02 + * according to FS + * ratio provided by CPU/SOC. + */ + + for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) { + es7210_write(ES7210_MCLK_CTL_REG02, + ES7210_MCLK_LRCK_RATIO, i2c_clt1[cnt]); + } + // es7210_multi_chips_write(ES7210_MCLK_CTL_REG02, + // 0xc1); + break; + case ES7210_TDM_NLRCK_DSPA: + case ES7210_TDM_NLRCK_DSPB: + case ES7210_TDM_NLRCK_I2S: + case ES7210_TDM_NLRCK_LJ: + /* + * Here to set TDM format for DSP-A with + * multiple LRCK TDM mode + */ + channel = ES7210_CHANNELS_MAX; + /* + * Set the microphone numbers in array + */ + switch (channel) { + case 2: + /* ES7210_CHANNELS_MAX=2 */ + es7210_multi_chips_write( + ES7210_MODE_CFG_REG08, 0x10); + break; + case 4: + /* ES7210_CHANNELS_MAX=4 */ + es7210_multi_chips_write( + ES7210_MODE_CFG_REG08, 0x20); + break; + case 6: + /* ES7210_CHANNELS_MAX=6 */ + es7210_multi_chips_write( + ES7210_MODE_CFG_REG08, 0x30); + break; + case 8: + /* ES7210_CHANNELS_MAX=8 */ + es7210_multi_chips_write( + ES7210_MODE_CFG_REG08, 0x40); + break; + case 10: + /* ES7210_CHANNELS_MAX=10 */ + es7210_multi_chips_write( + ES7210_MODE_CFG_REG08, 0x50); + break; + case 12: + /* ES7210_CHANNELS_MAX=12 */ + es7210_multi_chips_write( + ES7210_MODE_CFG_REG08, 0x60); + break; + case 14: + /* ES7210_CHANNELS_MAX=14 */ + es7210_multi_chips_write( + ES7210_MODE_CFG_REG08, 0x70); + break; + case 16: + /* ES7210_CHANNELS_MAX=16 */ + es7210_multi_chips_write( + ES7210_MODE_CFG_REG08, 0x80); + break; + default: + break; + } + /* + * to set internal mclk + * here, we assume that cpu/soc always provides + * 256FS i2s clock + * to es7210 and there is four + * es7210 devices in tdm link. so the + * internal FS in es7210 + * is only FS/4; + * dll bypassed, clock doubler bypassed. the clk + * divider ratio is + * 2. so the clock of internal + * modem equals to (256FS / (FS/4) / 2) * FS + * = 512FS + * user must modify the setting of register0x02 + * according to FS + * ratio provided by CPU/SOC. + */ + + es7210_multi_chips_write(ES7210_MCLK_CTL_REG02, + ES7210_MCLK_LRCK_RATIO);// NFS MODE:RATIO_768 ,12.288M/48K(16K 6 CH),12.288M/64K(16K 8 CH) + break; + default: + /* + * to set internal mclk for normal mode + * here, we assume that cpu/soc always provides + * 256FS i2s clock + * to es7210. + * dll bypassed, use clock doubler to get double + * frequency for + * internal modem which need + * 512FS clock. the clk divider ratio is 1. + * user must modify the setting of register0x02 + * according to FS + * ratio provided by CPU/SOC. + */ + for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) { + es7210_write(ES7210_MCLK_CTL_REG02, + ES7210_MCLK_LRCK_RATIO, i2c_clt1[cnt]); + } + + break; + } for (cnt = 0; cnt < sizeof(es7210_tdm_reg_common_cfg3) / sizeof(es7210_tdm_reg_common_cfg3[0]); @@ -657,53 +651,52 @@ static void es7210_tdm_init_codec(u8 mode) } if (i == 1) { /* set second es7210 PGA GAIN */ - es7210_write(ES7210_MIC1_GAIN_REG43, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC1_GAIN_REG43, ES7210_AEC_GAIN, i2c_clt1[i]); - es7210_write(ES7210_MIC2_GAIN_REG44, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC2_GAIN_REG44, ES7210_AEC_GAIN, i2c_clt1[i]); - es7210_write(ES7210_MIC3_GAIN_REG45, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC3_GAIN_REG45, ES7210_AEC_GAIN, i2c_clt1[i]); - es7210_write(ES7210_MIC4_GAIN_REG46, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC4_GAIN_REG46, ES7210_AEC_GAIN, i2c_clt1[i]); } if (i == 2) { /* set third es7210 PGA GAIN */ - es7210_write(ES7210_MIC1_GAIN_REG43, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC1_GAIN_REG43, ES7210_AEC_GAIN, i2c_clt1[i]); - es7210_write(ES7210_MIC2_GAIN_REG44, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC2_GAIN_REG44, ES7210_AEC_GAIN, i2c_clt1[i]); - es7210_write(ES7210_MIC3_GAIN_REG45, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC3_GAIN_REG45, ES7210_AEC_GAIN, i2c_clt1[i]); - es7210_write(ES7210_MIC4_GAIN_REG46, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC4_GAIN_REG46, ES7210_AEC_GAIN, i2c_clt1[i]); } if (i == 3) { /* set third es7210 PGA GAIN */ - es7210_write(ES7210_MIC1_GAIN_REG43, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC1_GAIN_REG43, ES7210_AEC_GAIN, i2c_clt1[i]); - es7210_write(ES7210_MIC2_GAIN_REG44, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC2_GAIN_REG44, ES7210_AEC_GAIN, i2c_clt1[i]); - es7210_write(ES7210_MIC3_GAIN_REG45, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC3_GAIN_REG45, ES7210_AEC_GAIN, i2c_clt1[i]); - es7210_write(ES7210_MIC4_GAIN_REG46, ES7210_MIC_GAIN, + es7210_write(ES7210_MIC4_GAIN_REG46, ES7210_AEC_GAIN, i2c_clt1[i]); } } } static void es7210_unmute(void) { + printk("enter into %s\n", __func__); es7210_multi_chips_update_bits(ES7210_ADC34_MUTE_REG14, 0x03, 0x00); es7210_multi_chips_update_bits(ES7210_ADC12_MUTE_REG15, 0x03, 0x00); - es7210_multi_chips_update_bits(ES7210_MIC1_GAIN_REG43, 0x1f, ES7210_MIC_GAIN); - es7210_multi_chips_update_bits(ES7210_MIC2_GAIN_REG44, 0x1f, ES7210_MIC_GAIN); - es7210_multi_chips_update_bits(ES7210_MIC3_GAIN_REG45, 0x1f, ES7210_MIC_GAIN); - es7210_multi_chips_update_bits(ES7210_MIC4_GAIN_REG46, 0x1f, ES7210_MIC_GAIN); } static void pcm_pop_work_events(struct work_struct *work) { + printk("enter into %s\n", __func__); es7210_unmute(); + es7210_init_reg = 1; } static int es7210_pcm_startup(struct snd_pcm_substream *substream, @@ -713,7 +706,6 @@ static int es7210_pcm_startup(struct snd_pcm_substream *substream, struct es7210_priv *es7210 = snd_soc_component_get_drvdata(component); if (es7210_init_reg == 0) { - es7210_init_reg = 1; schedule_delayed_work(&es7210->pcm_pop_work, msecs_to_jiffies(100)); } return 0; @@ -722,22 +714,13 @@ static int es7210_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { - struct snd_soc_component *component = dai->component; - struct es7210_priv *priv = snd_soc_component_get_drvdata(component); + int i; - if (es7210_hw_param_reg == 1 && params_format(params) == priv->pcm_format) { - return 0; - } - - es7210_hw_param_reg = 1; - priv->pcm_format = params_format(params); - es7210_tdm_init_ratio(priv); - es7210_multi_chips_update_bits(ES7210_RESET_CTL_REG00, 0x30, 0x30); for (i = 0; i < ADC_DEV_MAXNUM; i++) { /* set es7210 bit size */ - switch (priv->pcm_format) { + switch (params_format(params)) { case SNDRV_PCM_FORMAT_S16_LE: es7210_update_bits(0x11, 0xE0, 0x60, i2c_clt1[i]); @@ -770,7 +753,6 @@ static int es7210_pcm_hw_params(struct snd_pcm_substream *substream, default: break; } - return 0; } @@ -785,7 +767,7 @@ static struct snd_soc_dai_ops es7210_ops = { .set_fmt = es7210_set_dai_fmt, .set_sysclk = es7210_set_dai_sysclk, }; - +#if ES7210_CHANNELS_MAX > 0 static struct snd_soc_dai_driver es7210_dai0 = { .name = "ES7210 ADC 0", .capture = { @@ -798,8 +780,8 @@ static struct snd_soc_dai_driver es7210_dai0 = { .ops = &es7210_ops, .symmetric_rates = 1, }; - - +#endif +#if ES7210_CHANNELS_MAX > 4 static struct snd_soc_dai_driver es7210_dai1 = { .name = "ES7210 4CH ADC 1", .capture = { @@ -812,7 +794,8 @@ static struct snd_soc_dai_driver es7210_dai1 = { .ops = &es7210_ops, .symmetric_rates = 1, }; - +#endif +#if ES7210_CHANNELS_MAX > 8 static struct snd_soc_dai_driver es7210_dai2 = { .name = "ES7210 4CH ADC 2", .capture = { @@ -825,7 +808,8 @@ static struct snd_soc_dai_driver es7210_dai2 = { .ops = &es7210_ops, .symmetric_rates = 1, }; - +#endif +#if ES7210_CHANNELS_MAX > 12 static struct snd_soc_dai_driver es7210_dai3 = { .name = "ES7210 4CH ADC 3", .capture = { @@ -838,12 +822,20 @@ static struct snd_soc_dai_driver es7210_dai3 = { .ops = &es7210_ops, .symmetric_rates = 1, }; - +#endif static struct snd_soc_dai_driver *es7210_dai[] = { +#if ES7210_CHANNELS_MAX > 0 &es7210_dai0, +#endif +#if ES7210_CHANNELS_MAX > 4 &es7210_dai1, +#endif +#if ES7210_CHANNELS_MAX > 8 &es7210_dai2, +#endif +#if ES7210_CHANNELS_MAX > 12 &es7210_dai3, +#endif }; static int es7210_suspend(struct snd_soc_component *component) @@ -894,7 +886,7 @@ static int es7210_resume(struct snd_soc_component *component) static int es7210_probe(struct snd_soc_component *component) { struct es7210_priv *es7210 = snd_soc_component_get_drvdata(component); - u8 val, val1, cnt; + u8 val, val1; int ret = 0; resume_es7210 = es7210; @@ -904,18 +896,15 @@ static int es7210_probe(struct snd_soc_component *component) } tron_codec1[es7210_codec_num++] = component; - INIT_DELAYED_WORK(&es7210->pcm_pop_work, pcm_pop_work_events); - - for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) { - /* es7210 chip id */ - ret = es7210_read(0x3D, &val, i2c_clt1[cnt]); - ret = es7210_read(0x3E, &val1, i2c_clt1[cnt]); - if (ret < 0) { - pr_err("%s: read chipid failed %d\n", __func__, ret); - goto exit_i2c_check_id_failed; - } - } + + /* es7210 chip id */ + ret = es7210_read(0x3D, &val, i2c_clt1[0]); + ret = es7210_read(0x3E, &val1, i2c_clt1[0]); + if (ret < 0) { + pr_err("%s: read chipid failed %d\n", __func__, ret); + goto exit_i2c_check_id_failed; + } es7210_tdm_init_codec(es7210->tdm_mode); @@ -945,6 +934,7 @@ static int es7210_set_bias_level(struct snd_soc_component *component, static const DECLARE_TLV_DB_SCALE(mic_boost_tlv, 0, 300, 0); +#if ES7210_CHANNELS_MAX > 0 static int es7210_micboost1_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { @@ -1075,11 +1065,12 @@ static int es7210_adc4_mute_get(struct snd_kcontrol *kcontrol, return 0; } +#endif + +#if ES7210_CHANNELS_MAX > 4 static int es7210_micboost5_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[1] == NULL) - return 0; es7210_update_bits(0x43, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[1]); return 0; } @@ -1088,8 +1079,6 @@ static int es7210_micboost5_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[1] == NULL) - return 0; es7210_read(0x43, &val, i2c_clt1[1]); ucontrol->value.integer.value[0] = val; return 0; @@ -1097,8 +1086,6 @@ static int es7210_micboost5_setting_get(struct snd_kcontrol *kcontrol, static int es7210_micboost6_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[1] == NULL) - return 0; es7210_update_bits(0x44, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[1]); return 0; } @@ -1107,8 +1094,6 @@ static int es7210_micboost6_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[1] == NULL) - return 0; es7210_read(0x44, &val, i2c_clt1[1]); ucontrol->value.integer.value[0] = val; return 0; @@ -1116,8 +1101,6 @@ static int es7210_micboost6_setting_get(struct snd_kcontrol *kcontrol, static int es7210_micboost7_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[1] == NULL) - return 0; es7210_update_bits(0x45, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[1]); return 0; } @@ -1126,8 +1109,6 @@ static int es7210_micboost7_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[1] == NULL) - return 0; es7210_read(0x45, &val, i2c_clt1[1]); ucontrol->value.integer.value[0] = val; return 0; @@ -1135,8 +1116,6 @@ static int es7210_micboost7_setting_get(struct snd_kcontrol *kcontrol, static int es7210_micboost8_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[1] == NULL) - return 0; es7210_update_bits(0x46, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[1]); return 0; } @@ -1145,8 +1124,6 @@ static int es7210_micboost8_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[1] == NULL) - return 0; es7210_read(0x46, &val, i2c_clt1[1]); ucontrol->value.integer.value[0] = val; return 0; @@ -1154,10 +1131,8 @@ static int es7210_micboost8_setting_get(struct snd_kcontrol *kcontrol, static int es7210_adc5_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[1] == NULL) - return 0; es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x01, - ucontrol->value.integer.value[0]&0x01, i2c_clt1[1]); + ucontrol->value.integer.value[0]&0x01, i2c_clt1[1]); return 0; } @@ -1165,8 +1140,6 @@ static int es7210_adc5_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[1] == NULL) - return 0; es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[1]); ucontrol->value.integer.value[0] = val & 0x01; return 0; @@ -1175,8 +1148,6 @@ static int es7210_adc5_mute_get(struct snd_kcontrol *kcontrol, static int es7210_adc6_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[1] == NULL) - return 0; es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x02, (ucontrol->value.integer.value[0] & 0x01) << 1, i2c_clt1[1]); return 0; @@ -1186,8 +1157,6 @@ static int es7210_adc6_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[1] == NULL) - return 0; es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[1]); ucontrol->value.integer.value[0] = (val & 0x02) >> 1; return 0; @@ -1196,8 +1165,6 @@ static int es7210_adc6_mute_get(struct snd_kcontrol *kcontrol, static int es7210_adc7_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[1] == NULL) - return 0; es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x01, ucontrol->value.integer.value[0]&0x01, i2c_clt1[1]); return 0; @@ -1207,8 +1174,6 @@ static int es7210_adc7_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[1] == NULL) - return 0; es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[1]); ucontrol->value.integer.value[0] = val & 0x01; return 0; @@ -1216,8 +1181,6 @@ static int es7210_adc7_mute_get(struct snd_kcontrol *kcontrol, static int es7210_adc8_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[1] == NULL) - return 0; es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x02, (ucontrol->value.integer.value[0] & 0x01) << 1, i2c_clt1[1]); return 0; @@ -1227,18 +1190,16 @@ static int es7210_adc8_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[1] == NULL) - return 0; es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[1]); ucontrol->value.integer.value[0] = (val & 0x02) >> 1; return 0; } +#endif +#if ES7210_CHANNELS_MAX > 8 static int es7210_micboost9_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[2] == NULL) - return 0; es7210_update_bits(0x43, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[2]); return 0; } @@ -1247,8 +1208,6 @@ static int es7210_micboost9_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[2] == NULL) - return 0; es7210_read(0x43, &val, i2c_clt1[2]); ucontrol->value.integer.value[0] = val; return 0; @@ -1256,8 +1215,6 @@ static int es7210_micboost9_setting_get(struct snd_kcontrol *kcontrol, static int es7210_micboost10_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[2] == NULL) - return 0; es7210_update_bits(0x44, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[2]); return 0; } @@ -1266,8 +1223,6 @@ static int es7210_micboost10_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[2] == NULL) - return 0; es7210_read(0x44, &val, i2c_clt1[2]); ucontrol->value.integer.value[0] = val; return 0; @@ -1275,8 +1230,6 @@ static int es7210_micboost10_setting_get(struct snd_kcontrol *kcontrol, static int es7210_micboost11_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[2] == NULL) - return 0; es7210_update_bits(0x45, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[2]); return 0; } @@ -1285,8 +1238,6 @@ static int es7210_micboost11_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[2] == NULL) - return 0; es7210_read(0x45, &val, i2c_clt1[2]); ucontrol->value.integer.value[0] = val; return 0; @@ -1294,8 +1245,6 @@ static int es7210_micboost11_setting_get(struct snd_kcontrol *kcontrol, static int es7210_micboost12_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[2] == NULL) - return 0; es7210_update_bits(0x46, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[2]); return 0; } @@ -1304,8 +1253,6 @@ static int es7210_micboost12_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[2] == NULL) - return 0; es7210_read(0x46, &val, i2c_clt1[2]); ucontrol->value.integer.value[0] = val; return 0; @@ -1313,10 +1260,8 @@ static int es7210_micboost12_setting_get(struct snd_kcontrol *kcontrol, static int es7210_adc9_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[2] == NULL) - return 0; es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x01, - ucontrol->value.integer.value[0]&0x01, i2c_clt1[2]); + ucontrol->value.integer.value[0]&0x01, i2c_clt1[2]); return 0; } @@ -1324,8 +1269,6 @@ static int es7210_adc9_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[2] == NULL) - return 0; es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[2]); ucontrol->value.integer.value[0] = val & 0x01; return 0; @@ -1334,8 +1277,6 @@ static int es7210_adc9_mute_get(struct snd_kcontrol *kcontrol, static int es7210_adc10_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[2] == NULL) - return 0; es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x02, (ucontrol->value.integer.value[0] & 0x01) << 1, i2c_clt1[2]); return 0; @@ -1345,8 +1286,6 @@ static int es7210_adc10_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[2] == NULL) - return 0; es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[2]); ucontrol->value.integer.value[0] = (val & 0x02) >> 1; return 0; @@ -1355,8 +1294,6 @@ static int es7210_adc10_mute_get(struct snd_kcontrol *kcontrol, static int es7210_adc11_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[2] == NULL) - return 0; es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x01, ucontrol->value.integer.value[0]&0x01, i2c_clt1[2]); return 0; @@ -1366,8 +1303,6 @@ static int es7210_adc11_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[2] == NULL) - return 0; es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[2]); ucontrol->value.integer.value[0] = val & 0x01; return 0; @@ -1375,8 +1310,6 @@ static int es7210_adc11_mute_get(struct snd_kcontrol *kcontrol, static int es7210_adc12_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[2] == NULL) - return 0; es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x02, (ucontrol->value.integer.value[0] & 0x01) << 1, i2c_clt1[2]); return 0; @@ -1386,18 +1319,16 @@ static int es7210_adc12_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[2] == NULL) - return 0; es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[2]); ucontrol->value.integer.value[0] = (val & 0x02) >> 1; return 0; } +#endif +#if ES7210_CHANNELS_MAX > 12 static int es7210_micboost13_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[3] == NULL) - return 0; es7210_update_bits(0x43, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[3]); return 0; } @@ -1406,8 +1337,6 @@ static int es7210_micboost13_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[3] == NULL) - return 0; es7210_read(0x43, &val, i2c_clt1[3]); ucontrol->value.integer.value[0] = val; return 0; @@ -1415,8 +1344,6 @@ static int es7210_micboost13_setting_get(struct snd_kcontrol *kcontrol, static int es7210_micboost14_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[3] == NULL) - return 0; es7210_update_bits(0x44, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[3]); return 0; } @@ -1425,8 +1352,6 @@ static int es7210_micboost14_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[3] == NULL) - return 0; es7210_read(0x44, &val, i2c_clt1[3]); ucontrol->value.integer.value[0] = val; return 0; @@ -1434,8 +1359,6 @@ static int es7210_micboost14_setting_get(struct snd_kcontrol *kcontrol, static int es7210_micboost15_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[3] == NULL) - return 0; es7210_update_bits(0x45, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[3]); return 0; } @@ -1444,8 +1367,6 @@ static int es7210_micboost15_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[3] == NULL) - return 0; es7210_read(0x45, &val, i2c_clt1[3]); ucontrol->value.integer.value[0] = val; return 0; @@ -1453,8 +1374,6 @@ static int es7210_micboost15_setting_get(struct snd_kcontrol *kcontrol, static int es7210_micboost16_setting_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[3] == NULL) - return 0; es7210_update_bits(0x46, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[3]); return 0; } @@ -1463,8 +1382,6 @@ static int es7210_micboost16_setting_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[3] == NULL) - return 0; es7210_read(0x46, &val, i2c_clt1[3]); ucontrol->value.integer.value[0] = val; return 0; @@ -1472,10 +1389,8 @@ static int es7210_micboost16_setting_get(struct snd_kcontrol *kcontrol, static int es7210_adc13_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[3] == NULL) - return 0; es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x01, - ucontrol->value.integer.value[0]&0x01, i2c_clt1[3]); + ucontrol->value.integer.value[0]&0x01, i2c_clt1[3]); return 0; } @@ -1483,8 +1398,6 @@ static int es7210_adc13_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[3] == NULL) - return 0; es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[3]); ucontrol->value.integer.value[0] = val & 0x01; return 0; @@ -1493,8 +1406,6 @@ static int es7210_adc13_mute_get(struct snd_kcontrol *kcontrol, static int es7210_adc14_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[3] == NULL) - return 0; es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x02, (ucontrol->value.integer.value[0] & 0x01) << 1, i2c_clt1[3]); return 0; @@ -1504,8 +1415,6 @@ static int es7210_adc14_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[3] == NULL) - return 0; es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[3]); ucontrol->value.integer.value[0] = (val & 0x02) >> 1; return 0; @@ -1514,8 +1423,6 @@ static int es7210_adc14_mute_get(struct snd_kcontrol *kcontrol, static int es7210_adc15_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[3] == NULL) - return 0; es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x01, ucontrol->value.integer.value[0]&0x01, i2c_clt1[3]); return 0; @@ -1525,8 +1432,6 @@ static int es7210_adc15_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[3] == NULL) - return 0; es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[3]); ucontrol->value.integer.value[0] = val & 0x01; return 0; @@ -1534,8 +1439,6 @@ static int es7210_adc15_mute_get(struct snd_kcontrol *kcontrol, static int es7210_adc16_mute_set(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (i2c_clt1[3] == NULL) - return 0; es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x02, (ucontrol->value.integer.value[0] & 0x01) << 1, i2c_clt1[3]); return 0; @@ -1545,14 +1448,14 @@ static int es7210_adc16_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u8 val; - if (i2c_clt1[3] == NULL) - return 0; es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[3]); ucontrol->value.integer.value[0] = (val & 0x02) >> 1; return 0; } +#endif static const struct snd_kcontrol_new es7210_snd_controls[] = { +#if ES7210_CHANNELS_MAX > 0 SOC_SINGLE_EXT_TLV("PGA1_setting", 0x43, 0, 0x0E, 0, es7210_micboost1_setting_get, es7210_micboost1_setting_set, @@ -1577,6 +1480,8 @@ static const struct snd_kcontrol_new es7210_snd_controls[] = { es7210_adc3_mute_get, es7210_adc3_mute_set), SOC_SINGLE_EXT("ADC4_MUTE", ES7210_ADC34_MUTE_REG14, 1, 1, 0, es7210_adc4_mute_get, es7210_adc4_mute_set), +#endif +#if ES7210_CHANNELS_MAX > 4 SOC_SINGLE_EXT_TLV("PGA5_setting", 0x43, 0, 0x0E, 0, es7210_micboost5_setting_get, es7210_micboost5_setting_set, @@ -1601,6 +1506,9 @@ static const struct snd_kcontrol_new es7210_snd_controls[] = { es7210_adc7_mute_get, es7210_adc7_mute_set), SOC_SINGLE_EXT("ADC8_MUTE", ES7210_ADC34_MUTE_REG14, 1, 1, 0, es7210_adc8_mute_get, es7210_adc8_mute_set), + +#endif +#if ES7210_CHANNELS_MAX > 8 SOC_SINGLE_EXT_TLV("PGA9_setting", 0x43, 0, 0x0E, 0, es7210_micboost9_setting_get, es7210_micboost9_setting_set, @@ -1625,6 +1533,9 @@ static const struct snd_kcontrol_new es7210_snd_controls[] = { es7210_adc11_mute_get, es7210_adc11_mute_set), SOC_SINGLE_EXT("ADC12_MUTE", ES7210_ADC34_MUTE_REG14, 1, 1, 0, es7210_adc12_mute_get, es7210_adc12_mute_set), + +#endif +#if ES7210_CHANNELS_MAX > 12 SOC_SINGLE_EXT_TLV("PGA13_setting", 0x43, 0, 0x0E, 0, es7210_micboost13_setting_get, es7210_micboost13_setting_set, @@ -1649,10 +1560,12 @@ static const struct snd_kcontrol_new es7210_snd_controls[] = { es7210_adc15_mute_get, es7210_adc15_mute_set), SOC_SINGLE_EXT("ADC16_MUTE", ES7210_ADC34_MUTE_REG14, 1, 1, 0, es7210_adc16_mute_get, es7210_adc16_mute_set), + +#endif + }; static struct snd_soc_component_driver soc_codec_dev_es7210 = { - .name = "es7210", .probe = es7210_probe, .suspend = es7210_suspend, .resume = es7210_resume, @@ -1702,12 +1615,6 @@ static ssize_t es7210_show(struct device *dev, struct device_attribute *attr, ch printk("echo flag|reg|val > es7210\n"); printk("eg read star address=0x06,count 0x10:echo 0610 >es7210\n"); printk("eg write star address=0x90,value=0x3c,count=4:echo 4903c >es7210\n"); - struct es7210_priv *es7210 = dev_get_drvdata(dev); - u8 value, i; - for (i = 0; i < 0x4d; i++) { - es7210_read(i, &value, es7210->i2c_client); - printk("reg[0x%x]=0x%x\n", i, value); - } return 0; } @@ -1731,9 +1638,6 @@ static int es7210_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *i2c_id) { struct es7210_priv *es7210; - struct device_node *np = i2c_client->dev.of_node; - char* property; - int ret; es7210 = devm_kzalloc(&i2c_client->dev, sizeof(struct es7210_priv), @@ -1741,42 +1645,7 @@ static int es7210_i2c_probe(struct i2c_client *i2c_client, if (es7210 == NULL) return -ENOMEM; es7210->i2c_client = i2c_client; - - property = of_get_property(np, "work-mode", NULL); - if (property) { - if (!strcmp(property, "ES7210_TDM_1LRCK_DSPB")) { - es7210->tdm_mode = ES7210_TDM_1LRCK_DSPB; - } else if (!strcmp(property, "ES7210_NORMAL_I2S")) { - es7210->tdm_mode = ES7210_NORMAL_I2S; - } else { - pr_err("unsupported work mode\n"); - return -EINVAL; - } - } else { - pr_warn("es7210 work-mode not defined.using ES7210_NORMAL_I2S by default\n"); - es7210->tdm_mode = ES7210_NORMAL_I2S; - } - - if (of_property_read_u32(np, "channels-max", &ES7210_CHANNELS_MAX) == 0) { - if (ES7210_CHANNELS_MAX == MIC_CHN_2 || ES7210_CHANNELS_MAX == MIC_CHN_4) { - ADC_DEV_MAXNUM = 1; - } else if (ES7210_CHANNELS_MAX == MIC_CHN_6 || ES7210_CHANNELS_MAX == MIC_CHN_8) { - ADC_DEV_MAXNUM = 2; - } else if (ES7210_CHANNELS_MAX == MIC_CHN_10 || ES7210_CHANNELS_MAX == MIC_CHN_12) { - ADC_DEV_MAXNUM = 3; - } else if (ES7210_CHANNELS_MAX == MIC_CHN_14 || ES7210_CHANNELS_MAX == MIC_CHN_16) { - ADC_DEV_MAXNUM = 4; - } else { - pr_err("es7210 unsupported channels-max\n"); - return -EINVAL; - } - } else { - pr_warn("es7210 channels-max not defined.using MIC_CHN_2 by default\n"); - ES7210_CHANNELS_MAX = MIC_CHN_2; - ADC_DEV_MAXNUM = 1; - } - //printk("%s es7210->tdm_mode=%d channels-max=%d ADC_DEV_MAXNUM=%d\n", __func__, es7210->tdm_mode, ES7210_CHANNELS_MAX, ADC_DEV_MAXNUM); - + es7210->tdm_mode = ES7210_WORK_MODE; //to set tdm mode or normal mode i2c_set_clientdata(i2c_client, es7210); if (i2c_id->driver_data < ADC_DEV_MAXNUM) { i2c_clt1[i2c_id->driver_data] = i2c_client; @@ -1796,19 +1665,41 @@ static int es7210_i2c_probe(struct i2c_client *i2c_client, static const struct i2c_device_id es7210_i2c_id[] = { +#if ES7210_CHANNELS_MAX > 0 { "MicArray_0", 0 },//es7210_0 +#endif + +#if ES7210_CHANNELS_MAX > 4 { "MicArray_1", 1 },//es7210_1 +#endif + +#if ES7210_CHANNELS_MAX > 8 { "MicArray_2", 2 },//es7210_2 +#endif + +#if ES7210_CHANNELS_MAX > 12 { "MicArray_3", 3 },//es7210_3 +#endif { } }; MODULE_DEVICE_TABLE(i2c_client, es7210_i2c_id); static const struct of_device_id es7210_dt_ids[] = { +#if ES7210_CHANNELS_MAX > 0 { .compatible = "MicArray_0", },//es7210_0 +#endif + +#if ES7210_CHANNELS_MAX > 4 { .compatible = "MicArray_1", },//es7210_1 +#endif + +#if ES7210_CHANNELS_MAX > 8 { .compatible = "MicArray_2", },//es7210_2 +#endif + +#if ES7210_CHANNELS_MAX > 12 { .compatible = "MicArray_3", },//es7210_3 +#endif {} }; MODULE_DEVICE_TABLE(of, es7210_dt_ids); diff --git a/sound/soc/codecs/es7210.h b/sound/soc/codecs/es7210.h index 9b0fcccc4..c3b89fd4d 100644 --- a/sound/soc/codecs/es7210.h +++ b/sound/soc/codecs/es7210.h @@ -69,19 +69,5 @@ #define ES7210_MIC4_LP_REG4A 0x4A #define ES7210_MIC12_PDN_REG4B 0x4B #define ES7210_MIC34_PDN_REG4C 0x4C - -/* codec private data */ -struct es7210_priv { - struct regmap *regmap; - struct i2c_client *i2c_client; - unsigned int dmic_enable; - unsigned int sysclk; - struct clk *mclk; - struct snd_pcm_hw_constraint_list *sysclk_constraints; - unsigned int tdm_mode; - struct delayed_work pcm_pop_work; - int mclk_lrck_ratio; - int pcm_format; -}; - + #endif /* _ES7210_H_ */ diff --git a/sound/soc/codecs/es8156.c b/sound/soc/codecs/es8156.c index 36f9840e3..47ab55ef0 100644 --- a/sound/soc/codecs/es8156.c +++ b/sound/soc/codecs/es8156.c @@ -36,7 +36,6 @@ #define GPIO_LOW 0 #define GPIO_HIGH 1 #define es8156_DEF_VOL 0xBF -#define ES8156_VOL_MAX 0xBF /* * If your system doesn't have MCLK, define this to 0 or the * driver will crash. @@ -116,7 +115,7 @@ static const struct snd_kcontrol_new es8156_snd_controls[] = { 4,0,15,0), /* DAC Digital controls */ SOC_SINGLE_TLV("DAC Playback Volume", ES8156_VOLUME_CONTROL_REG14, - 0, ES8156_VOL_MAX, 0, dac_vol_tlv), + 0, 0xff, 0, dac_vol_tlv), SOC_SINGLE("HP Switch",ES8156_ANALOG_SYS3_REG22,3,1,0), @@ -124,7 +123,7 @@ static const struct snd_kcontrol_new es8156_snd_controls[] = { static const struct snd_soc_dapm_widget es8156_dapm_widgets[] = { - SND_SOC_DAPM_AIF_OUT("AIFSDOUT", "I2S Capture", 0, + SND_SOC_DAPM_AIF_OUT("SDOUT", "I2S Capture", 0, ES8156_P2S_CONTROL_REG0D, 2, 0), SND_SOC_DAPM_AIF_IN("SDIN", "I2S Playback", 0, @@ -162,6 +161,150 @@ static const struct snd_soc_dapm_route es8156_dapm_routes[] = { { "ROUT", NULL, "DACR" }, }; +/*************** parameter define ***************/ +#define STATEconfirm 0x0C +#define NORMAL_I2S 0x00 +#define NORMAL_LJ 0x01 +#define NORMAL_DSPA 0x03 +#define NORMAL_DSPB 0x07 +#define Format_Len24 0x00 +#define Format_Len20 0x01 +#define Format_Len18 0x02 +#define Format_Len16 0x03 +#define Format_Len32 0x04 + +#define VDDA_3V3 0x00 +#define VDDA_1V8 0x01 +#define MCLK_PIN 0x00 +#define SCLK_PIN 0x01 + +/**************************************************/ +#define MSMode_MasterSelOn 0 // SlaveMode:0, MasterMode:1 +#define Ratio 64 // Ratio = MCLK/LRCK on board +#define Format NORMAL_I2S +#define Format_Len Format_Len16 // data format +#define SCLK_DIV 8 // SCLK_DIV = MCLK/SCLK +#define SCLK_INV 0 +#define MCLK_SOURCE SCLK_PIN // select MCLK source, MCLK_PIN or SCLK_PIN +#define EQ7bandOn 0 +#define VDDA_VOLTAGE VDDA_3V3 +#define DAC_Volume 191 // DAC digital gain +#define DACHPModeOn 0 // disable:0, enable:1 + +/**************************************************/ + +static int es8156_init_sequence(struct snd_soc_component *codec) +{ + pr_debug("%s\n", __func__); + + snd_soc_component_write(codec,0x02,(MCLK_SOURCE<<7) + (SCLK_INV<<4) + (EQ7bandOn<<3) + 0x04 + MSMode_MasterSelOn); + snd_soc_component_write(codec,0x19,0x20); + + if(DACHPModeOn == 0) // output from PA + { + snd_soc_component_write(codec,0x20,0x2A); + snd_soc_component_write(codec,0x21,0x3C); + snd_soc_component_write(codec,0x22,0x02); + snd_soc_component_write(codec,0x24,0x07); + snd_soc_component_write(codec,0x23,0x40 + (0x30*VDDA_VOLTAGE)); + } + if(DACHPModeOn == 1) // output from headphone + { + snd_soc_component_write(codec,0x20,0x16); + snd_soc_component_write(codec,0x21,0x3F); + snd_soc_component_write(codec,0x22,0x0A); + snd_soc_component_write(codec,0x24,0x01); + snd_soc_component_write(codec,0x23,0xCA + (0x30*VDDA_VOLTAGE)); + } + snd_soc_component_write(codec,0x0A,0x01); + snd_soc_component_write(codec,0x0B,0x01); + //snd_soc_component_write(codec,0x11,NORMAL_I2S + (Format_Len<<4)); + snd_soc_component_write(codec,0x14,DAC_Volume); + if(Ratio == 1536) // Ratio=MCLK/LRCK=1536; 12M288/8K; 24M576/16K + { + snd_soc_component_write(codec,0x01,0x26 - (0x03*EQ7bandOn)); // 1536 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x09,0x00); // 1536 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x03,0x06); // LRCK H + snd_soc_component_write(codec,0x04,0x00); // LRCK=MCLK/1536 + snd_soc_component_write(codec,0x05,SCLK_DIV); // BCLK=MCLK/4 + } + if(Ratio == 1024) // Ratio=MCLK/LRCK=1024; 12M288/12K; 24M576/24K + { + snd_soc_component_write(codec,0x01,0x24 - (0x02*EQ7bandOn)); // 256 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x09,0x00); // 256 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x03,0x04); // LRCK H + snd_soc_component_write(codec,0x04,0x00); // LRCK=MCLK/256 + snd_soc_component_write(codec,0x05,SCLK_DIV); // BCLK=MCLK/4 + } + if(Ratio == 768) // Ratio=MCLK/LRCK=768; 12M288/16K; 24M576/32K + { + snd_soc_component_write(codec,0x01,0x23 + (0x40*EQ7bandOn)); // 768 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x09,0x00); // 768 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x03,0x03); // LRCK H + snd_soc_component_write(codec,0x04,0x00); // LRCK=MCLK/768 + snd_soc_component_write(codec,0x05,SCLK_DIV); // BCLK=MCLK/4 + } + if(Ratio == 512) // Ratio=MCLK/LRCK=512; 12M288/24K; 24M576/48K + { + snd_soc_component_write(codec,0x01,0xC0 + 0x22 - (0x01*EQ7bandOn)); // 512 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x09,0x00); // 512 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x03,0x02); // LRCK H + snd_soc_component_write(codec,0x04,0x00); // LRCK=MCLK/512 + snd_soc_component_write(codec,0x05,SCLK_DIV); //BCLK=MCLK/4 + } + if(Ratio == 400) // Ratio=MCLK/LRCK=400; 19M2/48K + { // DVDD must be 3.3V + snd_soc_component_write(codec,0x01,0x21 + (0x40*EQ7bandOn)); // 384 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x09,0x00); // 400 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x10,0x64); // 400 OSR + snd_soc_component_write(codec,0x03,0x01); // LRCK H + snd_soc_component_write(codec,0x04,0x90); // LRCK=MCLK/400 + snd_soc_component_write(codec,0x05,SCLK_DIV); // BCLK=MCLK/4 + } + if(Ratio == 384) // Ratio=MCLK/LRCK=384; 12M288/32K; 6M144/16K + { + snd_soc_component_write(codec,0x01,0x63 + (0x40*EQ7bandOn)); // 384 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x09,0x00); // 384 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x03,0x01); // LRCK H + snd_soc_component_write(codec,0x04,0x80); // LRCK=MCLK/384 + snd_soc_component_write(codec,0x05,SCLK_DIV); // BCLK=MCLK/4 + } + if(Ratio == 256) // Ratio=MCLK/LRCK=256; 12M288/48K + { + snd_soc_component_write(codec,0x01,0x21 + (0x40*EQ7bandOn)); // 256 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x09,0x00); // 256 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x03,0x01); // LRCK H + snd_soc_component_write(codec,0x04,0x00); // LRCK=MCLK/256 + snd_soc_component_write(codec,0x05,SCLK_DIV); // BCLK=MCLK/4 + } + if(Ratio == 128) // Ratio=MCLK/LRCK=128; 6M144/48K + { + snd_soc_component_write(codec,0x01,0x61 + (0x40*EQ7bandOn)); // 128 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x09,0x00); // 128 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x03,0x00); // LRCK H + snd_soc_component_write(codec,0x04,0x80); // LRCK=MCLK/128 + snd_soc_component_write(codec,0x05,SCLK_DIV); // BCLK=MCLK/4 + } + if(Ratio == 64) // Ratio=MCLK/LRCK=64; 3M072/48K + { + snd_soc_component_write(codec,0x01,0xE1); // 64 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x09,0x02); // 64 Ratio(MCLK/LRCK) + snd_soc_component_write(codec,0x03,0x00); // LRCK H + snd_soc_component_write(codec,0x04,0x40); // LRCK=MCLK/64 + snd_soc_component_write(codec,0x05,SCLK_DIV); // BCLK=MCLK/2 + } + + snd_soc_component_write(codec,0x0D,0x14); + snd_soc_component_write(codec,0x18,0x00); + snd_soc_component_write(codec,0x08,0x3F); + snd_soc_component_write(codec,0x00,0x02); + snd_soc_component_write(codec,0x00,0x03); + snd_soc_component_write(codec,0x25,0x20); + + return 0; +} + + static int es8156_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { @@ -269,25 +412,7 @@ static int es8156_set_bias_level(struct snd_soc_component *codec, if (!IS_ERR(priv->mclk)) { ret = clk_prepare_enable(priv->mclk); - snd_soc_component_write(codec, ES8156_SCLK_MODE_REG02,0x04); - snd_soc_component_write(codec, ES8156_ANALOG_SYS1_REG20,0x2A); - snd_soc_component_write(codec, ES8156_ANALOG_SYS2_REG21,0x3C); - snd_soc_component_write(codec, ES8156_ANALOG_SYS3_REG22,0x08); - snd_soc_component_write(codec, ES8156_ANALOG_LP_REG24,0x07); - if(ES8156_DVDD==ES8156_1V8) - snd_soc_component_write(codec, ES8156_ANALOG_SYS4_REG23,VMIDLEVEL3<<4); - else - snd_soc_component_write(codec, ES8156_ANALOG_SYS4_REG23,0x00); - snd_soc_component_write(codec, ES8156_TIME_CONTROL1_REG0A,0x01); - snd_soc_component_write(codec, ES8156_TIME_CONTROL2_REG0B,0x01); - //snd_soc_component_write(codec, ES8156_VOLUME_CONTROL_REG14,0xBF); - snd_soc_component_write(codec, ES8156_MAINCLOCK_CTL_REG01,0x21); - snd_soc_component_write(codec, ES8156_P2S_CONTROL_REG0D,0x14); - snd_soc_component_write(codec, ES8156_MISC_CONTROL3_REG18,0x00); - snd_soc_component_write(codec, ES8156_CLOCK_ON_OFF_REG08,0x3F); - snd_soc_component_write(codec, ES8156_RESET_REG00,0x02); - snd_soc_component_write(codec, ES8156_RESET_REG00,0x03); - snd_soc_component_write(codec, ES8156_ANALOG_SYS5_REG25,0x20); + es8156_init_sequence(codec); if (ret) { dev_err(codec->dev, @@ -300,22 +425,23 @@ static int es8156_set_bias_level(struct snd_soc_component *codec, break; case SND_SOC_BIAS_OFF: - //snd_soc_component_write(codec, ES8156_VOLUME_CONTROL_REG14, 0x00); - snd_soc_component_write(codec, ES8156_EQ_CONTROL1_REG19, 0x02); - snd_soc_component_write(codec, ES8156_ANALOG_SYS2_REG21, 0x1F); - snd_soc_component_write(codec, ES8156_ANALOG_SYS3_REG22, 0x02); - snd_soc_component_write(codec, ES8156_ANALOG_SYS5_REG25, 0x21); - snd_soc_component_write(codec, ES8156_ANALOG_SYS5_REG25, 0x01); - snd_soc_component_write(codec, ES8156_ANALOG_SYS5_REG25, 0x87); - snd_soc_component_write(codec, ES8156_MISC_CONTROL3_REG18, 0x01); - snd_soc_component_write(codec, ES8156_MISC_CONTROL2_REG09, 0x02); - snd_soc_component_write(codec, ES8156_MISC_CONTROL2_REG09, 0x01); - snd_soc_component_write(codec, ES8156_CLOCK_ON_OFF_REG08, 0x00); + snd_soc_component_write(codec,0x14,0x00); + snd_soc_component_write(codec,0x19,0x02); + snd_soc_component_write(codec,0x22,0x02); + snd_soc_component_write(codec,0x25,0x81); + snd_soc_component_write(codec,0x18,0x01); + snd_soc_component_write(codec,0x09,0x02); + snd_soc_component_write(codec,0x09,0x01); + snd_soc_component_write(codec,0x08,0x00); + mdelay(500); + snd_soc_component_write(codec,0x25,0x87); /* *close i2s clock */ - if (!IS_ERR(priv->mclk)) + if (!IS_ERR(priv->mclk)) { + pr_info("%s codec_uninit_sequence\n", __func__); clk_disable_unprepare(priv->mclk); + } break; } return 0; @@ -348,43 +474,6 @@ static struct snd_soc_dai_driver es8156_dai = { }; -static int es8156_init_regs(struct snd_soc_component *codec) -{ - /* - *set clock and analog power - */ - snd_soc_component_write(codec, ES8156_SCLK_MODE_REG02,0x04); - snd_soc_component_write(codec, ES8156_ANALOG_SYS1_REG20,0x2A); - snd_soc_component_write(codec, ES8156_ANALOG_SYS2_REG21,0x3C); - snd_soc_component_write(codec, ES8156_ANALOG_SYS3_REG22,0x08); - snd_soc_component_write(codec, ES8156_ANALOG_LP_REG24,0x07); - if(ES8156_DVDD==ES8156_1V8) - snd_soc_component_write(codec, ES8156_ANALOG_SYS4_REG23,VMIDLEVEL3<<4); - else - snd_soc_component_write(codec, ES8156_ANALOG_SYS4_REG23,0x00); - /* - *set powerup time - */ - snd_soc_component_write(codec, ES8156_TIME_CONTROL1_REG0A,0x01); - snd_soc_component_write(codec, ES8156_TIME_CONTROL2_REG0B,0x01); - /* - *set digtal volume - */ - snd_soc_component_write(codec, ES8156_VOLUME_CONTROL_REG14,0xBF); - /* - *set MCLK - */ - snd_soc_component_write(codec, ES8156_MAINCLOCK_CTL_REG01,0x21); - snd_soc_component_write(codec, ES8156_P2S_CONTROL_REG0D,0x14); - snd_soc_component_write(codec, ES8156_MISC_CONTROL3_REG18,0x00); - snd_soc_component_write(codec, ES8156_CLOCK_ON_OFF_REG08,0x3F); - snd_soc_component_write(codec, ES8156_RESET_REG00,0x02); - snd_soc_component_write(codec, ES8156_RESET_REG00,0x03); - snd_soc_component_write(codec, ES8156_ANALOG_SYS5_REG25,0x20); - - return 0; -} - static int es8156_suspend(struct snd_soc_component *codec) { es8156_set_bias_level(codec, SND_SOC_BIAS_OFF); @@ -471,7 +560,7 @@ static int es8156_probe(struct snd_soc_component *codec) ret = clk_prepare_enable(es8156->mclk); #endif es8156_reset(codec); - es8156_init_regs(codec); + es8156_init_sequence(codec); return ret; } @@ -490,7 +579,6 @@ const struct regmap_config es8156_regmap_config = { }; static struct snd_soc_component_driver soc_codec_dev_es8156 = { - .name = "es8156", .probe = es8156_probe, .remove = es8156_remove, .suspend = es8156_suspend,