diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c index b91774a138bf6a..59d0d5754530ed 100644 --- a/sound/soc/codecs/es8316.c +++ b/sound/soc/codecs/es8316.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -40,7 +39,6 @@ struct es8316_priv { struct snd_soc_component *component; struct snd_soc_jack *jack; int irq; - struct gpio_desc *pa_enable; unsigned int sysclk; unsigned int allowed_rates[NR_SUPPORTED_MCLK_LRCK_RATIOS]; struct snd_pcm_hw_constraint_list sysclk_constraints; @@ -88,8 +86,6 @@ static const struct soc_enum dacpol = SOC_ENUM_SINGLE(ES8316_DAC_SET1, 0, 4, dacpol_txt); static const struct snd_kcontrol_new es8316_snd_controls[] = { - //SOC_DOUBLE_TLV("Headphone Playback Volume", ES8316_CPHP_ICAL_VOL, - // 4, 0, 3, 1, hpout_vol_tlv), SOC_DOUBLE_TLV("Headphone Mixer Volume", ES8316_HPMIX_VOL, 4, 0, 11, 0, hpmixer_gain_tlv), @@ -104,7 +100,6 @@ static const struct snd_kcontrol_new es8316_snd_controls[] = { SOC_SINGLE("DAC Mono Mix Switch", ES8316_DAC_SET3, 3, 1, 0), SOC_ENUM("Capture Polarity", adcpol), - //SOC_SINGLE("Mic Boost Switch", ES8316_ADC_D2SEPGA, 0, 1, 0), SOC_SINGLE_TLV("ADC Capture Volume", ES8316_ADC_VOLUME, 0, 0xc0, 1, adc_vol_tlv), SOC_SINGLE_TLV("ADC PGA Gain Volume", ES8316_ADC_PGAGAIN, @@ -206,7 +201,6 @@ static const struct snd_kcontrol_new es8316_dacsrc_mux_controls = static const struct snd_soc_dapm_widget es8316_dapm_widgets[] = { SND_SOC_DAPM_SUPPLY("Bias", SND_SOC_NOPM, 0, 0, NULL, 0), SND_SOC_DAPM_SUPPLY("Analog power", SND_SOC_NOPM, 0, 0, NULL, 0), - SND_SOC_DAPM_SUPPLY("Mic Bias", SND_SOC_NOPM, 0, 0, NULL, 0), SND_SOC_DAPM_INPUT("DMIC"), SND_SOC_DAPM_INPUT("MIC1"), @@ -284,8 +278,6 @@ static const struct snd_soc_dapm_widget es8316_dapm_widgets[] = { static const struct snd_soc_dapm_route es8316_dapm_routes[] = { /* Recording */ - {"MIC1", NULL, "Mic Bias"}, - {"MIC2", NULL, "Mic Bias"}, {"MIC1", NULL, "Bias"}, {"MIC2", NULL, "Bias"}, {"MIC1", NULL, "Analog power"}, @@ -364,7 +356,7 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai, struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); int i, ret; int count = 0; - printk("Enter into %s\n", __func__); + es8316->sysclk = freq; if (freq == 0) { @@ -390,7 +382,7 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai, es8316->sysclk_constraints.list = es8316->allowed_rates; es8316->sysclk_constraints.count = count; - printk("Exit %s\n", __func__); + return 0; } @@ -400,10 +392,8 @@ static int es8316_set_dai_fmt(struct snd_soc_dai *codec_dai, struct snd_soc_component *component = codec_dai->component; u8 serdata1 = 0; u8 serdata2 = 0; - u8 clksw; u8 mask; - printk("Enter into %s\n", __func__); if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) { dev_err(component->dev, "Codec driver only supports slave mode\n"); return -EINVAL; @@ -439,11 +429,6 @@ static int es8316_set_dai_fmt(struct snd_soc_dai *codec_dai, snd_soc_component_update_bits(component, ES8316_SERDATA_ADC, mask, serdata2); snd_soc_component_update_bits(component, ES8316_SERDATA_DAC, mask, serdata2); - /* Enable BCLK and MCLK inputs in slave mode */ - //clksw = ES8316_CLKMGR_CLKSW_MCLK_ON | ES8316_CLKMGR_CLKSW_BCLK_ON; - //snd_soc_component_update_bits(component, ES8316_CLKMGR_CLKSW, clksw, clksw); - - printk("Exit %s\n", __func__); return 0; } @@ -452,28 +437,16 @@ static int es8316_pcm_startup(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); - static int a=1; - printk("Enter into %s\n", __func__); + if (es8316->sysclk_constraints.list) snd_pcm_hw_constraint_list(substream->runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &es8316->sysclk_constraints); - if(a){ - //gpiod_set_value_cansleep(es8316->pa_enable, false); - a++; - if(a==19) - { - mdelay(5000); - printk("i2cset 0x0d 0x08"); - snd_soc_component_write(component, 0x4e, 0xf1); - snd_soc_component_write(component, 0x4e, 0xf2); - } - - - } + mdelay(50); + snd_soc_component_write(component, ES8316_GPIO_DEBOUNCE, 0xf1); + snd_soc_component_write(component, ES8316_GPIO_DEBOUNCE, 0xf2); - printk("Exit %s\n", __func__); return 0; } @@ -486,7 +459,6 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream, u8 wordlen = 0; int i; - printk("Enter into %s\n", __func__); /* Validate supported sample rates that are autodetected from MCLK */ for (i = 0; i < NR_SUPPORTED_MCLK_LRCK_RATIOS; i++) { const unsigned int ratio = supported_mclk_lrck_ratios[i]; @@ -521,29 +493,110 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream, snd_soc_component_update_bits(component, ES8316_SERDATA_ADC, ES8316_SERDATA2_LEN_MASK, wordlen); - snd_soc_component_write(component, 0x01, 0x7f); - snd_soc_component_write(component, 0x02, 0x09); - snd_soc_component_update_bits(component,ES8316_ADC_PDN_LINSEL,0xcf,0x00); - //snd_soc_component_write(component, 0x22, 0x30); - snd_soc_component_write(component, 0x0a, 0x00); - snd_soc_component_write(component, 0x0d, 0x00); + snd_soc_component_write(component, ES8316_CLKMGR_CLKSW, 0x7f); + snd_soc_component_write(component, ES8316_CLKMGR_CLKSEL, 0x09); + snd_soc_component_update_bits(component, ES8316_ADC_PDN_LINSEL, 0xcf, 0x00); + snd_soc_component_write(component, ES8316_SERDATA_ADC, 0x00); + snd_soc_component_write(component, ES8316_SYS_PDN, 0x00); - printk("Exit %s\n", __func__); return 0; } static int es8316_mute(struct snd_soc_dai *dai, int mute, int direction) { - printk("Enter into %s\n", __func__); snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20, mute ? 0x20 : 0); - printk("Exit %s\n", __func__); return 0; } #define ES8316_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ SNDRV_PCM_FMTBIT_S24_LE) +static int es8316_start(struct snd_soc_component *component) +{ + snd_soc_component_write(component, ES8316_RESET, 0x3f); + usleep_range(5000, 5500); + snd_soc_component_write(component, ES8316_RESET, 0x00); + msleep(30); + snd_soc_component_write(component, ES8316_SYS_VMIDSEL, 0xFF); + msleep(30); + snd_soc_component_write(component, ES8316_CLKMGR_CLKSEL, 0x09); + snd_soc_component_write(component, ES8316_CLKMGR_ADCOSR, 0x32); + snd_soc_component_write(component, ES8316_CLKMGR_ADCDIV1, 0x11); + snd_soc_component_write(component, ES8316_CLKMGR_ADCDIV2, 0x90); + snd_soc_component_write(component, ES8316_CLKMGR_DACDIV1, 0x11); + snd_soc_component_write(component, ES8316_CLKMGR_DACDIV2, 0x90); + snd_soc_component_write(component, ES8316_CLKMGR_CPDIV, 0x00); + snd_soc_component_write(component, ES8316_SERDATA1, 0x04); + snd_soc_component_write(component, ES8316_CLKMGR_CLKSW, 0x7F); + snd_soc_component_write(component, ES8316_CAL_TYPE, 0x0F); + snd_soc_component_write(component, ES8316_CAL_HPLIV, 0x90); + snd_soc_component_write(component, ES8316_CAL_HPRIV, 0x90); + snd_soc_component_write(component, ES8316_ADC_VOLUME, 0x00); + snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL, 0xc0); + snd_soc_component_write(component, ES8316_ADC_D2SEPGA, 0x00); + snd_soc_component_write(component, ES8316_ADC_DMIC, 0x08); + snd_soc_component_write(component, ES8316_DAC_SET2, 0x20); + snd_soc_component_write(component, ES8316_DAC_SET3, 0x00); + snd_soc_component_write(component, ES8316_DAC_VOLL, 0x00); + snd_soc_component_write(component, ES8316_DAC_VOLR, 0x00); + snd_soc_component_write(component, ES8316_SERDATA_ADC, 0x00); + snd_soc_component_write(component, ES8316_SERDATA_DAC, 0x00); + snd_soc_component_write(component, ES8316_SYS_VMIDLOW, 0x11); + snd_soc_component_write(component, ES8316_SYS_VSEL, 0xFC); + snd_soc_component_write(component, ES8316_SYS_REF, 0x28); + snd_soc_component_write(component, ES8316_SYS_LP1, 0x04); + snd_soc_component_write(component, ES8316_SYS_LP2, 0x0C); + snd_soc_component_write(component, ES8316_DAC_PDN, 0x11); + snd_soc_component_write(component, ES8316_HPMIX_SEL, 0x00); + snd_soc_component_write(component, ES8316_HPMIX_SWITCH, 0x88); + snd_soc_component_write(component, ES8316_HPMIX_PDN, 0x00); + snd_soc_component_write(component, ES8316_HPMIX_VOL, 0xBB); + snd_soc_component_write(component, ES8316_CPHP_PDN2, 0x10); + snd_soc_component_write(component, ES8316_CPHP_LDOCTL, 0x30); + snd_soc_component_write(component, ES8316_CPHP_PDN1, 0x02); + snd_soc_component_write(component, ES8316_CPHP_ICAL_VOL, 0x00); + snd_soc_component_write(component, ES8316_GPIO_SEL, 0x00); + snd_soc_component_write(component, ES8316_GPIO_DEBOUNCE, 0xf2); + snd_soc_component_write(component, ES8316_TESTMODE, 0xA0); + snd_soc_component_write(component, ES8316_ADC_MUTE, 0x00); + snd_soc_component_write(component, ES8316_TEST1, 0x00); + snd_soc_component_write(component, ES8316_TEST2, 0x00); + snd_soc_component_write(component, ES8316_SYS_PDN, 0x00); + snd_soc_component_write(component, ES8316_RESET, 0xC0); + msleep(50); + snd_soc_component_write(component, ES8316_ADC_PGAGAIN, 0x60); + snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL, 0x30); + snd_soc_component_write(component, ES8316_ADC_D2SEPGA, 0x00); + /* adc ds mode, HPF enable */ + snd_soc_component_write(component, ES8316_ADC_DMIC, 0x08); + snd_soc_component_write(component, ES8316_ADC_ALC1, 0xcd); + snd_soc_component_write(component, ES8316_ADC_ALC2, 0x08); + snd_soc_component_write(component, ES8316_ADC_ALC3, 0xa0); + snd_soc_component_write(component, ES8316_ADC_ALC4, 0x05); + snd_soc_component_write(component, ES8316_ADC_ALC5, 0x06); + snd_soc_component_write(component, ES8316_ADC_ALC_NG, 0x61); + /* + * Documentation is unclear, but this value from the vendor driver is + * needed otherwise audio output is silent. + */ + snd_soc_component_write(component, ES8316_SYS_VMIDSEL, 0xff); + + /* + * Documentation for this register is unclear and incomplete, + * but here is a vendor-provided value that improves volume + * and quality for Intel CHT platforms. + */ + snd_soc_component_write(component, ES8316_CLKMGR_ADCOSR, 0x32); + + return 0; +} + +static int es8316_resume(struct snd_soc_component *component) +{ + return es8316_start(component); +} + static const struct snd_soc_dai_ops es8316_ops = { .startup = es8316_pcm_startup, .hw_params = es8316_pcm_hw_params, @@ -578,31 +631,22 @@ static void es8316_enable_micbias_for_mic_gnd_short_detect( { struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); - printk("Enter into %s\n", __func__); snd_soc_dapm_mutex_lock(dapm); - //snd_soc_dapm_force_enable_pin_unlocked(dapm, "Bias"); snd_soc_dapm_force_enable_pin_unlocked(dapm, "Analog power"); - //snd_soc_dapm_force_enable_pin_unlocked(dapm, "Mic Bias"); snd_soc_dapm_sync_unlocked(dapm); snd_soc_dapm_mutex_unlock(dapm); - msleep(20); - printk("Exit %s\n", __func__); } static void es8316_disable_micbias_for_mic_gnd_short_detect( struct snd_soc_component *component) { struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); - printk("Enter into %s\n", __func__); snd_soc_dapm_mutex_lock(dapm); - //snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Bias"); snd_soc_dapm_disable_pin_unlocked(dapm, "Analog power"); - //snd_soc_dapm_disable_pin_unlocked(dapm, "Bias"); snd_soc_dapm_sync_unlocked(dapm); snd_soc_dapm_mutex_unlock(dapm); - printk("Exit %s\n", __func__); } static irqreturn_t es8316_irq(int irq, void *data) @@ -610,14 +654,16 @@ static irqreturn_t es8316_irq(int irq, void *data) struct es8316_priv *es8316 = data; struct snd_soc_component *comp = es8316->component; unsigned int flags; - struct snd_soc_dapm_context *dapm; - static int a=1; - printk("Enter into %s\n", __func__); + dev_dbg(comp->dev,"Enter into %s\n", __func__); + mutex_lock(&es8316->lock); - snd_soc_component_write(comp, ES8316_GPIO_DEBUNCE_INT_REG4E, 0xf0); - snd_soc_component_write(comp,0x01,0x7f); - msleep(500); + + snd_soc_component_write(comp, ES8316_GPIO_DEBOUNCE, 0xf0); + snd_soc_component_write(comp, ES8316_CLKMGR_CLKSW, 0x7f); + + msleep(500); + regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); if (flags == 0x00) goto out; /* Powered-down / reset */ @@ -629,121 +675,88 @@ static irqreturn_t es8316_irq(int irq, void *data) if (es8316->jd_inverted) flags ^= ES8316_GPIO_FLAG_HP_NOT_INSERTED; - //dapm = snd_soc_component_get_dapm(es8316->component); - - if(a){ - //es8316_enable_micbias_for_mic_gnd_short_detect(comp); - //es8316_disable_micbias_for_mic_gnd_short_detect(comp); - a++; - if(a=5) - a=0; - // - //snd_soc_dapm_force_enable_pin(dapm,""); - //snd_soc_dapm_disable_pin(dapm, "MIC1"); - //snd_soc_dapm_disable_pin(dapm, "MIC2"); - - } - - - - printk("%s, gpio flags %#04x\n", __func__, flags); + dev_dbg(comp->dev,"%s, gpio flags %#04x\n", __func__, flags); if (flags & ES8316_GPIO_FLAG_HP_NOT_INSERTED) { - printk("%s, removed detected--1!\n", __func__); - printk("%s, set pa enable to true!\n", __func__); - gpiod_set_value_cansleep(es8316->pa_enable, true); - snd_soc_component_write(comp,ES8316_ADC_PDN_LINSEL,0x20); + dev_dbg(comp->dev,"%s, removed detected--1!\n", __func__); + snd_soc_component_write(comp, ES8316_ADC_PDN_LINSEL, 0x20); /* Jack removed, or spurious IRQ? */ - //if (es8316->jack->status & SND_JACK_MICROPHONE) - // es8316_disable_micbias_for_mic_gnd_short_detect(comp); - if ((es8316->jack->status & SND_JACK_HEADPHONE)|a) { + if (es8316->jack->status & SND_JACK_HEADPHONE) { snd_soc_jack_report(es8316->jack, 0, SND_JACK_HEADSET | SND_JACK_BTN_0); - printk("%s. jack unplugged\n", __func__); - //snd_soc_dapm_force_enable_pin(dapm, "MIC1"); - //snd_soc_dapm_disable_pin(dapm, "MIC2"); - snd_soc_component_write(comp,ES8316_ADC_PDN_LINSEL,0x20); - if(a){ - snd_soc_jack_report(es8316->jack, + dev_dbg(comp->dev,"%s. jack unplugged\n", __func__); + snd_soc_component_write(comp, ES8316_ADC_PDN_LINSEL, 0x20); + snd_soc_jack_report(es8316->jack, SND_JACK_HEADSET, SND_JACK_HEADSET); - snd_soc_jack_report(es8316->jack, 0, + snd_soc_jack_report(es8316->jack, 0, SND_JACK_HEADSET | SND_JACK_BTN_0); - snd_soc_component_write(comp,ES8316_ADC_PDN_LINSEL,0x20); + snd_soc_component_write(comp, ES8316_ADC_PDN_LINSEL, 0x20); } - - } } else if (!(es8316->jack->status & SND_JACK_HEADPHONE)) { /* Jack inserted, determine type */ - snd_soc_component_write(comp, ES8316_GPIO_DEBUNCE_INT_REG4E, 0xf2); - snd_soc_component_write(comp, 0x0d, 0x00); - //es8316_enable_micbias_for_mic_gnd_short_detect(comp); + snd_soc_component_write(comp, ES8316_GPIO_DEBOUNCE, 0xf2); + snd_soc_component_write(comp, ES8316_SYS_PDN, 0x00); regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); + if (es8316->jd_inverted) flags ^= ES8316_GPIO_FLAG_HP_NOT_INSERTED; - printk("%s, gpio flags %#04x\n", __func__, flags); + + dev_dbg(comp->dev,"%s, gpio flags %#04x\n", __func__, flags); + if (flags & ES8316_GPIO_FLAG_HP_NOT_INSERTED) { /* Jack unplugged underneath us */ - printk("%s, Removal detected--2!\n", __func__); - printk("%s, set pa enable to true!\n", __func__); - gpiod_set_value_cansleep(es8316->pa_enable, true); - //es8316_disable_micbias_for_mic_gnd_short_detect(comp); - snd_soc_component_write(comp,ES8316_ADC_PDN_LINSEL,0x20); + dev_dbg(comp->dev,"%s, Removal detected--2!\n", __func__); + snd_soc_component_write(comp, ES8316_ADC_PDN_LINSEL, 0x20); } else if (flags & ES8316_GPIO_FLAG_GM_NOT_SHORTED) { - printk("%s, headset detected!\n", __func__); + dev_dbg(comp->dev,"%s, headset detected!\n", __func__); /* Open, headset */ - printk("%s, set pa enable to false!\n", __func__); - gpiod_set_value_cansleep(es8316->pa_enable, false); - snd_soc_component_write(comp,ES8316_ADC_PDN_LINSEL,0x30); + snd_soc_component_write(comp, ES8316_ADC_PDN_LINSEL, 0x30); snd_soc_jack_report(es8316->jack, SND_JACK_HEADSET, SND_JACK_HEADSET); /* Keep mic-gnd-short detection on for button press */ } else { /* Shorted, headphones */ - printk("%s, headphone detected!\n", __func__); - printk("%s, set pa enable to false!\n", __func__); -if(a) - {snd_soc_jack_report(es8316->jack, 0, SND_JACK_HEADSET | SND_JACK_BTN_0);} - gpiod_set_value_cansleep(es8316->pa_enable, false); + dev_dbg(comp->dev,"%s, headphone detected!\n", __func__); + + snd_soc_jack_report(es8316->jack, + 0, SND_JACK_HEADSET | SND_JACK_BTN_0); + snd_soc_jack_report(es8316->jack, SND_JACK_HEADPHONE, SND_JACK_HEADSET); - snd_soc_component_write(comp,ES8316_ADC_PDN_LINSEL,0x20); - + snd_soc_component_write(comp, ES8316_ADC_PDN_LINSEL, 0x20); - /* No longer need mic-gnd-short detection */ - //es8316_disable_micbias_for_mic_gnd_short_detect(comp); } } else if (es8316->jack->status & SND_JACK_MICROPHONE) { /* Interrupt while jack inserted, report button state */ - printk("%s, button detected!\n", __func__); - printk("%s, set pa enable to false!\n", __func__); - gpiod_set_value_cansleep(es8316->pa_enable, false); - snd_soc_component_write(comp,ES8316_ADC_PDN_LINSEL,0x30); - }else{ - if (flags & ES8316_GPIO_FLAG_GM_NOT_SHORTED) { - printk("%s, headset detected!\n", __func__); + dev_dbg(comp->dev,"%s, button detected!\n", __func__); + + snd_soc_component_write(comp, ES8316_ADC_PDN_LINSEL, 0x30); + } else { + if (flags & ES8316_GPIO_FLAG_GM_NOT_SHORTED) { + dev_dbg(comp->dev,"%s, headset detected!\n", __func__); + /* Open, headset */ - printk("%s, set pa enable to false!\n", __func__); - gpiod_set_value_cansleep(es8316->pa_enable, false); - snd_soc_component_write(comp,ES8316_ADC_PDN_LINSEL,0x30); -if(a) - {snd_soc_jack_report(es8316->jack, 0, SND_JACK_HEADSET);} + snd_soc_component_write(comp, ES8316_ADC_PDN_LINSEL, 0x30); + + snd_soc_jack_report(es8316->jack, 0, SND_JACK_HEADSET); + snd_soc_jack_report(es8316->jack, SND_JACK_HEADSET, SND_JACK_HEADSET); - //es8316_disable_micbias_for_mic_gnd_short_detect(comp); - - } - } + } + } out: - //snd_soc_dapm_sync(dapm); - mdelay(5); - snd_soc_component_write(comp, ES8316_GPIO_DEBUNCE_INT_REG4E, 0xf2); + mdelay(5); + + snd_soc_component_write(comp, ES8316_GPIO_DEBOUNCE, 0xf2); + mutex_unlock(&es8316->lock); - printk("Exit %s\n", __func__); + dev_dbg(comp->dev,"Exit %s\n", __func__); + return IRQ_HANDLED; } @@ -751,44 +764,33 @@ static void es8316_enable_jack_detect(struct snd_soc_component *component, struct snd_soc_jack *jack) { struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); - static int a=0; - printk("Enter into %s\n", __func__); - /* - * Init es8316->jd_inverted here and not in the probe, as we cannot - * guarantee that the bytchr-es8316 driver, which might set this - * property, will probe before us. - */ - //es8316->jd_inverted = device_property_read_bool(component->dev, - // "everest,jack-detect-inverted"); - if(!a){ - es8316->jd_inverted = false; - - mutex_lock(&es8316->lock); + static int initial = 0; - es8316->jack = jack; + if (!initial) { + es8316->jd_inverted = false; - if (es8316->jack->status & SND_JACK_MICROPHONE) - es8316_enable_micbias_for_mic_gnd_short_detect(component); + mutex_lock(&es8316->lock); - snd_soc_component_update_bits(component, ES8316_GPIO_DEBOUNCE, - ES8316_GPIO_ENABLE_INTERRUPT, - ES8316_GPIO_ENABLE_INTERRUPT); + es8316->jack = jack; + if (es8316->jack->status & SND_JACK_MICROPHONE) + es8316_enable_micbias_for_mic_gnd_short_detect(component); - mutex_unlock(&es8316->lock); - //disable_irq(es8316->irq); - /* Enable irq and sync initial jack state */ - enable_irq(es8316->irq); - es8316_irq(es8316->irq, es8316); - printk("exit %s\n", __func__);a=1; - }else{ + snd_soc_component_update_bits(component, ES8316_GPIO_DEBOUNCE, + ES8316_GPIO_ENABLE_INTERRUPT, + ES8316_GPIO_ENABLE_INTERRUPT); + + mutex_unlock(&es8316->lock); + /* Enable irq and sync initial jack state */ + enable_irq(es8316->irq); + es8316_irq(es8316->irq, es8316); + + initial = 1; } - } static void es8316_disable_jack_detect(struct snd_soc_component *component) { struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); - printk("Enter into %s\n", __func__); if (!es8316->jack) return; /* Already disabled (or never enabled) */ @@ -808,19 +810,16 @@ static void es8316_disable_jack_detect(struct snd_soc_component *component) es8316->jack = NULL; mutex_unlock(&es8316->lock); - printk("exit %s\n", __func__); } static int es8316_set_jack(struct snd_soc_component *component, struct snd_soc_jack *jack, void *data) { - printk("Enter into %s\n", __func__); if (jack) es8316_enable_jack_detect(component, jack); else es8316_disable_jack_detect(component); - printk("exit %s\n", __func__); return 0; } @@ -829,115 +828,25 @@ static int es8316_probe(struct snd_soc_component *component) struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); int ret; - printk("Enter into %s\n", __func__); es8316->component = component; - - es8316->pa_enable = devm_gpiod_get_optional(component->dev, "pa,enable", - GPIOD_OUT_LOW); - - if (IS_ERR(es8316->pa_enable)) { - ret = PTR_ERR(es8316->pa_enable); - printk("%s, Failed to get pa enable line: %d\n", __func__, ret); - return ret; - } - - gpiod_set_value_cansleep(es8316->pa_enable, true); - - es8316->mclk = devm_clk_get_optional(component->dev, "mclk"); if (IS_ERR(es8316->mclk)) { - printk("%s,unable to get mclk\n", __func__); + dev_err(component->dev, "unable to get mclk\n"); return PTR_ERR(es8316->mclk); } if (!es8316->mclk) - printk("%s, assuming static mclk\n", __func__); + dev_warn(component->dev, "assuming static mclk\n"); ret = clk_prepare_enable(es8316->mclk); if (ret) { - printk("%s, unable to enable mclk\n", __func__); + dev_err(component->dev, "unable to enable mclk\n"); return ret; } /* Reset codec and enable current state machine */ - snd_soc_component_write(component, ES8316_RESET_REG00, 0x3f); - usleep_range(5000, 5500); - snd_soc_component_write(component, ES8316_RESET_REG00, 0x00); - msleep(30); - snd_soc_component_write(component, ES8316_SYS_VMIDSEL_REG0C, 0xFF); - msleep(30); - snd_soc_component_write(component, ES8316_CLKMGR_CLKSEL_REG02, 0x09); - snd_soc_component_write(component, ES8316_CLKMGR_ADCOSR_REG03, 0x32); - snd_soc_component_write(component, ES8316_CLKMGR_ADCDIV1_REG04, 0x11); - snd_soc_component_write(component, ES8316_CLKMGR_ADCDIV2_REG05, 0x90); - snd_soc_component_write(component, ES8316_CLKMGR_DACDIV1_REG06, 0x11); - snd_soc_component_write(component, ES8316_CLKMGR_DACDIV2_REG07, 0x90); - snd_soc_component_write(component, ES8316_CLKMGR_CPDIV_REG08, 0x00); - snd_soc_component_write(component, ES8316_SDP_MS_BCKDIV_REG09, 0x04); - snd_soc_component_write(component, ES8316_CLKMGR_CLKSW_REG01, 0x7F); - snd_soc_component_write(component, ES8316_CAL_TYPE_REG1C, 0x0F); - snd_soc_component_write(component, ES8316_CAL_HPLIV_REG1E, 0x90); - snd_soc_component_write(component, ES8316_CAL_HPRIV_REG1F, 0x90); - snd_soc_component_write(component, ES8316_ADC_VOLUME_REG27, 0x00); - snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL_REG22, 0xc0); - snd_soc_component_write(component, ES8316_ADC_D2SEPGA_REG24, 0x00); - snd_soc_component_write(component, ES8316_ADC_DMIC_REG25, 0x08); - snd_soc_component_write(component, ES8316_DAC_SET2_REG31, 0x20); - snd_soc_component_write(component, ES8316_DAC_SET3_REG32, 0x00); - snd_soc_component_write(component, ES8316_DAC_VOLL_REG33, 0x00); - snd_soc_component_write(component, ES8316_DAC_VOLR_REG34, 0x00); - snd_soc_component_write(component, ES8316_SDP_ADCFMT_REG0A, 0x00); - snd_soc_component_write(component, ES8316_SDP_DACFMT_REG0B, 0x00); - snd_soc_component_write(component, ES8316_SYS_VMIDLOW_REG10, 0x11); - snd_soc_component_write(component, ES8316_SYS_VSEL_REG11, 0xFC); - snd_soc_component_write(component, ES8316_SYS_REF_REG12, 0x28); - snd_soc_component_write(component, ES8316_SYS_LP1_REG0E, 0x04); - snd_soc_component_write(component, ES8316_SYS_LP2_REG0F, 0x0C); - snd_soc_component_write(component, ES8316_DAC_PDN_REG2F, 0x11); - snd_soc_component_write(component, ES8316_HPMIX_SEL_REG13, 0x00); - snd_soc_component_write(component, ES8316_HPMIX_SWITCH_REG14, 0x88); - snd_soc_component_write(component, ES8316_HPMIX_PDN_REG15, 0x00); - snd_soc_component_write(component, ES8316_HPMIX_VOL_REG16, 0xBB); - snd_soc_component_write(component, ES8316_CPHP_PDN2_REG1A, 0x10); - snd_soc_component_write(component, ES8316_CPHP_LDOCTL_REG1B, 0x30); - snd_soc_component_write(component, ES8316_CPHP_PDN1_REG19, 0x02); - snd_soc_component_write(component, ES8316_CPHP_ICAL_VOL_REG18, 0x00); - snd_soc_component_write(component, ES8316_GPIO_SEL_REG4D, 0x00); - snd_soc_component_write(component, ES8316_GPIO_DEBUNCE_INT_REG4E, 0xf2); - snd_soc_component_write(component, ES8316_TESTMODE_REG50, 0xA0); - snd_soc_component_write(component,0x26,0x00); - snd_soc_component_write(component, ES8316_TEST1_REG51, 0x00); - snd_soc_component_write(component, ES8316_TEST2_REG52, 0x00); - snd_soc_component_write(component, ES8316_SYS_PDN_REG0D, 0x00); - snd_soc_component_write(component, ES8316_RESET_REG00, 0xC0); - msleep(50); - snd_soc_component_write(component, ES8316_ADC_PGAGAIN_REG23, 0x60); - snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL_REG22, 0x30); - snd_soc_component_write(component, ES8316_ADC_D2SEPGA_REG24, 0x00); - /* adc ds mode, HPF enable */ - snd_soc_component_write(component, ES8316_ADC_DMIC_REG25, 0x08); - snd_soc_component_write(component, ES8316_ADC_ALC1_REG29, 0xcd); - snd_soc_component_write(component, ES8316_ADC_ALC2_REG2A, 0x08); - snd_soc_component_write(component, ES8316_ADC_ALC3_REG2B, 0xa0); - snd_soc_component_write(component, ES8316_ADC_ALC4_REG2C, 0x05); - snd_soc_component_write(component, ES8316_ADC_ALC5_REG2D, 0x06); - snd_soc_component_write(component, ES8316_ADC_ALC6_REG2E, 0x61); + es8316_start(component); - /* - * Documentation is unclear, but this value from the vendor driver is - * needed otherwise audio output is silent. - */ - snd_soc_component_write(component, ES8316_SYS_VMIDSEL, 0xff); - - /* - * Documentation for this register is unclear and incomplete, - * but here is a vendor-provided value that improves volume - * and quality for Intel CHT platforms. - */ - snd_soc_component_write(component, ES8316_CLKMGR_ADCOSR, 0x32); - //snd_soc_component_write(component, ES8316_SYS_PDN_REG0D, 0x01); - - printk("exit %s\n", __func__); return 0; } @@ -951,6 +860,7 @@ static void es8316_remove(struct snd_soc_component *component) static const struct snd_soc_component_driver soc_component_dev_es8316 = { .probe = es8316_probe, .remove = es8316_remove, + .resume = es8316_resume, .set_jack = es8316_set_jack, .controls = es8316_snd_controls, .num_controls = ARRAY_SIZE(es8316_snd_controls), @@ -987,7 +897,6 @@ static int es8316_i2c_probe(struct i2c_client *i2c_client, struct es8316_priv *es8316; int ret; - printk("Enter into %s\n", __func__); es8316 = devm_kzalloc(&i2c_client->dev, sizeof(struct es8316_priv), GFP_KERNEL); if (es8316 == NULL) @@ -1013,7 +922,6 @@ static int es8316_i2c_probe(struct i2c_client *i2c_client, es8316->irq = -ENXIO; } - printk("exit %s\n", __func__); return devm_snd_soc_register_component(&i2c_client->dev, &soc_component_dev_es8316, &es8316_dai, 1); @@ -1037,7 +945,7 @@ MODULE_DEVICE_TABLE(of, es8316_of_match); #ifdef CONFIG_ACPI static const struct acpi_device_id es8316_acpi_match[] = { - //{"ESSX8316", 0}, + {"ESSX8316", 0}, {"ESSX8336", 0}, {}, }; @@ -1058,4 +966,3 @@ module_i2c_driver(es8316_i2c_driver); MODULE_DESCRIPTION("Everest Semi ES8316 ALSA SoC Codec Driver"); MODULE_AUTHOR("David Yang "); MODULE_LICENSE("GPL v2"); - diff --git a/sound/soc/codecs/es8316.h b/sound/soc/codecs/es8316.h index dcab9fd80a5908..c335138e283789 100644 --- a/sound/soc/codecs/es8316.h +++ b/sound/soc/codecs/es8316.h @@ -11,144 +11,7 @@ /* * ES8316 register space */ -#define ES8316_RESET_REG00 0x00 -/* -* Clock Managerment -*/ -#define ES8316_CLKMGR_CLKSW_REG01 0x01 -#define ES8316_CLKMGR_CLKSEL_REG02 0x02 -#define ES8316_CLKMGR_ADCOSR_REG03 0x03 -#define ES8316_CLKMGR_ADCDIV1_REG04 0x04 -#define ES8316_CLKMGR_ADCDIV2_REG05 0x05 -#define ES8316_CLKMGR_DACDIV1_REG06 0x06 -#define ES8316_CLKMGR_DACDIV2_REG07 0x07 -#define ES8316_CLKMGR_CPDIV_REG08 0x08 -/* -* SDP Control -*/ -#define ES8316_SDP_MS_BCKDIV_REG09 0x09 -#define ES8316_SDP_ADCFMT_REG0A 0x0a -#define ES8316_SDP_DACFMT_REG0B 0x0b -/* -* System Control -*/ -#define ES8316_SYS_VMIDSEL_REG0C 0x0c -#define ES8316_SYS_PDN_REG0D 0x0d -#define ES8316_SYS_LP1_REG0E 0x0e -#define ES8316_SYS_LP2_REG0F 0x0f -#define ES8316_SYS_VMIDLOW_REG10 0x10 -#define ES8316_SYS_VSEL_REG11 0x11 -#define ES8316_SYS_REF_REG12 0x12 -/* -* HP Mixer -*/ -#define ES8316_HPMIX_SEL_REG13 0x13 -#define ES8316_HPMIX_SWITCH_REG14 0x14 -#define ES8316_HPMIX_PDN_REG15 0x15 -#define ES8316_HPMIX_VOL_REG16 0x16 -/* -* Charge Pump Headphone driver -*/ -#define ES8316_CPHP_OUTEN_REG17 0x17 -#define ES8316_CPHP_ICAL_VOL_REG18 0x18 -#define ES8316_CPHP_PDN1_REG19 0x19 -#define ES8316_CPHP_PDN2_REG1A 0x1a -#define ES8316_CPHP_LDOCTL_REG1B 0x1b -/* -* Calibration -*/ -#define ES8316_CAL_TYPE_REG1C 0x1c -#define ES8316_CAL_SET_REG1D 0x1d -#define ES8316_CAL_HPLIV_REG1E 0x1e -#define ES8316_CAL_HPRIV_REG1F 0x1f -#define ES8316_CAL_HPLMV_REG20 0x20 -#define ES8316_CAL_HPRMV_REG21 0x21 -/* -* ADC Control -*/ -#define ES8316_ADC_PDN_LINSEL_REG22 0x22 -#define ES8316_ADC_PGAGAIN_REG23 0x23 -#define ES8316_ADC_D2SEPGA_REG24 0x24 -#define ES8316_ADC_DMIC_REG25 0x25 -#define ES8316_ADC_MUTE_REG26 0x26 -#define ES8316_ADC_VOLUME_REG27 0x27 -#define ES8316_ADC_ALC1_REG29 0x29 -#define ES8316_ADC_ALC2_REG2A 0x2a -#define ES8316_ADC_ALC3_REG2B 0x2b -#define ES8316_ADC_ALC4_REG2C 0x2c -#define ES8316_ADC_ALC5_REG2D 0x2d -#define ES8316_ADC_ALC6_REG2E 0x2e -/* -* DAC Control -*/ -#define ES8316_DAC_PDN_REG2F 0x2f -#define ES8316_DAC_SET1_REG30 0x30 -#define ES8316_DAC_SET2_REG31 0x31 -#define ES8316_DAC_SET3_REG32 0x32 -#define ES8316_DAC_VOLL_REG33 0x33 -#define ES8316_DAC_VOLR_REG34 0x34 -/* -* GPIO -*/ -#define ES8316_GPIO_SEL_REG4D 0x4D -#define ES8316_GPIO_DEBUNCE_INT_REG4E 0x4E -#define ES8316_GPIO_FLAG 0x4F -/* -* TEST MODE -*/ -#define ES8316_TESTMODE_REG50 0x50 -#define ES8316_TEST1_REG51 0x51 -#define ES8316_TEST2_REG52 0x52 -#define ES8316_TEST3_REG53 0x53 - -#define ES8316_IFACE ES8316_SDP_MS_BCKDIV_REG09 -#define ES8316_ADC_IFACE ES8316_SDP_ADCFMT_REG0A -#define ES8316_DAC_IFACE ES8316_SDP_DACFMT_REG0B - -#define ES8316_REGNUM 84 - -/* REGISTER 0X01 CLOCK MANAGER */ -#define ES8316_CLKMGR_MCLK_DIV_MASK (0X1<<7) -#define ES8316_CLKMGR_MCLK_DIV_NML (0X0<<7) -#define ES8316_CLKMGR_MCLK_DIV_1 (0X1<<7) -#define ES8316_CLKMGR_ADC_MCLK_MASK (0X1<<3) -#define ES8316_CLKMGR_ADC_MCLK_EN (0X1<<3) -#define ES8316_CLKMGR_ADC_MCLK_DIS (0X0<<3) -#define ES8316_CLKMGR_DAC_MCLK_MASK (0X1<<2) -#define ES8316_CLKMGR_DAC_MCLK_EN (0X1<<2) -#define ES8316_CLKMGR_DAC_MCLK_DIS (0X0<<2) -#define ES8316_CLKMGR_ADC_ANALOG_MASK (0X1<<1) -#define ES8316_CLKMGR_ADC_ANALOG_EN (0X1<<1) -#define ES8316_CLKMGR_ADC_ANALOG_DIS (0X0<<1) -#define ES8316_CLKMGR_DAC_ANALOG_MASK (0X1<<0) -#define ES8316_CLKMGR_DAC_ANALOG_EN (0X1<<0) -#define ES8316_CLKMGR_DAC_ANALOG_DIS (0X0<<0) - -/* REGISTER 0X0A */ -#define ES8316_ADCWL_MASK (0x7 << 2) -#define ES8316_ADCWL_32 (0x4 << 2) -#define ES8316_ADCWL_24 (0x0 << 2) -#define ES8316_ADCWL_20 (0x1 << 2) -#define ES8316_ADCWL_18 (0x2 << 2) -#define ES8316_ADCWL_16 (0x3 << 2) -#define ES8316_ADCFMT_MASK (0x3 << 0) -#define ES8316_ADCFMT_I2S (0x0 << 0) -#define ES8316_ADCWL_LEFT (0x1 << 0) -#define ES8316_ADCWL_RIGHT (0x2 << 0) -#define ES8316_ADCWL_PCM (0x3 << 0) -/* REGISTER 0X0B */ -#define ES8316_DACWL_MASK (0x7 << 2) -#define ES8316_DACWL_32 (0x4 << 2) -#define ES8316_DACWL_24 (0x0 << 2) -#define ES8316_DACWL_20 (0x1 << 2) -#define ES8316_DACWL_18 (0x2 << 2) -#define ES8316_DACWL_16 (0x3 << 2) -#define ES8316_DACFMT_MASK (0x3 << 0) -#define ES8316_DACFMT_I2S (0x0 << 0) -#define ES8316_DACWL_LEFT (0x1 << 0) -#define ES8316_DACWL_RIGHT (0x2 << 0) -#define ES8316_DACWL_PCM (0x3 << 0) /* Reset Control */ #define ES8316_RESET 0x00