Lines Matching +full:mic +full:- +full:amp +full:- +full:in +full:- +full:sel

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * da7218.c - DA7218 ALSA SoC Codec Driver
22 #include <sound/soc-dapm.h>
37 static const DECLARE_TLV_DB_SCALE(da7218_mic_gain_tlv, -600, 600, 0);
38 static const DECLARE_TLV_DB_SCALE(da7218_mixin_gain_tlv, -450, 150, 0);
39 static const DECLARE_TLV_DB_SCALE(da7218_in_dig_gain_tlv, -8325, 75, 0);
40 static const DECLARE_TLV_DB_SCALE(da7218_ags_trigger_tlv, -9000, 600, 0);
42 static const DECLARE_TLV_DB_SCALE(da7218_alc_threshold_tlv, -9450, 150, 0);
47 static const DECLARE_TLV_DB_SCALE(da7218_dmix_gain_tlv, -4200, 150, 0);
50 static const DECLARE_TLV_DB_SCALE(da7218_dgs_trigger_tlv, -9450, 150, 0);
51 static const DECLARE_TLV_DB_SCALE(da7218_dgs_anticlip_tlv, -4200, 600, 0);
52 static const DECLARE_TLV_DB_SCALE(da7218_dgs_signal_tlv, -9000, 600, 0);
53 static const DECLARE_TLV_DB_SCALE(da7218_out_eq_band_tlv, -1050, 150, 0);
54 static const DECLARE_TLV_DB_SCALE(da7218_out_dig_gain_tlv, -8325, 75, 0);
55 static const DECLARE_TLV_DB_SCALE(da7218_dac_ng_threshold_tlv, -10200, 600, 0);
56 static const DECLARE_TLV_DB_SCALE(da7218_mixout_gain_tlv, -100, 50, 0);
57 static const DECLARE_TLV_DB_SCALE(da7218_hp_gain_tlv, -5700, 150, 0);
201 "Sum", "SWG1", "SWG2", "SWG1_1-Cos"
300 /* Save current state of MIC control registers */ in da7218_alc_calib()
318 /* Enable then Mute MIC PGAs */ in da7218_alc_calib()
385 dev_warn(component->dev, in da7218_alc_calib()
386 "ALC auto calibration failed - %s\n", in da7218_alc_calib()
420 /* Restore MIC control registers to original states */ in da7218_alc_calib()
435 * If ALC in operation and value of control has been updated, in da7218_mixin_gain_put()
438 if ((ret == 1) && (da7218->alc_en)) in da7218_mixin_gain_put()
448 (struct soc_mixer_control *) kcontrol->private_value; in da7218_alc_sw_put()
451 unsigned int lvalue = ucontrol->value.integer.value[0]; in da7218_alc_sw_put()
452 unsigned int rvalue = ucontrol->value.integer.value[1]; in da7218_alc_sw_put()
453 unsigned int lshift = mc->shift; in da7218_alc_sw_put()
454 unsigned int rshift = mc->rshift; in da7218_alc_sw_put()
455 unsigned int mask = (mc->max << lshift) | (mc->max << rshift); in da7218_alc_sw_put()
458 if ((lvalue || rvalue) && (!da7218->alc_en)) in da7218_alc_sw_put()
462 da7218->alc_en &= ~mask; in da7218_alc_sw_put()
463 da7218->alc_en |= (lvalue << lshift) | (rvalue << rshift); in da7218_alc_sw_put()
475 (struct soc_mixer_control *) kcontrol->private_value; in da7218_tonegen_freq_get()
476 unsigned int reg = mixer_ctrl->reg; in da7218_tonegen_freq_get()
481 * Frequency value spans two 8-bit registers, lower then upper byte. in da7218_tonegen_freq_get()
484 ret = regmap_raw_read(da7218->regmap, reg, &val, 2); in da7218_tonegen_freq_get()
488 ucontrol->value.integer.value[0] = le16_to_cpu(val); in da7218_tonegen_freq_get()
499 (struct soc_mixer_control *) kcontrol->private_value; in da7218_tonegen_freq_put()
500 unsigned int reg = mixer_ctrl->reg; in da7218_tonegen_freq_put()
504 * Frequency value spans two 8-bit registers, lower then upper byte. in da7218_tonegen_freq_put()
508 val = cpu_to_le16(ucontrol->value.integer.value[0]); in da7218_tonegen_freq_put()
510 return regmap_raw_write(da7218->regmap, reg, &val, 2); in da7218_tonegen_freq_put()
519 (struct soc_mixer_control *) kcontrol->private_value; in da7218_mic_lvl_det_sw_put()
520 unsigned int lvalue = ucontrol->value.integer.value[0]; in da7218_mic_lvl_det_sw_put()
521 unsigned int rvalue = ucontrol->value.integer.value[1]; in da7218_mic_lvl_det_sw_put()
522 unsigned int lshift = mixer_ctrl->shift; in da7218_mic_lvl_det_sw_put()
523 unsigned int rshift = mixer_ctrl->rshift; in da7218_mic_lvl_det_sw_put()
524 unsigned int mask = (mixer_ctrl->max << lshift) | in da7218_mic_lvl_det_sw_put()
525 (mixer_ctrl->max << rshift); in da7218_mic_lvl_det_sw_put()
526 da7218->mic_lvl_det_en &= ~mask; in da7218_mic_lvl_det_sw_put()
527 da7218->mic_lvl_det_en |= (lvalue << lshift) | (rvalue << rshift); in da7218_mic_lvl_det_sw_put()
536 return snd_soc_component_write(component, mixer_ctrl->reg, in da7218_mic_lvl_det_sw_put()
537 (da7218->in_filt_en & da7218->mic_lvl_det_en)); in da7218_mic_lvl_det_sw_put()
546 (struct soc_mixer_control *) kcontrol->private_value; in da7218_mic_lvl_det_sw_get()
547 unsigned int lshift = mixer_ctrl->shift; in da7218_mic_lvl_det_sw_get()
548 unsigned int rshift = mixer_ctrl->rshift; in da7218_mic_lvl_det_sw_get()
549 unsigned int lmask = (mixer_ctrl->max << lshift); in da7218_mic_lvl_det_sw_get()
550 unsigned int rmask = (mixer_ctrl->max << rshift); in da7218_mic_lvl_det_sw_get()
552 ucontrol->value.integer.value[0] = in da7218_mic_lvl_det_sw_get()
553 (da7218->mic_lvl_det_en & lmask) >> lshift; in da7218_mic_lvl_det_sw_get()
554 ucontrol->value.integer.value[1] = in da7218_mic_lvl_det_sw_get()
555 (da7218->mic_lvl_det_en & rmask) >> rshift; in da7218_mic_lvl_det_sw_get()
566 (struct soc_bytes_ext *) kcontrol->private_value; in da7218_biquad_coeff_get()
569 switch (bytes_ext->max) { in da7218_biquad_coeff_get()
571 memcpy(ucontrol->value.bytes.data, da7218->biq_5stage_coeff, in da7218_biquad_coeff_get()
572 bytes_ext->max); in da7218_biquad_coeff_get()
575 memcpy(ucontrol->value.bytes.data, da7218->stbiq_3stage_coeff, in da7218_biquad_coeff_get()
576 bytes_ext->max); in da7218_biquad_coeff_get()
579 return -EINVAL; in da7218_biquad_coeff_get()
591 (struct soc_bytes_ext *) kcontrol->private_value; in da7218_biquad_coeff_put()
600 switch (bytes_ext->max) { in da7218_biquad_coeff_put()
603 memcpy(da7218->biq_5stage_coeff, ucontrol->value.bytes.data, in da7218_biquad_coeff_put()
604 bytes_ext->max); in da7218_biquad_coeff_put()
608 memcpy(da7218->stbiq_3stage_coeff, ucontrol->value.bytes.data, in da7218_biquad_coeff_put()
609 bytes_ext->max); in da7218_biquad_coeff_put()
612 return -EINVAL; in da7218_biquad_coeff_put()
620 for (i = 0; i < bytes_ext->max; ++i) { in da7218_biquad_coeff_put()
621 cfg[DA7218_BIQ_CFG_DATA] = ucontrol->value.bytes.data[i]; in da7218_biquad_coeff_put()
623 regmap_raw_write(da7218->regmap, reg, cfg, DA7218_BIQ_CFG_SIZE); in da7218_biquad_coeff_put()
694 SOC_SINGLE_TLV("In Filter1L Volume", DA7218_IN_1L_GAIN,
698 SOC_SINGLE("In Filter1L Switch", DA7218_IN_1L_FILTER_CTRL,
701 SOC_SINGLE("In Filter1L Gain Ramp Switch", DA7218_IN_1L_FILTER_CTRL,
704 SOC_SINGLE_TLV("In Filter1R Volume", DA7218_IN_1R_GAIN,
708 SOC_SINGLE("In Filter1R Switch", DA7218_IN_1R_FILTER_CTRL,
711 SOC_SINGLE("In Filter1R Gain Ramp Switch",
714 SOC_SINGLE_TLV("In Filter2L Volume", DA7218_IN_2L_GAIN,
718 SOC_SINGLE("In Filter2L Switch", DA7218_IN_2L_FILTER_CTRL,
721 SOC_SINGLE("In Filter2L Gain Ramp Switch", DA7218_IN_2L_FILTER_CTRL,
724 SOC_SINGLE_TLV("In Filter2R Volume", DA7218_IN_2R_GAIN,
728 SOC_SINGLE("In Filter2R Switch", DA7218_IN_2R_FILTER_CTRL,
731 SOC_SINGLE("In Filter2R Gain Ramp Switch",
796 /* Input High-Pass Filters */
797 SOC_ENUM("In Filter1 HPF Mode", da7218_in1_hpf_mode),
798 SOC_ENUM("In Filter1 HPF Corner Audio", da7218_in1_audio_hpf_corner),
799 SOC_ENUM("In Filter1 HPF Corner Voice", da7218_in1_voice_hpf_corner),
800 SOC_ENUM("In Filter2 HPF Mode", da7218_in2_hpf_mode),
801 SOC_ENUM("In Filter2 HPF Corner Audio", da7218_in2_audio_hpf_corner),
802 SOC_ENUM("In Filter2 HPF Corner Voice", da7218_in2_voice_hpf_corner),
804 /* Mic Level Detect */
805 SOC_DOUBLE_EXT("Mic Level Detect Channel1 Switch", DA7218_LVL_DET_CTRL,
810 SOC_DOUBLE_EXT("Mic Level Detect Channel2 Switch", DA7218_LVL_DET_CTRL,
815 SOC_SINGLE("Mic Level Detect Level", DA7218_LVL_DET_LEVEL,
820 SOC_SINGLE_TLV("DMix In Filter1L Out1 DAIL Volume",
825 SOC_SINGLE_TLV("DMix In Filter1L Out1 DAIR Volume",
830 SOC_SINGLE_TLV("DMix In Filter1L Out2 DAIL Volume",
835 SOC_SINGLE_TLV("DMix In Filter1L Out2 DAIR Volume",
841 SOC_SINGLE_TLV("DMix In Filter1R Out1 DAIL Volume",
846 SOC_SINGLE_TLV("DMix In Filter1R Out1 DAIR Volume",
851 SOC_SINGLE_TLV("DMix In Filter1R Out2 DAIL Volume",
856 SOC_SINGLE_TLV("DMix In Filter1R Out2 DAIR Volume",
862 SOC_SINGLE_TLV("DMix In Filter2L Out1 DAIL Volume",
867 SOC_SINGLE_TLV("DMix In Filter2L Out1 DAIR Volume",
872 SOC_SINGLE_TLV("DMix In Filter2L Out2 DAIL Volume",
877 SOC_SINGLE_TLV("DMix In Filter2L Out2 DAIR Volume",
883 SOC_SINGLE_TLV("DMix In Filter2R Out1 DAIL Volume",
888 SOC_SINGLE_TLV("DMix In Filter2R Out1 DAIR Volume",
893 SOC_SINGLE_TLV("DMix In Filter2R Out2 DAIL Volume",
898 SOC_SINGLE_TLV("DMix In Filter2R Out2 DAIR Volume",
925 SOC_SINGLE_TLV("DMix In DAIL Out1 DAIL Volume",
930 SOC_SINGLE_TLV("DMix In DAIL Out1 DAIR Volume",
935 SOC_SINGLE_TLV("DMix In DAIL Out2 DAIL Volume",
940 SOC_SINGLE_TLV("DMix In DAIL Out2 DAIR Volume",
946 SOC_SINGLE_TLV("DMix In DAIR Out1 DAIL Volume",
951 SOC_SINGLE_TLV("DMix In DAIR Out1 DAIR Volume",
956 SOC_SINGLE_TLV("DMix In DAIR Out2 DAIL Volume",
961 SOC_SINGLE_TLV("DMix In DAIR Out2 DAIR Volume",
968 SOC_SINGLE_TLV("DMix In Filter1L Out FilterL Volume",
973 SOC_SINGLE_TLV("DMix In Filter1L Out FilterR Volume",
979 SOC_SINGLE_TLV("DMix In Filter1R Out FilterL Volume",
984 SOC_SINGLE_TLV("DMix In Filter1R Out FilterR Volume",
990 SOC_SINGLE_TLV("DMix In Filter2L Out FilterL Volume",
995 SOC_SINGLE_TLV("DMix In Filter2L Out FilterR Volume",
1001 SOC_SINGLE_TLV("DMix In Filter2R Out FilterL Volume",
1006 SOC_SINGLE_TLV("DMix In Filter2R Out FilterR Volume",
1023 SOC_SINGLE_TLV("DMix In DAIL Out FilterL Volume",
1028 SOC_SINGLE_TLV("DMix In DAIL Out FilterR Volume",
1034 SOC_SINGLE_TLV("DMix In DAIR Out FilterL Volume",
1039 SOC_SINGLE_TLV("DMix In DAIR Out FilterR Volume",
1113 /* Output High-Pass Filter */
1118 /* 5-Band Equaliser */
1233 "In Filter1L", "In Filter1R", "In Filter2L", "In Filter2R"
1273 SOC_DAPM_SINGLE("In Filter1L Switch", reg, \
1276 SOC_DAPM_SINGLE("In Filter1R Switch", reg, \
1279 SOC_DAPM_SINGLE("In Filter2L Switch", reg, \
1282 SOC_DAPM_SINGLE("In Filter2R Switch", reg, \
1342 * We keep track of which input filters are enabled. This is used in the logic
1343 * for controlling the mic level detect feature.
1348 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7218_in_filter_event()
1352 switch (w->reg) { in da7218_in_filter_event()
1366 return -EINVAL; in da7218_in_filter_event()
1371 da7218->in_filt_en |= mask; in da7218_in_filter_event()
1373 * If we're enabling path for mic level detect, wait for path in da7218_in_filter_event()
1377 if (mask & da7218->mic_lvl_det_en) in da7218_in_filter_event()
1381 da7218->in_filt_en &= ~mask; in da7218_in_filter_event()
1384 return -EINVAL; in da7218_in_filter_event()
1389 (da7218->in_filt_en & da7218->mic_lvl_det_en)); in da7218_in_filter_event()
1397 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7218_dai_event()
1405 if (da7218->master) in da7218_dai_event()
1433 dev_warn(component->dev, in da7218_dai_event()
1459 dev_warn(component->dev, "SRM failed to lock\n"); in da7218_dai_event()
1463 /* PC free-running */ in da7218_dai_event()
1466 if (da7218->master) in da7218_dai_event()
1473 return -EINVAL; in da7218_dai_event()
1480 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7218_cp_event()
1487 if (da7218->hp_single_supply) in da7218_cp_event()
1500 return -EINVAL; in da7218_cp_event()
1507 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in da7218_hp_pga_event()
1512 snd_soc_component_update_bits(component, w->reg, DA7218_HP_AMP_OE_MASK, in da7218_hp_pga_event()
1517 snd_soc_component_update_bits(component, w->reg, DA7218_HP_AMP_OE_MASK, 0); in da7218_hp_pga_event()
1520 return -EINVAL; in da7218_hp_pga_event()
1531 SND_SOC_DAPM_SUPPLY("Mic Bias1", DA7218_MICBIAS_EN,
1534 SND_SOC_DAPM_SUPPLY("Mic Bias2", DA7218_MICBIAS_EN,
1580 /* Mic/DMic Muxes */
1585 SND_SOC_DAPM_ADC_E("In Filter1L", NULL, DA7218_IN_1L_FILTER_CTRL,
1589 SND_SOC_DAPM_ADC_E("In Filter1R", NULL, DA7218_IN_1R_FILTER_CTRL,
1593 SND_SOC_DAPM_ADC_E("In Filter2L", NULL, DA7218_IN_2L_FILTER_CTRL,
1597 SND_SOC_DAPM_ADC_E("In Filter2R", NULL, DA7218_IN_2R_FILTER_CTRL,
1699 {name, "In Filter1L Switch", "In Filter1L"}, \
1700 {name, "In Filter1R Switch", "In Filter1R"}, \
1701 {name, "In Filter2L Switch", "In Filter2L"}, \
1702 {name, "In Filter2R Switch", "In Filter2R"}, \
1719 {"MIC1", NULL, "Mic Bias1"},
1720 {"MIC2", NULL, "Mic Bias2"},
1721 {"DMIC1L", NULL, "Mic Bias1"},
1723 {"DMIC1R", NULL, "Mic Bias1"},
1725 {"DMIC2L", NULL, "Mic Bias2"},
1727 {"DMIC2R", NULL, "Mic Bias2"},
1746 {"In Filter1L", NULL, "Mic1 Mux"},
1747 {"In Filter1R", NULL, "Mic1 Mux"},
1748 {"In Filter2L", NULL, "Mic2 Mux"},
1749 {"In Filter2R", NULL, "Mic2 Mux"},
1753 {"Sidetone Mux", "In Filter1L", "In Filter1L"},
1754 {"Sidetone Mux", "In Filter1R", "In Filter1R"},
1755 {"Sidetone Mux", "In Filter2L", "In Filter2L"},
1756 {"Sidetone Mux", "In Filter2R", "In Filter2R"},
1812 struct snd_soc_component *component = codec_dai->component; in da7218_set_dai_sysclk()
1816 if (da7218->mclk_rate == freq) in da7218_set_dai_sysclk()
1820 dev_err(codec_dai->dev, "Unsupported MCLK value %d\n", in da7218_set_dai_sysclk()
1822 return -EINVAL; in da7218_set_dai_sysclk()
1836 dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id); in da7218_set_dai_sysclk()
1837 return -EINVAL; in da7218_set_dai_sysclk()
1840 if (da7218->mclk) { in da7218_set_dai_sysclk()
1841 freq = clk_round_rate(da7218->mclk, freq); in da7218_set_dai_sysclk()
1842 ret = clk_set_rate(da7218->mclk, freq); in da7218_set_dai_sysclk()
1844 dev_err(codec_dai->dev, "Failed to set clock rate %d\n", in da7218_set_dai_sysclk()
1850 da7218->mclk_rate = freq; in da7218_set_dai_sysclk()
1858 struct snd_soc_component *component = codec_dai->component; in da7218_set_dai_pll()
1866 /* Verify 2MHz - 54MHz MCLK provided, and set input divider */ in da7218_set_dai_pll()
1867 if (da7218->mclk_rate < 2000000) { in da7218_set_dai_pll()
1868 dev_err(component->dev, "PLL input clock %d below valid range\n", in da7218_set_dai_pll()
1869 da7218->mclk_rate); in da7218_set_dai_pll()
1870 return -EINVAL; in da7218_set_dai_pll()
1871 } else if (da7218->mclk_rate <= 4500000) { in da7218_set_dai_pll()
1874 } else if (da7218->mclk_rate <= 9000000) { in da7218_set_dai_pll()
1877 } else if (da7218->mclk_rate <= 18000000) { in da7218_set_dai_pll()
1880 } else if (da7218->mclk_rate <= 36000000) { in da7218_set_dai_pll()
1883 } else if (da7218->mclk_rate <= 54000000) { in da7218_set_dai_pll()
1887 dev_err(component->dev, "PLL input clock %d above valid range\n", in da7218_set_dai_pll()
1888 da7218->mclk_rate); in da7218_set_dai_pll()
1889 return -EINVAL; in da7218_set_dai_pll()
1891 freq_ref = (da7218->mclk_rate / indiv); in da7218_set_dai_pll()
1909 dev_err(component->dev, "Invalid PLL config\n"); in da7218_set_dai_pll()
1910 return -EINVAL; in da7218_set_dai_pll()
1933 struct snd_soc_component *component = codec_dai->component; in da7218_set_dai_fmt()
1939 da7218->master = true; in da7218_set_dai_fmt()
1942 da7218->master = false; in da7218_set_dai_fmt()
1945 return -EINVAL; in da7218_set_dai_fmt()
1966 return -EINVAL; in da7218_set_dai_fmt()
1984 return -EINVAL; in da7218_set_dai_fmt()
1988 return -EINVAL; in da7218_set_dai_fmt()
2005 return -EINVAL; in da7218_set_dai_fmt()
2022 struct snd_soc_component *component = dai->component; in da7218_set_dai_tdm_slot()
2026 /* No channels enabled so disable TDM, revert to 64-bit frames */ in da7218_set_dai_tdm_slot()
2039 dev_err(component->dev, "Invalid number of slots, max = %d\n", in da7218_set_dai_tdm_slot()
2041 return -EINVAL; in da7218_set_dai_tdm_slot()
2046 dev_err(component->dev, "Invalid slot offset, max = %d\n", in da7218_set_dai_tdm_slot()
2048 return -EINVAL; in da7218_set_dai_tdm_slot()
2067 dev_err(component->dev, "Invalid frame size\n"); in da7218_set_dai_tdm_slot()
2068 return -EINVAL; in da7218_set_dai_tdm_slot()
2091 struct snd_soc_component *component = dai->component; in da7218_hw_params()
2109 return -EINVAL; in da7218_hw_params()
2114 dev_err(component->dev, in da7218_hw_params()
2117 return -EINVAL; in da7218_hw_params()
2156 return -EINVAL; in da7218_hw_params()
2181 .name = "da7218-hifi",
2211 if (da7218->dev_id == DA7217_DEV_ID) in da7218_hpldet()
2212 return -EINVAL; in da7218_hpldet()
2214 da7218->jack = jack; in da7218_hpldet()
2230 kobject_uevent_env(&component->dev->kobj, KOBJ_CHANGE, envp); in da7218_micldet_irq()
2246 snd_soc_jack_report(da7218->jack, report, SND_JACK_HEADPHONE); in da7218_hpldet_irq()
2263 /* Mic level detect */ in da7218_irq_thread()
2311 dev_warn(component->dev, "Invalid micbias level"); in da7218_of_micbias_lvl()
2326 dev_warn(component->dev, "Invalid mic input type selection"); in da7218_of_mic_amp_in_sel()
2339 dev_warn(component->dev, "Invalid DMIC data type selection"); in da7218_of_dmic_data_sel()
2352 dev_warn(component->dev, "Invalid DMIC sample phase"); in da7218_of_dmic_samplephase()
2366 dev_warn(component->dev, "Invalid DMIC clock rate"); in da7218_of_dmic_clkrate()
2392 dev_warn(component->dev, "Invalid jack detect rate"); in da7218_of_jack_rate()
2410 dev_warn(component->dev, "Invalid jack debounce"); in da7218_of_jack_debounce()
2428 dev_warn(component->dev, "Invalid jack threshold level"); in da7218_of_jack_thr()
2436 struct device_node *np = component->dev->of_node; in da7218_of_to_pdata()
2443 pdata = devm_kzalloc(component->dev, sizeof(*pdata), GFP_KERNEL); in da7218_of_to_pdata()
2447 if (of_property_read_u32(np, "dlg,micbias1-lvl-millivolt", &of_val32) >= 0) in da7218_of_to_pdata()
2448 pdata->micbias1_lvl = da7218_of_micbias_lvl(component, of_val32); in da7218_of_to_pdata()
2450 pdata->micbias1_lvl = DA7218_MICBIAS_1_6V; in da7218_of_to_pdata()
2452 if (of_property_read_u32(np, "dlg,micbias2-lvl-millivolt", &of_val32) >= 0) in da7218_of_to_pdata()
2453 pdata->micbias2_lvl = da7218_of_micbias_lvl(component, of_val32); in da7218_of_to_pdata()
2455 pdata->micbias2_lvl = DA7218_MICBIAS_1_6V; in da7218_of_to_pdata()
2457 if (!of_property_read_string(np, "dlg,mic1-amp-in-sel", &of_str)) in da7218_of_to_pdata()
2458 pdata->mic1_amp_in_sel = in da7218_of_to_pdata()
2461 pdata->mic1_amp_in_sel = DA7218_MIC_AMP_IN_SEL_DIFF; in da7218_of_to_pdata()
2463 if (!of_property_read_string(np, "dlg,mic2-amp-in-sel", &of_str)) in da7218_of_to_pdata()
2464 pdata->mic2_amp_in_sel = in da7218_of_to_pdata()
2467 pdata->mic2_amp_in_sel = DA7218_MIC_AMP_IN_SEL_DIFF; in da7218_of_to_pdata()
2469 if (!of_property_read_string(np, "dlg,dmic1-data-sel", &of_str)) in da7218_of_to_pdata()
2470 pdata->dmic1_data_sel = da7218_of_dmic_data_sel(component, of_str); in da7218_of_to_pdata()
2472 pdata->dmic1_data_sel = DA7218_DMIC_DATA_LRISE_RFALL; in da7218_of_to_pdata()
2474 if (!of_property_read_string(np, "dlg,dmic1-samplephase", &of_str)) in da7218_of_to_pdata()
2475 pdata->dmic1_samplephase = in da7218_of_to_pdata()
2478 pdata->dmic1_samplephase = DA7218_DMIC_SAMPLE_ON_CLKEDGE; in da7218_of_to_pdata()
2480 if (of_property_read_u32(np, "dlg,dmic1-clkrate-hz", &of_val32) >= 0) in da7218_of_to_pdata()
2481 pdata->dmic1_clk_rate = da7218_of_dmic_clkrate(component, of_val32); in da7218_of_to_pdata()
2483 pdata->dmic1_clk_rate = DA7218_DMIC_CLK_3_0MHZ; in da7218_of_to_pdata()
2485 if (!of_property_read_string(np, "dlg,dmic2-data-sel", &of_str)) in da7218_of_to_pdata()
2486 pdata->dmic2_data_sel = da7218_of_dmic_data_sel(component, of_str); in da7218_of_to_pdata()
2488 pdata->dmic2_data_sel = DA7218_DMIC_DATA_LRISE_RFALL; in da7218_of_to_pdata()
2490 if (!of_property_read_string(np, "dlg,dmic2-samplephase", &of_str)) in da7218_of_to_pdata()
2491 pdata->dmic2_samplephase = in da7218_of_to_pdata()
2494 pdata->dmic2_samplephase = DA7218_DMIC_SAMPLE_ON_CLKEDGE; in da7218_of_to_pdata()
2496 if (of_property_read_u32(np, "dlg,dmic2-clkrate-hz", &of_val32) >= 0) in da7218_of_to_pdata()
2497 pdata->dmic2_clk_rate = da7218_of_dmic_clkrate(component, of_val32); in da7218_of_to_pdata()
2499 pdata->dmic2_clk_rate = DA7218_DMIC_CLK_3_0MHZ; in da7218_of_to_pdata()
2501 if (da7218->dev_id == DA7217_DEV_ID) { in da7218_of_to_pdata()
2502 if (of_property_read_bool(np, "dlg,hp-diff-single-supply")) in da7218_of_to_pdata()
2503 pdata->hp_diff_single_supply = true; in da7218_of_to_pdata()
2506 if (da7218->dev_id == DA7218_DEV_ID) { in da7218_of_to_pdata()
2511 hpldet_pdata = devm_kzalloc(component->dev, sizeof(*hpldet_pdata), in da7218_of_to_pdata()
2517 pdata->hpldet_pdata = hpldet_pdata; in da7218_of_to_pdata()
2519 if (of_property_read_u32(hpldet_np, "dlg,jack-rate-us", in da7218_of_to_pdata()
2521 hpldet_pdata->jack_rate = in da7218_of_to_pdata()
2524 hpldet_pdata->jack_rate = DA7218_HPLDET_JACK_RATE_40US; in da7218_of_to_pdata()
2526 if (of_property_read_u32(hpldet_np, "dlg,jack-debounce", in da7218_of_to_pdata()
2528 hpldet_pdata->jack_debounce = in da7218_of_to_pdata()
2531 hpldet_pdata->jack_debounce = in da7218_of_to_pdata()
2534 if (of_property_read_u32(hpldet_np, "dlg,jack-threshold-pct", in da7218_of_to_pdata()
2536 hpldet_pdata->jack_thr = in da7218_of_to_pdata()
2539 hpldet_pdata->jack_thr = DA7218_HPLDET_JACK_THR_84PCT; in da7218_of_to_pdata()
2541 if (of_property_read_bool(hpldet_np, "dlg,comp-inv")) in da7218_of_to_pdata()
2542 hpldet_pdata->comp_inv = true; in da7218_of_to_pdata()
2545 hpldet_pdata->hyst = true; in da7218_of_to_pdata()
2548 hpldet_pdata->discharge = true; in da7218_of_to_pdata()
2573 if (da7218->mclk) { in da7218_set_bias_level()
2574 ret = clk_prepare_enable(da7218->mclk); in da7218_set_bias_level()
2576 dev_err(component->dev, "Failed to enable mclk\n"); in da7218_set_bias_level()
2596 if (da7218->mclk) in da7218_set_bias_level()
2597 clk_disable_unprepare(da7218->mclk); in da7218_set_bias_level()
2602 if (!da7218->jack) { in da7218_set_bias_level()
2632 da7218->supplies[i].supply = da7218_supply_names[i]; in da7218_handle_supplies()
2634 ret = devm_regulator_bulk_get(component->dev, DA7218_NUM_SUPPLIES, in da7218_handle_supplies()
2635 da7218->supplies); in da7218_handle_supplies()
2637 dev_err(component->dev, "Failed to get supplies\n"); in da7218_handle_supplies()
2642 vddio = da7218->supplies[DA7218_SUPPLY_VDDIO].consumer; in da7218_handle_supplies()
2645 dev_warn(component->dev, "Invalid VDDIO voltage\n"); in da7218_handle_supplies()
2650 ret = regulator_bulk_enable(DA7218_NUM_SUPPLIES, da7218->supplies); in da7218_handle_supplies()
2652 dev_err(component->dev, "Failed to enable supplies\n"); in da7218_handle_supplies()
2656 /* Ensure device in active mode */ in da7218_handle_supplies()
2668 struct da7218_pdata *pdata = da7218->pdata; in da7218_handle_pdata()
2673 /* Mic Bias voltages */ in da7218_handle_pdata()
2674 switch (pdata->micbias1_lvl) { in da7218_handle_pdata()
2686 micbias_lvl |= (pdata->micbias1_lvl << in da7218_handle_pdata()
2691 switch (pdata->micbias2_lvl) { in da7218_handle_pdata()
2703 micbias_lvl |= (pdata->micbias2_lvl << in da7218_handle_pdata()
2710 /* Mic */ in da7218_handle_pdata()
2711 switch (pdata->mic1_amp_in_sel) { in da7218_handle_pdata()
2716 pdata->mic1_amp_in_sel); in da7218_handle_pdata()
2720 switch (pdata->mic2_amp_in_sel) { in da7218_handle_pdata()
2725 pdata->mic2_amp_in_sel); in da7218_handle_pdata()
2730 switch (pdata->dmic1_data_sel) { in da7218_handle_pdata()
2733 dmic_cfg |= (pdata->dmic1_data_sel << in da7218_handle_pdata()
2738 switch (pdata->dmic1_samplephase) { in da7218_handle_pdata()
2741 dmic_cfg |= (pdata->dmic1_samplephase << in da7218_handle_pdata()
2746 switch (pdata->dmic1_clk_rate) { in da7218_handle_pdata()
2749 dmic_cfg |= (pdata->dmic1_clk_rate << in da7218_handle_pdata()
2760 switch (pdata->dmic2_data_sel) { in da7218_handle_pdata()
2763 dmic_cfg |= (pdata->dmic2_data_sel << in da7218_handle_pdata()
2768 switch (pdata->dmic2_samplephase) { in da7218_handle_pdata()
2771 dmic_cfg |= (pdata->dmic2_samplephase << in da7218_handle_pdata()
2776 switch (pdata->dmic2_clk_rate) { in da7218_handle_pdata()
2779 dmic_cfg |= (pdata->dmic2_clk_rate << in da7218_handle_pdata()
2790 if (da7218->dev_id == DA7217_DEV_ID) { in da7218_handle_pdata()
2791 da7218->hp_single_supply = in da7218_handle_pdata()
2792 pdata->hp_diff_single_supply; in da7218_handle_pdata()
2794 if (da7218->hp_single_supply) { in da7218_handle_pdata()
2804 if ((da7218->dev_id == DA7218_DEV_ID) && in da7218_handle_pdata()
2805 (pdata->hpldet_pdata)) { in da7218_handle_pdata()
2807 pdata->hpldet_pdata; in da7218_handle_pdata()
2810 switch (hpldet_pdata->jack_rate) { in da7218_handle_pdata()
2820 (hpldet_pdata->jack_rate << in da7218_handle_pdata()
2825 switch (hpldet_pdata->jack_debounce) { in da7218_handle_pdata()
2831 (hpldet_pdata->jack_debounce << in da7218_handle_pdata()
2836 switch (hpldet_pdata->jack_thr) { in da7218_handle_pdata()
2842 (hpldet_pdata->jack_thr << in da7218_handle_pdata()
2853 if (hpldet_pdata->comp_inv) in da7218_handle_pdata()
2856 if (hpldet_pdata->hyst) in da7218_handle_pdata()
2859 if (hpldet_pdata->discharge) in da7218_handle_pdata()
2878 if (component->dev->of_node) in da7218_probe()
2879 da7218->pdata = da7218_of_to_pdata(component); in da7218_probe()
2881 da7218->pdata = dev_get_platdata(component->dev); in da7218_probe()
2886 da7218->mclk = devm_clk_get_optional(component->dev, "mclk"); in da7218_probe()
2887 if (IS_ERR(da7218->mclk)) { in da7218_probe()
2888 ret = PTR_ERR(da7218->mclk); in da7218_probe()
2892 /* Default PC to free-running */ in da7218_probe()
2897 * Mic to HP passthrough paths by default at startup. in da7218_probe()
2944 if (da7218->dev_id == DA7217_DEV_ID) { in da7218_probe()
2954 if (da7218->irq) { in da7218_probe()
2955 ret = devm_request_threaded_irq(component->dev, da7218->irq, NULL, in da7218_probe()
2960 dev_err(component->dev, "Failed to request IRQ %d: %d\n", in da7218_probe()
2961 da7218->irq, ret); in da7218_probe()
2970 regulator_bulk_disable(DA7218_NUM_SUPPLIES, da7218->supplies); in da7218_probe()
2979 regulator_bulk_disable(DA7218_NUM_SUPPLIES, da7218->supplies); in da7218_remove()
2990 if (!da7218->jack) in da7218_suspend()
3001 if (!da7218->jack) in da7218_resume()
3251 da7218 = devm_kzalloc(&i2c->dev, sizeof(*da7218), GFP_KERNEL); in da7218_i2c_probe()
3253 return -ENOMEM; in da7218_i2c_probe()
3257 da7218->dev_id = (uintptr_t)i2c_get_match_data(i2c); in da7218_i2c_probe()
3259 if ((da7218->dev_id != DA7217_DEV_ID) && in da7218_i2c_probe()
3260 (da7218->dev_id != DA7218_DEV_ID)) { in da7218_i2c_probe()
3261 dev_err(&i2c->dev, "Invalid device Id\n"); in da7218_i2c_probe()
3262 return -EINVAL; in da7218_i2c_probe()
3265 da7218->irq = i2c->irq; in da7218_i2c_probe()
3267 da7218->regmap = devm_regmap_init_i2c(i2c, &da7218_regmap_config); in da7218_i2c_probe()
3268 if (IS_ERR(da7218->regmap)) { in da7218_i2c_probe()
3269 ret = PTR_ERR(da7218->regmap); in da7218_i2c_probe()
3270 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); in da7218_i2c_probe()
3274 ret = devm_snd_soc_register_component(&i2c->dev, in da7218_i2c_probe()
3277 dev_err(&i2c->dev, "Failed to register da7218 component: %d\n", in da7218_i2c_probe()