diff options
Diffstat (limited to 'sound/soc/codecs/rt5659.c')
-rw-r--r-- | sound/soc/codecs/rt5659.c | 472 |
1 files changed, 297 insertions, 175 deletions
diff --git a/sound/soc/codecs/rt5659.c b/sound/soc/codecs/rt5659.c index 07e7757417bc..1c1a521c73cb 100644 --- a/sound/soc/codecs/rt5659.c +++ b/sound/soc/codecs/rt5659.c @@ -1238,26 +1238,26 @@ static SOC_VALUE_ENUM_SINGLE_DECL( static int rt5659_hp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); + struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); int ret = snd_soc_put_volsw(kcontrol, ucontrol); - if (snd_soc_read(codec, RT5659_STO_NG2_CTRL_1) & RT5659_NG2_EN) { - snd_soc_update_bits(codec, RT5659_STO_NG2_CTRL_1, + if (snd_soc_component_read32(component, RT5659_STO_NG2_CTRL_1) & RT5659_NG2_EN) { + snd_soc_component_update_bits(component, RT5659_STO_NG2_CTRL_1, RT5659_NG2_EN_MASK, RT5659_NG2_DIS); - snd_soc_update_bits(codec, RT5659_STO_NG2_CTRL_1, + snd_soc_component_update_bits(component, RT5659_STO_NG2_CTRL_1, RT5659_NG2_EN_MASK, RT5659_NG2_EN); } return ret; } -static void rt5659_enable_push_button_irq(struct snd_soc_codec *codec, +static void rt5659_enable_push_button_irq(struct snd_soc_component *component, bool enable) { - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); if (enable) { - snd_soc_write(codec, RT5659_4BTN_IL_CMD_1, 0x000b); + snd_soc_component_write(component, RT5659_4BTN_IL_CMD_1, 0x000b); /* MICBIAS1 and Mic Det Power for button detect*/ snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); @@ -1265,19 +1265,19 @@ static void rt5659_enable_push_button_irq(struct snd_soc_codec *codec, "Mic Det Power"); snd_soc_dapm_sync(dapm); - snd_soc_update_bits(codec, RT5659_PWR_ANLG_2, + snd_soc_component_update_bits(component, RT5659_PWR_ANLG_2, RT5659_PWR_MB1, RT5659_PWR_MB1); - snd_soc_update_bits(codec, RT5659_PWR_VOL, + snd_soc_component_update_bits(component, RT5659_PWR_VOL, RT5659_PWR_MIC_DET, RT5659_PWR_MIC_DET); - snd_soc_update_bits(codec, RT5659_IRQ_CTRL_2, + snd_soc_component_update_bits(component, RT5659_IRQ_CTRL_2, RT5659_IL_IRQ_MASK, RT5659_IL_IRQ_EN); - snd_soc_update_bits(codec, RT5659_4BTN_IL_CMD_2, + snd_soc_component_update_bits(component, RT5659_4BTN_IL_CMD_2, RT5659_4BTN_IL_MASK, RT5659_4BTN_IL_EN); } else { - snd_soc_update_bits(codec, RT5659_4BTN_IL_CMD_2, + snd_soc_component_update_bits(component, RT5659_4BTN_IL_CMD_2, RT5659_4BTN_IL_MASK, RT5659_4BTN_IL_DIS); - snd_soc_update_bits(codec, RT5659_IRQ_CTRL_2, + snd_soc_component_update_bits(component, RT5659_IRQ_CTRL_2, RT5659_IL_IRQ_MASK, RT5659_IL_IRQ_DIS); /* MICBIAS1 and Mic Det Power for button detect*/ snd_soc_dapm_disable_pin(dapm, "MICBIAS1"); @@ -1288,7 +1288,7 @@ static void rt5659_enable_push_button_irq(struct snd_soc_codec *codec, /** * rt5659_headset_detect - Detect headset. - * @codec: SoC audio codec device. + * @component: SoC audio component device. * @jack_insert: Jack insert or not. * * Detect whether is headset or not when jack inserted. @@ -1296,37 +1296,37 @@ static void rt5659_enable_push_button_irq(struct snd_soc_codec *codec, * Returns detect status. */ -static int rt5659_headset_detect(struct snd_soc_codec *codec, int jack_insert) +static int rt5659_headset_detect(struct snd_soc_component *component, int jack_insert) { - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); int val, i = 0, sleep_time[5] = {300, 150, 100, 50, 30}; int reg_63; - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); if (jack_insert) { snd_soc_dapm_force_enable_pin(dapm, "Mic Det Power"); snd_soc_dapm_sync(dapm); - reg_63 = snd_soc_read(codec, RT5659_PWR_ANLG_1); + reg_63 = snd_soc_component_read32(component, RT5659_PWR_ANLG_1); - snd_soc_update_bits(codec, RT5659_PWR_ANLG_1, + snd_soc_component_update_bits(component, RT5659_PWR_ANLG_1, RT5659_PWR_VREF2 | RT5659_PWR_MB, RT5659_PWR_VREF2 | RT5659_PWR_MB); msleep(20); - snd_soc_update_bits(codec, RT5659_PWR_ANLG_1, + snd_soc_component_update_bits(component, RT5659_PWR_ANLG_1, RT5659_PWR_FV2, RT5659_PWR_FV2); - snd_soc_write(codec, RT5659_EJD_CTRL_2, 0x4160); - snd_soc_update_bits(codec, RT5659_EJD_CTRL_1, + snd_soc_component_write(component, RT5659_EJD_CTRL_2, 0x4160); + snd_soc_component_update_bits(component, RT5659_EJD_CTRL_1, 0x20, 0x0); msleep(20); - snd_soc_update_bits(codec, RT5659_EJD_CTRL_1, + snd_soc_component_update_bits(component, RT5659_EJD_CTRL_1, 0x20, 0x20); while (i < 5) { msleep(sleep_time[i]); - val = snd_soc_read(codec, RT5659_EJD_CTRL_2) & 0x0003; + val = snd_soc_component_read32(component, RT5659_EJD_CTRL_2) & 0x0003; i++; if (val == 0x1 || val == 0x2 || val == 0x3) break; @@ -1335,10 +1335,10 @@ static int rt5659_headset_detect(struct snd_soc_codec *codec, int jack_insert) switch (val) { case 1: rt5659->jack_type = SND_JACK_HEADSET; - rt5659_enable_push_button_irq(codec, true); + rt5659_enable_push_button_irq(component, true); break; default: - snd_soc_write(codec, RT5659_PWR_ANLG_1, reg_63); + snd_soc_component_write(component, RT5659_PWR_ANLG_1, reg_63); rt5659->jack_type = SND_JACK_HEADPHONE; snd_soc_dapm_disable_pin(dapm, "Mic Det Power"); snd_soc_dapm_sync(dapm); @@ -1348,21 +1348,21 @@ static int rt5659_headset_detect(struct snd_soc_codec *codec, int jack_insert) snd_soc_dapm_disable_pin(dapm, "Mic Det Power"); snd_soc_dapm_sync(dapm); if (rt5659->jack_type == SND_JACK_HEADSET) - rt5659_enable_push_button_irq(codec, false); + rt5659_enable_push_button_irq(component, false); rt5659->jack_type = 0; } - dev_dbg(codec->dev, "jack_type = %d\n", rt5659->jack_type); + dev_dbg(component->dev, "jack_type = %d\n", rt5659->jack_type); return rt5659->jack_type; } -static int rt5659_button_detect(struct snd_soc_codec *codec) +static int rt5659_button_detect(struct snd_soc_component *component) { int btn_type, val; - val = snd_soc_read(codec, RT5659_4BTN_IL_CMD_1); + val = snd_soc_component_read32(component, RT5659_4BTN_IL_CMD_1); btn_type = val & 0xfff0; - snd_soc_write(codec, RT5659_4BTN_IL_CMD_1, val); + snd_soc_component_write(component, RT5659_4BTN_IL_CMD_1, val); return btn_type; } @@ -1377,10 +1377,10 @@ static irqreturn_t rt5659_irq(int irq, void *data) return IRQ_HANDLED; } -int rt5659_set_jack_detect(struct snd_soc_codec *codec, +int rt5659_set_jack_detect(struct snd_soc_component *component, struct snd_soc_jack *hs_jack) { - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); rt5659->hs_jack = hs_jack; @@ -1396,19 +1396,19 @@ static void rt5659_jack_detect_work(struct work_struct *work) container_of(work, struct rt5659_priv, jack_detect_work.work); int val, btn_type, report = 0; - if (!rt5659->codec) + if (!rt5659->component) return; - val = snd_soc_read(rt5659->codec, RT5659_INT_ST_1) & 0x0080; + val = snd_soc_component_read32(rt5659->component, RT5659_INT_ST_1) & 0x0080; if (!val) { /* jack in */ if (rt5659->jack_type == 0) { /* jack was out, report jack type */ - report = rt5659_headset_detect(rt5659->codec, 1); + report = rt5659_headset_detect(rt5659->component, 1); } else { /* jack is already in, report button event */ report = SND_JACK_HEADSET; - btn_type = rt5659_button_detect(rt5659->codec); + btn_type = rt5659_button_detect(rt5659->component); /** * rt5659 can report three kinds of button behavior, * one click, double click and hold. However, @@ -1441,7 +1441,7 @@ static void rt5659_jack_detect_work(struct work_struct *work) break; default: btn_type = 0; - dev_err(rt5659->codec->dev, + dev_err(rt5659->component->dev, "Unexpected button code 0x%04x\n", btn_type); break; @@ -1453,7 +1453,7 @@ static void rt5659_jack_detect_work(struct work_struct *work) } } else { /* jack out */ - report = rt5659_headset_detect(rt5659->codec, 0); + report = rt5659_headset_detect(rt5659->component, 0); } snd_soc_jack_report(rt5659->hs_jack, report, SND_JACK_HEADSET | @@ -1461,6 +1461,61 @@ static void rt5659_jack_detect_work(struct work_struct *work) SND_JACK_BTN_2 | SND_JACK_BTN_3); } +static void rt5659_jack_detect_intel_hd_header(struct work_struct *work) +{ + struct rt5659_priv *rt5659 = + container_of(work, struct rt5659_priv, jack_detect_work.work); + unsigned int value; + bool hp_flag, mic_flag; + + if (!rt5659->hs_jack) + return; + + /* headphone jack */ + regmap_read(rt5659->regmap, RT5659_GPIO_STA, &value); + hp_flag = (!(value & 0x8)) ? true : false; + + if (hp_flag != rt5659->hda_hp_plugged) { + rt5659->hda_hp_plugged = hp_flag; + + if (hp_flag) { + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1, + 0x10, 0x0); + rt5659->jack_type |= SND_JACK_HEADPHONE; + } else { + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1, + 0x10, 0x10); + rt5659->jack_type = rt5659->jack_type & + (~SND_JACK_HEADPHONE); + } + + snd_soc_jack_report(rt5659->hs_jack, rt5659->jack_type, + SND_JACK_HEADPHONE); + } + + /* mic jack */ + regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value); + regmap_write(rt5659->regmap, RT5659_4BTN_IL_CMD_1, value); + mic_flag = (value & 0x2000) ? true : false; + + if (mic_flag != rt5659->hda_mic_plugged) { + rt5659->hda_mic_plugged = mic_flag; + if (mic_flag) { + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, + 0x2, 0x2); + rt5659->jack_type |= SND_JACK_MICROPHONE; + } else { + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, + 0x2, 0x0); + rt5659->jack_type = rt5659->jack_type + & (~SND_JACK_MICROPHONE); + } + + snd_soc_jack_report(rt5659->hs_jack, rt5659->jack_type, + SND_JACK_MICROPHONE); + } +} + static const struct snd_kcontrol_new rt5659_snd_controls[] = { /* Speaker Output Volume */ SOC_DOUBLE_TLV("Speaker Playback Volume", RT5659_SPO_VOL, @@ -1550,8 +1605,8 @@ static const struct snd_kcontrol_new rt5659_snd_controls[] = { static int set_dmic_clk(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); int pd, idx = -EINVAL; pd = rl6231_get_pre_div(rt5659->regmap, @@ -1559,29 +1614,55 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w, idx = rl6231_calc_dmic_clk(rt5659->sysclk / pd); if (idx < 0) - dev_err(codec->dev, "Failed to set DMIC clock\n"); + dev_err(component->dev, "Failed to set DMIC clock\n"); else { - snd_soc_update_bits(codec, RT5659_DMIC_CTRL_1, + snd_soc_component_update_bits(component, RT5659_DMIC_CTRL_1, RT5659_DMIC_CLK_MASK, idx << RT5659_DMIC_CLK_SFT); } return idx; } -static int set_adc_clk(struct snd_soc_dapm_widget *w, +static int set_adc1_clk(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_update_bits(codec, RT5659_CHOP_ADC, - RT5659_CKXEN_ADCC_MASK | RT5659_CKGEN_ADCC_MASK, - RT5659_CKXEN_ADCC_MASK | RT5659_CKGEN_ADCC_MASK); + snd_soc_component_update_bits(component, RT5659_CHOP_ADC, + RT5659_CKXEN_ADC1_MASK | RT5659_CKGEN_ADC1_MASK, + RT5659_CKXEN_ADC1_MASK | RT5659_CKGEN_ADC1_MASK); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_update_bits(codec, RT5659_CHOP_ADC, - RT5659_CKXEN_ADCC_MASK | RT5659_CKGEN_ADCC_MASK, 0); + snd_soc_component_update_bits(component, RT5659_CHOP_ADC, + RT5659_CKXEN_ADC1_MASK | RT5659_CKGEN_ADC1_MASK, 0); + break; + + default: + return 0; + } + + return 0; + +} + +static int set_adc2_clk(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *component = + snd_soc_dapm_to_component(w->dapm); + + switch (event) { + case SND_SOC_DAPM_POST_PMU: + snd_soc_component_update_bits(component, RT5659_CHOP_ADC, + RT5659_CKXEN_ADC2_MASK | RT5659_CKGEN_ADC2_MASK, + RT5659_CKXEN_ADC2_MASK | RT5659_CKGEN_ADC2_MASK); + break; + + case SND_SOC_DAPM_PRE_PMD: + snd_soc_component_update_bits(component, RT5659_CHOP_ADC, + RT5659_CKXEN_ADC2_MASK | RT5659_CKGEN_ADC2_MASK, 0); break; default: @@ -1595,15 +1676,15 @@ static int set_adc_clk(struct snd_soc_dapm_widget *w, static int rt5659_charge_pump_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_PRE_PMU: /* Depop */ - snd_soc_write(codec, RT5659_DEPOP_1, 0x0009); + snd_soc_component_write(component, RT5659_DEPOP_1, 0x0009); break; case SND_SOC_DAPM_POST_PMD: - snd_soc_write(codec, RT5659_HP_CHARGE_PUMP_1, 0x0c16); + snd_soc_component_write(component, RT5659_HP_CHARGE_PUMP_1, 0x0c16); break; default: return 0; @@ -1616,9 +1697,9 @@ static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *w, struct snd_soc_dapm_widget *sink) { unsigned int val; - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); - val = snd_soc_read(codec, RT5659_GLB_CLK); + val = snd_soc_component_read32(component, RT5659_GLB_CLK); val &= RT5659_SCLK_SRC_MASK; if (val == RT5659_SCLK_SRC_PLL1) return 1; @@ -1630,7 +1711,7 @@ static int is_using_asrc(struct snd_soc_dapm_widget *w, struct snd_soc_dapm_widget *sink) { unsigned int reg, shift, val; - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (w->shift) { case RT5659_ADC_MONO_R_ASRC_SFT: @@ -1661,13 +1742,13 @@ static int is_using_asrc(struct snd_soc_dapm_widget *w, return 0; } - val = (snd_soc_read(codec, reg) >> shift) & 0xf; + val = (snd_soc_component_read32(component, reg) >> shift) & 0xf; switch (val) { case 1: case 2: case 3: /* I2S_Pre_Div1 should be 1 in asrc mode */ - snd_soc_update_bits(codec, RT5659_ADDA_CLK_1, + snd_soc_component_update_bits(component, RT5659_ADDA_CLK_1, RT5659_I2S_PD1_MASK, RT5659_I2S_PD1_2); return 1; default: @@ -2303,24 +2384,24 @@ static const struct snd_kcontrol_new pdm_r_switch = static int rt5659_spk_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_PRE_PMU: - snd_soc_update_bits(codec, RT5659_CLASSD_CTRL_1, + snd_soc_component_update_bits(component, RT5659_CLASSD_CTRL_1, RT5659_POW_CLSD_DB_MASK, RT5659_POW_CLSD_DB_EN); - snd_soc_update_bits(codec, RT5659_CLASSD_2, + snd_soc_component_update_bits(component, RT5659_CLASSD_2, RT5659_M_RI_DIG, RT5659_M_RI_DIG); - snd_soc_write(codec, RT5659_CLASSD_1, 0x0803); - snd_soc_write(codec, RT5659_SPK_DC_CAILB_CTRL_3, 0x0000); + snd_soc_component_write(component, RT5659_CLASSD_1, 0x0803); + snd_soc_component_write(component, RT5659_SPK_DC_CAILB_CTRL_3, 0x0000); break; case SND_SOC_DAPM_POST_PMD: - snd_soc_write(codec, RT5659_CLASSD_1, 0x0011); - snd_soc_update_bits(codec, RT5659_CLASSD_2, + snd_soc_component_write(component, RT5659_CLASSD_1, 0x0011); + snd_soc_component_update_bits(component, RT5659_CLASSD_2, RT5659_M_RI_DIG, 0x0); - snd_soc_write(codec, RT5659_SPK_DC_CAILB_CTRL_3, 0x0003); - snd_soc_update_bits(codec, RT5659_CLASSD_CTRL_1, + snd_soc_component_write(component, RT5659_SPK_DC_CAILB_CTRL_3, 0x0003); + snd_soc_component_update_bits(component, RT5659_CLASSD_CTRL_1, RT5659_POW_CLSD_DB_MASK, RT5659_POW_CLSD_DB_DIS); break; @@ -2335,15 +2416,15 @@ static int rt5659_spk_event(struct snd_soc_dapm_widget *w, static int rt5659_mono_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_PRE_PMU: - snd_soc_write(codec, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e00); + snd_soc_component_write(component, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e00); break; case SND_SOC_DAPM_POST_PMD: - snd_soc_write(codec, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e04); + snd_soc_component_write(component, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e04); break; default: @@ -2357,16 +2438,16 @@ static int rt5659_mono_event(struct snd_soc_dapm_widget *w, static int rt5659_hp_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_write(codec, RT5659_HP_CHARGE_PUMP_1, 0x0e1e); - snd_soc_update_bits(codec, RT5659_DEPOP_1, 0x0010, 0x0010); + snd_soc_component_write(component, RT5659_HP_CHARGE_PUMP_1, 0x0e1e); + snd_soc_component_update_bits(component, RT5659_DEPOP_1, 0x0010, 0x0010); break; case SND_SOC_DAPM_PRE_PMD: - snd_soc_write(codec, RT5659_DEPOP_1, 0x0000); + snd_soc_component_write(component, RT5659_DEPOP_1, 0x0000); break; default: @@ -2500,13 +2581,13 @@ static const struct snd_soc_dapm_widget rt5659_dapm_widgets[] = { RT5659_PWR_ADC_L1_BIT, 0, NULL, 0), SND_SOC_DAPM_SUPPLY("ADC1 R Power", RT5659_PWR_DIG_1, RT5659_PWR_ADC_R1_BIT, 0, NULL, 0), - SND_SOC_DAPM_SUPPLY("ADC2 L Power", RT5659_PWR_DIG_2, + SND_SOC_DAPM_SUPPLY("ADC2 L Power", RT5659_PWR_DIG_1, RT5659_PWR_ADC_L2_BIT, 0, NULL, 0), - SND_SOC_DAPM_SUPPLY("ADC2 R Power", RT5659_PWR_DIG_2, + SND_SOC_DAPM_SUPPLY("ADC2 R Power", RT5659_PWR_DIG_1, RT5659_PWR_ADC_R2_BIT, 0, NULL, 0), - SND_SOC_DAPM_SUPPLY("ADC1 clock", SND_SOC_NOPM, 0, 0, set_adc_clk, + SND_SOC_DAPM_SUPPLY("ADC1 clock", SND_SOC_NOPM, 0, 0, set_adc1_clk, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), - SND_SOC_DAPM_SUPPLY("ADC2 clock", SND_SOC_NOPM, 0, 0, set_adc_clk, + SND_SOC_DAPM_SUPPLY("ADC2 clock", SND_SOC_NOPM, 0, 0, set_adc2_clk, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), /* ADC Mux */ @@ -2818,11 +2899,6 @@ static const struct snd_soc_dapm_route rt5659_dapm_routes[] = { { "I2S2", NULL, "I2S2 ASRC" }, { "I2S3", NULL, "I2S3 ASRC" }, - { "IN1P", NULL, "LDO2" }, - { "IN2P", NULL, "LDO2" }, - { "IN3P", NULL, "LDO2" }, - { "IN4P", NULL, "LDO2" }, - { "DMIC1", NULL, "DMIC L1" }, { "DMIC1", NULL, "DMIC R1" }, { "DMIC2", NULL, "DMIC L2" }, @@ -3237,21 +3313,21 @@ static const struct snd_soc_dapm_route rt5659_dapm_routes[] = { static int rt5659_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); unsigned int val_len = 0, val_clk, mask_clk; int pre_div, frame_size; rt5659->lrck[dai->id] = params_rate(params); pre_div = rl6231_get_clk_info(rt5659->sysclk, rt5659->lrck[dai->id]); if (pre_div < 0) { - dev_err(codec->dev, "Unsupported clock setting %d for DAI %d\n", + dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n", rt5659->lrck[dai->id], dai->id); return -EINVAL; } frame_size = snd_soc_params_to_frame_size(params); if (frame_size < 0) { - dev_err(codec->dev, "Unsupported frame size: %d\n", frame_size); + dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); return -EINVAL; } @@ -3278,39 +3354,39 @@ static int rt5659_hw_params(struct snd_pcm_substream *substream, case RT5659_AIF1: mask_clk = RT5659_I2S_PD1_MASK; val_clk = pre_div << RT5659_I2S_PD1_SFT; - snd_soc_update_bits(codec, RT5659_I2S1_SDP, + snd_soc_component_update_bits(component, RT5659_I2S1_SDP, RT5659_I2S_DL_MASK, val_len); break; case RT5659_AIF2: mask_clk = RT5659_I2S_PD2_MASK; val_clk = pre_div << RT5659_I2S_PD2_SFT; - snd_soc_update_bits(codec, RT5659_I2S2_SDP, + snd_soc_component_update_bits(component, RT5659_I2S2_SDP, RT5659_I2S_DL_MASK, val_len); break; case RT5659_AIF3: mask_clk = RT5659_I2S_PD3_MASK; val_clk = pre_div << RT5659_I2S_PD3_SFT; - snd_soc_update_bits(codec, RT5659_I2S3_SDP, + snd_soc_component_update_bits(component, RT5659_I2S3_SDP, RT5659_I2S_DL_MASK, val_len); break; default: - dev_err(codec->dev, "Invalid dai->id: %d\n", dai->id); + dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); return -EINVAL; } - snd_soc_update_bits(codec, RT5659_ADDA_CLK_1, mask_clk, val_clk); + snd_soc_component_update_bits(component, RT5659_ADDA_CLK_1, mask_clk, val_clk); switch (rt5659->lrck[dai->id]) { case 192000: - snd_soc_update_bits(codec, RT5659_ADDA_CLK_1, + snd_soc_component_update_bits(component, RT5659_ADDA_CLK_1, RT5659_DAC_OSR_MASK, RT5659_DAC_OSR_32); break; case 96000: - snd_soc_update_bits(codec, RT5659_ADDA_CLK_1, + snd_soc_component_update_bits(component, RT5659_ADDA_CLK_1, RT5659_DAC_OSR_MASK, RT5659_DAC_OSR_64); break; default: - snd_soc_update_bits(codec, RT5659_ADDA_CLK_1, + snd_soc_component_update_bits(component, RT5659_ADDA_CLK_1, RT5659_DAC_OSR_MASK, RT5659_DAC_OSR_128); break; } @@ -3320,8 +3396,8 @@ static int rt5659_hw_params(struct snd_pcm_substream *substream, static int rt5659_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) { - struct snd_soc_codec *codec = dai->codec; - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); unsigned int reg_val = 0; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { @@ -3364,31 +3440,31 @@ static int rt5659_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) switch (dai->id) { case RT5659_AIF1: - snd_soc_update_bits(codec, RT5659_I2S1_SDP, + snd_soc_component_update_bits(component, RT5659_I2S1_SDP, RT5659_I2S_MS_MASK | RT5659_I2S_BP_MASK | RT5659_I2S_DF_MASK, reg_val); break; case RT5659_AIF2: - snd_soc_update_bits(codec, RT5659_I2S2_SDP, + snd_soc_component_update_bits(component, RT5659_I2S2_SDP, RT5659_I2S_MS_MASK | RT5659_I2S_BP_MASK | RT5659_I2S_DF_MASK, reg_val); break; case RT5659_AIF3: - snd_soc_update_bits(codec, RT5659_I2S3_SDP, + snd_soc_component_update_bits(component, RT5659_I2S3_SDP, RT5659_I2S_MS_MASK | RT5659_I2S_BP_MASK | RT5659_I2S_DF_MASK, reg_val); break; default: - dev_err(codec->dev, "Invalid dai->id: %d\n", dai->id); + dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); return -EINVAL; } return 0; } -static int rt5659_set_codec_sysclk(struct snd_soc_codec *codec, int clk_id, +static int rt5659_set_component_sysclk(struct snd_soc_component *component, int clk_id, int source, unsigned int freq, int dir) { - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); unsigned int reg_val = 0; if (freq == rt5659->sysclk && clk_id == rt5659->sysclk_src) @@ -3405,25 +3481,25 @@ static int rt5659_set_codec_sysclk(struct snd_soc_codec *codec, int clk_id, reg_val |= RT5659_SCLK_SRC_RCCLK; break; default: - dev_err(codec->dev, "Invalid clock id (%d)\n", clk_id); + dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); return -EINVAL; } - snd_soc_update_bits(codec, RT5659_GLB_CLK, + snd_soc_component_update_bits(component, RT5659_GLB_CLK, RT5659_SCLK_SRC_MASK, reg_val); rt5659->sysclk = freq; rt5659->sysclk_src = clk_id; - dev_dbg(codec->dev, "Sysclk is %dHz and clock id is %d\n", + dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); return 0; } -static int rt5659_set_codec_pll(struct snd_soc_codec *codec, int pll_id, +static int rt5659_set_component_pll(struct snd_soc_component *component, int pll_id, int source, unsigned int freq_in, unsigned int freq_out) { - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); struct rl6231_pll_code pll_code; int ret; @@ -3432,50 +3508,50 @@ static int rt5659_set_codec_pll(struct snd_soc_codec *codec, int pll_id, return 0; if (!freq_in || !freq_out) { - dev_dbg(codec->dev, "PLL disabled\n"); + dev_dbg(component->dev, "PLL disabled\n"); rt5659->pll_in = 0; rt5659->pll_out = 0; - snd_soc_update_bits(codec, RT5659_GLB_CLK, + snd_soc_component_update_bits(component, RT5659_GLB_CLK, RT5659_SCLK_SRC_MASK, RT5659_SCLK_SRC_MCLK); return 0; } switch (source) { case RT5659_PLL1_S_MCLK: - snd_soc_update_bits(codec, RT5659_GLB_CLK, + snd_soc_component_update_bits(component, RT5659_GLB_CLK, RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_MCLK); break; case RT5659_PLL1_S_BCLK1: - snd_soc_update_bits(codec, RT5659_GLB_CLK, + snd_soc_component_update_bits(component, RT5659_GLB_CLK, RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_BCLK1); break; case RT5659_PLL1_S_BCLK2: - snd_soc_update_bits(codec, RT5659_GLB_CLK, + snd_soc_component_update_bits(component, RT5659_GLB_CLK, RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_BCLK2); break; case RT5659_PLL1_S_BCLK3: - snd_soc_update_bits(codec, RT5659_GLB_CLK, + snd_soc_component_update_bits(component, RT5659_GLB_CLK, RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_BCLK3); break; default: - dev_err(codec->dev, "Unknown PLL source %d\n", source); + dev_err(component->dev, "Unknown PLL source %d\n", source); return -EINVAL; } ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); if (ret < 0) { - dev_err(codec->dev, "Unsupport input clock %d\n", freq_in); + dev_err(component->dev, "Unsupport input clock %d\n", freq_in); return ret; } - dev_dbg(codec->dev, "bypass=%d m=%d n=%d k=%d\n", + dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), pll_code.n_code, pll_code.k_code); - snd_soc_write(codec, RT5659_PLL_CTRL_1, + snd_soc_component_write(component, RT5659_PLL_CTRL_1, pll_code.n_code << RT5659_PLL_N_SFT | pll_code.k_code); - snd_soc_write(codec, RT5659_PLL_CTRL_2, + snd_soc_component_write(component, RT5659_PLL_CTRL_2, (pll_code.m_bp ? 0 : pll_code.m_code) << RT5659_PLL_M_SFT | pll_code.m_bp << RT5659_PLL_M_BP_SFT); @@ -3489,7 +3565,7 @@ static int rt5659_set_codec_pll(struct snd_soc_codec *codec, int pll_id, static int rt5659_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) { - struct snd_soc_codec *codec = dai->codec; + struct snd_soc_component *component = dai->component; unsigned int val = 0; if (rx_mask || tx_mask) @@ -3533,29 +3609,29 @@ static int rt5659_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, return -EINVAL; } - snd_soc_update_bits(codec, RT5659_TDM_CTRL_1, 0x8ff0, val); + snd_soc_component_update_bits(component, RT5659_TDM_CTRL_1, 0x8ff0, val); return 0; } static int rt5659_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) { - struct snd_soc_codec *codec = dai->codec; - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); - dev_dbg(codec->dev, "%s ratio=%d\n", __func__, ratio); + dev_dbg(component->dev, "%s ratio=%d\n", __func__, ratio); rt5659->bclk[dai->id] = ratio; if (ratio == 64) { switch (dai->id) { case RT5659_AIF2: - snd_soc_update_bits(codec, RT5659_ADDA_CLK_1, + snd_soc_component_update_bits(component, RT5659_ADDA_CLK_1, RT5659_I2S_BCLK_MS2_MASK, RT5659_I2S_BCLK_MS2_64); break; case RT5659_AIF3: - snd_soc_update_bits(codec, RT5659_ADDA_CLK_1, + snd_soc_component_update_bits(component, RT5659_ADDA_CLK_1, RT5659_I2S_BCLK_MS3_MASK, RT5659_I2S_BCLK_MS3_64); break; @@ -3565,11 +3641,11 @@ static int rt5659_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) return 0; } -static int rt5659_set_bias_level(struct snd_soc_codec *codec, +static int rt5659_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); int ret; switch (level) { @@ -3591,7 +3667,7 @@ static int rt5659_set_bias_level(struct snd_soc_codec *codec, if (dapm->bias_level == SND_SOC_BIAS_OFF) { ret = clk_prepare_enable(rt5659->mclk); if (ret) { - dev_err(codec->dev, + dev_err(component->dev, "failed to enable MCLK: %d\n", ret); return ret; } @@ -3617,37 +3693,35 @@ static int rt5659_set_bias_level(struct snd_soc_codec *codec, return 0; } -static int rt5659_probe(struct snd_soc_codec *codec) +static int rt5659_probe(struct snd_soc_component *component) { - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); - rt5659->codec = codec; + rt5659->component = component; return 0; } -static int rt5659_remove(struct snd_soc_codec *codec) +static void rt5659_remove(struct snd_soc_component *component) { - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); regmap_write(rt5659->regmap, RT5659_RESET, 0); - - return 0; } #ifdef CONFIG_PM -static int rt5659_suspend(struct snd_soc_codec *codec) +static int rt5659_suspend(struct snd_soc_component *component) { - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); regcache_cache_only(rt5659->regmap, true); regcache_mark_dirty(rt5659->regmap); return 0; } -static int rt5659_resume(struct snd_soc_codec *codec) +static int rt5659_resume(struct snd_soc_component *component) { - struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); regcache_cache_only(rt5659->regmap, false); regcache_sync(rt5659->regmap); @@ -3730,23 +3804,23 @@ static struct snd_soc_dai_driver rt5659_dai[] = { }, }; -static const struct snd_soc_codec_driver soc_codec_dev_rt5659 = { - .probe = rt5659_probe, - .remove = rt5659_remove, - .suspend = rt5659_suspend, - .resume = rt5659_resume, - .set_bias_level = rt5659_set_bias_level, - .idle_bias_off = true, - .component_driver = { - .controls = rt5659_snd_controls, - .num_controls = ARRAY_SIZE(rt5659_snd_controls), - .dapm_widgets = rt5659_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(rt5659_dapm_widgets), - .dapm_routes = rt5659_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(rt5659_dapm_routes), - }, - .set_sysclk = rt5659_set_codec_sysclk, - .set_pll = rt5659_set_codec_pll, +static const struct snd_soc_component_driver soc_component_dev_rt5659 = { + .probe = rt5659_probe, + .remove = rt5659_remove, + .suspend = rt5659_suspend, + .resume = rt5659_resume, + .set_bias_level = rt5659_set_bias_level, + .controls = rt5659_snd_controls, + .num_controls = ARRAY_SIZE(rt5659_snd_controls), + .dapm_widgets = rt5659_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rt5659_dapm_widgets), + .dapm_routes = rt5659_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(rt5659_dapm_routes), + .set_sysclk = rt5659_set_component_sysclk, + .set_pll = rt5659_set_component_pll, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; @@ -3849,7 +3923,7 @@ static void rt5659_calibrate(struct rt5659_priv *rt5659) break; if (count > 30) { - dev_err(rt5659->codec->dev, + dev_err(rt5659->component->dev, "HP Calibration 1 Failure\n"); return; } @@ -3874,7 +3948,7 @@ static void rt5659_calibrate(struct rt5659_priv *rt5659) break; if (count > 85) { - dev_err(rt5659->codec->dev, + dev_err(rt5659->component->dev, "HP Calibration 2 Failure\n"); return; } @@ -3922,7 +3996,7 @@ static void rt5659_calibrate(struct rt5659_priv *rt5659) break; if (count > 10) { - dev_err(rt5659->codec->dev, + dev_err(rt5659->component->dev, "SPK Calibration Failure\n"); return; } @@ -3955,7 +4029,7 @@ static void rt5659_calibrate(struct rt5659_priv *rt5659) break; if (count > 35) { - dev_err(rt5659->codec->dev, + dev_err(rt5659->component->dev, "Mono Calibration Failure\n"); return; } @@ -3990,6 +4064,54 @@ static void rt5659_calibrate(struct rt5659_priv *rt5659) regmap_write(rt5659->regmap, RT5659_HP_CHARGE_PUMP_1, 0x0c16); } +static void rt5659_intel_hd_header_probe_setup(struct rt5659_priv *rt5659) +{ + int value; + + regmap_read(rt5659->regmap, RT5659_GPIO_STA, &value); + if (!(value & 0x8)) { + rt5659->hda_hp_plugged = true; + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1, + 0x10, 0x0); + } else { + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1, + 0x10, 0x10); + } + + regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1, + RT5659_PWR_VREF2 | RT5659_PWR_MB, + RT5659_PWR_VREF2 | RT5659_PWR_MB); + msleep(20); + regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1, + RT5659_PWR_FV2, RT5659_PWR_FV2); + + regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_3, RT5659_PWR_LDO2, + RT5659_PWR_LDO2); + regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_2, RT5659_PWR_MB1, + RT5659_PWR_MB1); + regmap_update_bits(rt5659->regmap, RT5659_PWR_VOL, RT5659_PWR_MIC_DET, + RT5659_PWR_MIC_DET); + msleep(20); + + regmap_update_bits(rt5659->regmap, RT5659_4BTN_IL_CMD_2, + RT5659_4BTN_IL_MASK, RT5659_4BTN_IL_EN); + regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value); + regmap_write(rt5659->regmap, RT5659_4BTN_IL_CMD_1, value); + regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value); + + if (value & 0x2000) { + rt5659->hda_mic_plugged = true; + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, + 0x2, 0x2); + } else { + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, + 0x2, 0x0); + } + + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, + RT5659_IL_IRQ_MASK, RT5659_IL_IRQ_EN); +} + static int rt5659_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -4174,16 +4296,23 @@ static int rt5659_i2c_probe(struct i2c_client *i2c, RT5659_PWR_MB, RT5659_PWR_MB); regmap_write(rt5659->regmap, RT5659_PWR_ANLG_2, 0x0001); regmap_write(rt5659->regmap, RT5659_IRQ_CTRL_2, 0x0040); + INIT_DELAYED_WORK(&rt5659->jack_detect_work, + rt5659_jack_detect_work); break; - case RT5659_JD_NULL: + case RT5659_JD_HDA_HEADER: + regmap_write(rt5659->regmap, RT5659_GPIO_CTRL_3, 0x8000); + regmap_write(rt5659->regmap, RT5659_RC_CLK_CTRL, 0x0900); + regmap_write(rt5659->regmap, RT5659_EJD_CTRL_1, 0x70c0); + regmap_write(rt5659->regmap, RT5659_JD_CTRL_1, 0x2000); + regmap_write(rt5659->regmap, RT5659_IRQ_CTRL_1, 0x0040); + INIT_DELAYED_WORK(&rt5659->jack_detect_work, + rt5659_jack_detect_intel_hd_header); + rt5659_intel_hd_header_probe_setup(rt5659); break; default: - dev_warn(&i2c->dev, "Currently, support JD3 only\n"); break; } - INIT_DELAYED_WORK(&rt5659->jack_detect_work, rt5659_jack_detect_work); - if (i2c->irq) { ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, rt5659_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING @@ -4196,17 +4325,11 @@ static int rt5659_i2c_probe(struct i2c_client *i2c, RT5659_GP1_PIN_MASK, RT5659_GP1_PIN_IRQ); } - return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5659, + return devm_snd_soc_register_component(&i2c->dev, + &soc_component_dev_rt5659, rt5659_dai, ARRAY_SIZE(rt5659_dai)); } -static int rt5659_i2c_remove(struct i2c_client *i2c) -{ - snd_soc_unregister_codec(&i2c->dev); - - return 0; -} - static void rt5659_i2c_shutdown(struct i2c_client *client) { struct rt5659_priv *rt5659 = i2c_get_clientdata(client); @@ -4239,7 +4362,6 @@ static struct i2c_driver rt5659_i2c_driver = { .acpi_match_table = ACPI_PTR(rt5659_acpi_match), }, .probe = rt5659_i2c_probe, - .remove = rt5659_i2c_remove, .shutdown = rt5659_i2c_shutdown, .id_table = rt5659_i2c_id, }; |