Set CDC_A_RX_COM_OCP_CTL to 0x12 (350 mA limit instead of 0xD1), unlock CDC_D_SEC_ACCESS / CDC_A_SEC_ACCESS (0xA5) around the PERPH_RESET_CTL4 1 -> 0 soft reset in pm8916_wcd_analog_probe(), expand msm8916_wcd_digital_force_sync_ctl() across all stateful registers in msm8916_wcd_digital_reg_defaults[], and split PM8909 CONGA (CDC_D_PERPH_SUBTYPE == 0x02) from CAJON_2_0 (CDC_A_PERPH_SUBTYPE == 0x0a) in patch 0015 so CAJON-only HPH test/bias writes no longer silence right-channel HPHR output on nokia-sparkler while preserving CAJON_2_0 on nokia-beatles and existing audio/standby invariants. Rebuilt kernel/modules, updated test-audio-quality.py and docs, and rebuilt and verified all four a1125 (ampere) target images.
1330 lines
49 KiB
Diff
1330 lines
49 KiB
Diff
diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c
|
|
index 257f780..5ae2e09 100644
|
|
--- a/sound/soc/codecs/msm8916-wcd-analog.c
|
|
+++ b/sound/soc/codecs/msm8916-wcd-analog.c
|
|
@@ -82,6 +82,8 @@
|
|
#define CDC_A_REVISION4 (0xf103)
|
|
#define CDC_A_PERPH_TYPE (0xf104)
|
|
#define CDC_A_PERPH_SUBTYPE (0xf105)
|
|
+#define CDC_D_PERPH_SUBTYPE_CONGA 0x02
|
|
+#define CDC_A_PERPH_SUBTYPE_CAJON 0x0a
|
|
#define CDC_A_INT_RT_STS (0xf110)
|
|
#define CDC_A_INT_SET_TYPE (0xf111)
|
|
#define CDC_A_INT_POLARITY_HIGH (0xf112)
|
|
@@ -191,6 +193,8 @@
|
|
CDC_A_MBHC_BTN_VREF_FINE_MASK)
|
|
#define CDC_A_MBHC_RESULT_1 (0xf158)
|
|
#define CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK GENMASK(4, 0)
|
|
+#define CDC_A_MBHC_RESULT_2 (0xf159)
|
|
+#define CDC_A_MBHC_RESULT_2_SWCH_LEVEL_REMOVE BIT(4)
|
|
#define CDC_A_TX_1_EN (0xf160)
|
|
#define CDC_A_TX_2_EN (0xf161)
|
|
#define CDC_A_TX_1_2_TEST_CTL_1 (0xf162)
|
|
@@ -220,20 +224,28 @@
|
|
#define CDC_A_RX_HPH_BIAS_LDO_OCP (0xf195)
|
|
#define CDC_A_RX_HPH_BIAS_CNP (0xf196)
|
|
#define CDC_A_RX_HPH_CNP_EN (0xf197)
|
|
+#define CDC_A_RX_HPH_CNP_EN_PU_MASK BIT(3)
|
|
+#define CDC_A_RX_HPH_L_TEST (0xf19A)
|
|
#define CDC_A_RX_HPH_L_PA_DAC_CTL (0xf19B)
|
|
#define RX_HPA_L_PA_DAC_CTL_DATA_RESET_MASK BIT(1)
|
|
#define RX_HPA_L_PA_DAC_CTL_DATA_RESET_RESET BIT(1)
|
|
+#define CDC_A_RX_HPH_R_TEST (0xf19C)
|
|
#define CDC_A_RX_HPH_R_PA_DAC_CTL (0xf19D)
|
|
#define RX_HPH_R_PA_DAC_CTL_DATA_RESET BIT(1)
|
|
#define RX_HPH_R_PA_DAC_CTL_DATA_RESET_MASK BIT(1)
|
|
+#define RX_HPH_TEST_PA_EN BIT(2)
|
|
+#define RX_HPH_TEST_CAJON_CFG BIT(7)
|
|
|
|
#define CDC_A_RX_EAR_CTL (0xf19E)
|
|
#define RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK BIT(0)
|
|
#define RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE BIT(0)
|
|
+#define RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK BIT(5)
|
|
+#define RX_EAR_CTL_PA_GAIN_POS_6_DB BIT(5)
|
|
#define RX_EAR_CTL_PA_EAR_PA_EN_MASK BIT(6)
|
|
#define RX_EAR_CTL_PA_EAR_PA_EN_ENABLE BIT(6)
|
|
#define RX_EAR_CTL_PA_SEL_MASK BIT(7)
|
|
#define RX_EAR_CTL_PA_SEL BIT(7)
|
|
+#define CDC_A_RX_EAR_STATUS (0xf1A1)
|
|
|
|
#define CDC_A_SPKR_DAC_CTL (0xf1B0)
|
|
#define SPKR_DAC_CTL_DAC_RESET_MASK BIT(4)
|
|
@@ -249,10 +261,13 @@
|
|
#define SPKR_DRV_BOOST_SET BIT(2)
|
|
#define SPKR_DRV_CMFB_SET BIT(1)
|
|
#define SPKR_DRV_GAIN_SET BIT(0)
|
|
+#define SPKR_DRV_CTL_NO_BOOST_VAL (SPKR_DRV_CAL_EN | SPKR_DRV_SETTLE_EN | \
|
|
+ SPKR_DRV_FW_EN | SPKR_DRV_GAIN_SET)
|
|
#define SPKR_DRV_CTL_DEF_VAL (SPKR_DRV_CLASSD_PA_EN_ENABLE | \
|
|
SPKR_DRV_CAL_EN | SPKR_DRV_SETTLE_EN | \
|
|
SPKR_DRV_FW_EN | SPKR_DRV_BOOST_SET | \
|
|
SPKR_DRV_CMFB_SET | SPKR_DRV_GAIN_SET)
|
|
+#define CDC_A_SPKR_ANA_BIAS_SET (0xf1B3)
|
|
#define CDC_A_SPKR_OCP_CTL (0xf1B4)
|
|
#define CDC_A_SPKR_PWRSTG_CTL (0xf1B5)
|
|
#define SPKR_PWRSTG_CTL_DAC_EN_MASK BIT(0)
|
|
@@ -314,8 +329,16 @@ struct pm8916_wcd_analog_priv {
|
|
bool audio_active;
|
|
bool jack_inserted;
|
|
bool s2_enabled;
|
|
+ bool is_cajon;
|
|
+ bool is_conga;
|
|
+ int jack_report;
|
|
};
|
|
|
|
+static inline bool pm8916_wcd_is_pm8909(const struct pm8916_wcd_analog_priv *priv)
|
|
+{
|
|
+ return priv->is_cajon || priv->is_conga;
|
|
+}
|
|
+
|
|
static const char *const adc2_mux_text[] = { "ZERO", "INP2", "INP3" };
|
|
static const char *const rdac2_mux_text[] = { "RX1", "RX2" };
|
|
static const char *const hph_text[] = { "ZERO", "Switch", };
|
|
@@ -435,6 +458,36 @@ static int pm8916_wcd_analog_enable_micbias2(struct snd_soc_dapm_widget *w,
|
|
|
|
}
|
|
|
|
+static void pm8916_wcd_analog_apply_defaults(struct snd_soc_component *component,
|
|
+ bool preserve_switch);
|
|
+static int pm8916_wcd_analog_switch_check(struct pm8916_wcd_analog_priv *priv, bool ins);
|
|
+
|
|
+static bool pm8916_mbhc_plug_present(struct snd_soc_component *component)
|
|
+{
|
|
+ int res2 = snd_soc_component_read(component, CDC_A_MBHC_RESULT_2);
|
|
+
|
|
+ if (res2 < 0)
|
|
+ return false;
|
|
+ return !(res2 & CDC_A_MBHC_RESULT_2_SWCH_LEVEL_REMOVE);
|
|
+}
|
|
+
|
|
+static void pm8916_mbhc_disable_btn_bias(struct snd_soc_component *component)
|
|
+{
|
|
+ snd_soc_component_update_bits(component, CDC_A_MBHC_FSM_CTL,
|
|
+ CDC_A_MBHC_FSM_CTL_BTN_ISRC_CTRL_MASK |
|
|
+ CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN_MASK,
|
|
+ 0);
|
|
+ if (!(snd_soc_component_read(component, CDC_A_MICB_2_EN) &
|
|
+ CDC_A_MICB_2_EN_ENABLE)) {
|
|
+ snd_soc_component_update_bits(component, CDC_A_MICB_1_INT_RBIAS,
|
|
+ MICB_1_INT_TX2_INT_RBIAS_EN_MASK,
|
|
+ 0);
|
|
+ snd_soc_component_update_bits(component, CDC_A_MICB_2_EN,
|
|
+ CDC_A_MICB_2_PULL_DOWN_EN_MASK,
|
|
+ CDC_A_MICB_2_PULL_DOWN_EN);
|
|
+ }
|
|
+}
|
|
+
|
|
static int pm8916_wcd_analog_update_power_locked(struct snd_soc_component *component)
|
|
{
|
|
struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
|
|
@@ -446,19 +499,31 @@ static int pm8916_wcd_analog_update_power_locked(struct snd_soc_component *compo
|
|
if (!ret) {
|
|
priv->s2_enabled = true;
|
|
usleep_range(1000, 1500);
|
|
- snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x30);
|
|
+ if (pm8916_wcd_is_pm8909(priv))
|
|
+ pm8916_wcd_analog_apply_defaults(component, true);
|
|
+ else
|
|
+ snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x30);
|
|
+ /*
|
|
+ * Keep digital MBHC debounce clock running so jack
|
|
+ * insertion/removal edges work cleanly even when playback starts idle.
|
|
+ */
|
|
+ snd_soc_component_update_bits(component, CDC_D_CDC_DIG_CLK_CTL,
|
|
+ DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
|
|
+ DIG_CLK_CTL_D_MBHC_CLK_EN);
|
|
} else {
|
|
dev_err(component->dev, "failed to enable vdd-cdc-tx-rx-cx (%d)\n", ret);
|
|
}
|
|
} else if (!need_s2 && priv->s2_enabled) {
|
|
- snd_soc_component_update_bits(component, CDC_A_MBHC_FSM_CTL,
|
|
- CDC_A_MBHC_FSM_CTL_BTN_ISRC_CTRL_MASK |
|
|
- CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN_MASK,
|
|
- 0);
|
|
+ pm8916_mbhc_disable_btn_bias(component);
|
|
+ /*
|
|
+ * Gate the 100uA button current source and s2 Linux vote while
|
|
+ * preserving MASTER_BIAS_CTL and DIG_CLK_CTL_D_MBHC_CLK_EN so the
|
|
+ * 3uA HPHL insertion comparator/debouncer keeps waking from idle.
|
|
+ */
|
|
snd_soc_component_update_bits(component, CDC_D_CDC_DIG_CLK_CTL,
|
|
DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
|
|
- 0);
|
|
- snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x00);
|
|
+ DIG_CLK_CTL_D_MBHC_CLK_EN);
|
|
+ snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x30);
|
|
regulator_disable(priv->supplies[1].consumer);
|
|
priv->s2_enabled = false;
|
|
}
|
|
@@ -698,37 +763,81 @@ static int pm8916_wcd_analog_enable_spk_pa(struct snd_soc_dapm_widget *w,
|
|
int event)
|
|
{
|
|
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
|
|
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
|
|
|
|
switch (event) {
|
|
case SND_SOC_DAPM_PRE_PMU:
|
|
- snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
|
|
- SPKR_PWRSTG_CTL_DAC_EN_MASK |
|
|
- SPKR_PWRSTG_CTL_BBM_MASK |
|
|
- SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
|
|
- SPKR_PWRSTG_CTL_CLAMP_EN_MASK,
|
|
- SPKR_PWRSTG_CTL_DAC_EN|
|
|
- SPKR_PWRSTG_CTL_BBM_EN |
|
|
- SPKR_PWRSTG_CTL_HBRDGE_EN |
|
|
- SPKR_PWRSTG_CTL_CLAMP_EN);
|
|
+ if (pm8916_wcd_is_pm8909(priv)) {
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
|
|
+ SPKR_PWRSTG_CTL_DAC_EN_MASK,
|
|
+ SPKR_PWRSTG_CTL_DAC_EN);
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
|
|
+ SPKR_DAC_CTL_DAC_RESET_MASK,
|
|
+ SPKR_DAC_CTL_DAC_RESET_MASK);
|
|
+ usleep_range(1000, 1100);
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
|
|
+ SPKR_PWRSTG_CTL_MASK,
|
|
+ SPKR_PWRSTG_CTL_BBM_EN |
|
|
+ SPKR_PWRSTG_CTL_HBRDGE_EN |
|
|
+ SPKR_PWRSTG_CTL_CLAMP_EN);
|
|
+ } else {
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
|
|
+ SPKR_PWRSTG_CTL_DAC_EN_MASK |
|
|
+ SPKR_PWRSTG_CTL_BBM_MASK |
|
|
+ SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
|
|
+ SPKR_PWRSTG_CTL_CLAMP_EN_MASK,
|
|
+ SPKR_PWRSTG_CTL_DAC_EN |
|
|
+ SPKR_PWRSTG_CTL_BBM_EN |
|
|
+ SPKR_PWRSTG_CTL_HBRDGE_EN |
|
|
+ SPKR_PWRSTG_CTL_CLAMP_EN);
|
|
+ }
|
|
|
|
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
|
|
RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK,
|
|
RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE);
|
|
break;
|
|
case SND_SOC_DAPM_POST_PMU:
|
|
- snd_soc_component_update_bits(component, CDC_A_SPKR_DRV_CTL,
|
|
- SPKR_DRV_CTL_DEF_MASK,
|
|
- SPKR_DRV_CTL_DEF_VAL);
|
|
+ if (pm8916_wcd_is_pm8909(priv)) {
|
|
+ usleep_range(1000, 1100);
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
|
|
+ SPKR_DAC_CTL_DAC_RESET_MASK,
|
|
+ SPKR_DAC_CTL_DAC_RESET_NORMAL);
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DRV_CTL,
|
|
+ SPKR_DRV_CTL_DEF_MASK &
|
|
+ ~SPKR_DRV_CLASSD_PA_EN_MASK,
|
|
+ SPKR_DRV_CTL_NO_BOOST_VAL);
|
|
+ } else {
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DRV_CTL,
|
|
+ SPKR_DRV_CTL_DEF_MASK,
|
|
+ SPKR_DRV_CTL_DEF_VAL);
|
|
+ }
|
|
snd_soc_component_update_bits(component, w->reg,
|
|
SPKR_DRV_CLASSD_PA_EN_MASK,
|
|
SPKR_DRV_CLASSD_PA_EN_ENABLE);
|
|
break;
|
|
+ case SND_SOC_DAPM_PRE_PMD:
|
|
+ if (pm8916_wcd_is_pm8909(priv)) {
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
|
|
+ SPKR_DAC_CTL_DAC_RESET_MASK,
|
|
+ SPKR_DAC_CTL_DAC_RESET_MASK);
|
|
+ snd_soc_component_update_bits(component, w->reg,
|
|
+ SPKR_DRV_CLASSD_PA_EN_MASK, 0);
|
|
+ }
|
|
+ break;
|
|
case SND_SOC_DAPM_POST_PMD:
|
|
- snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
|
|
- SPKR_PWRSTG_CTL_DAC_EN_MASK|
|
|
- SPKR_PWRSTG_CTL_BBM_MASK |
|
|
- SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
|
|
- SPKR_PWRSTG_CTL_CLAMP_EN_MASK, 0);
|
|
+ if (pm8916_wcd_is_pm8909(priv)) {
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
|
|
+ SPKR_PWRSTG_CTL_MASK, 0);
|
|
+ usleep_range(1000, 1100);
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
|
|
+ SPKR_PWRSTG_CTL_DAC_EN_MASK, 0);
|
|
+ } else {
|
|
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
|
|
+ SPKR_PWRSTG_CTL_DAC_EN_MASK |
|
|
+ SPKR_PWRSTG_CTL_BBM_MASK |
|
|
+ SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
|
|
+ SPKR_PWRSTG_CTL_CLAMP_EN_MASK, 0);
|
|
+ }
|
|
|
|
snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
|
|
SPKR_DAC_CTL_DAC_RESET_MASK,
|
|
@@ -745,11 +854,15 @@ static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w,
|
|
int event)
|
|
{
|
|
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
|
|
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
|
|
|
|
switch (event) {
|
|
case SND_SOC_DAPM_PRE_PMU:
|
|
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
|
|
- RX_EAR_CTL_PA_SEL_MASK, RX_EAR_CTL_PA_SEL);
|
|
+ RX_EAR_CTL_PA_SEL_MASK |
|
|
+ (pm8916_wcd_is_pm8909(priv) ? RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK : 0),
|
|
+ RX_EAR_CTL_PA_SEL |
|
|
+ (pm8916_wcd_is_pm8909(priv) ? RX_EAR_CTL_PA_GAIN_POS_6_DB : 0));
|
|
break;
|
|
case SND_SOC_DAPM_POST_PMU:
|
|
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
|
|
@@ -762,14 +875,127 @@ static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w,
|
|
/* Delay to reduce ear turn off pop */
|
|
usleep_range(7000, 7100);
|
|
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
|
|
- RX_EAR_CTL_PA_SEL_MASK, 0);
|
|
+ RX_EAR_CTL_PA_SEL_MASK |
|
|
+ (pm8916_wcd_is_pm8909(priv) ? RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK : 0),
|
|
+ 0);
|
|
+ break;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int pm8916_wcd_analog_enable_hphl_dac(struct snd_soc_dapm_widget *w,
|
|
+ struct snd_kcontrol *kcontrol,
|
|
+ int event)
|
|
+{
|
|
+ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
|
|
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
|
|
+
|
|
+ switch (event) {
|
|
+ case SND_SOC_DAPM_PRE_PMU:
|
|
+ if (priv->is_cajon) {
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_CNP_EN,
|
|
+ CDC_A_RX_HPH_CNP_EN_PU_MASK,
|
|
+ CDC_A_RX_HPH_CNP_EN_PU_MASK);
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_L_TEST,
|
|
+ RX_HPH_TEST_CAJON_CFG,
|
|
+ RX_HPH_TEST_CAJON_CFG);
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_R_TEST,
|
|
+ RX_HPH_TEST_CAJON_CFG,
|
|
+ RX_HPH_TEST_CAJON_CFG);
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_CNP_EN,
|
|
+ CDC_A_RX_HPH_CNP_EN_PU_MASK, 0);
|
|
+ snd_soc_component_update_bits(component, CDC_A_NCP_VCTRL,
|
|
+ 0x07, 0x07);
|
|
+ }
|
|
+ if (pm8916_wcd_is_pm8909(priv)) {
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
|
|
+ RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK,
|
|
+ RX_EAR_CTL_PA_GAIN_POS_6_DB);
|
|
+ }
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_L_PA_DAC_CTL,
|
|
+ RX_HPA_L_PA_DAC_CTL_DATA_RESET_MASK,
|
|
+ RX_HPA_L_PA_DAC_CTL_DATA_RESET_RESET);
|
|
+ break;
|
|
+ case SND_SOC_DAPM_POST_PMU:
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_L_PA_DAC_CTL,
|
|
+ RX_HPA_L_PA_DAC_CTL_DATA_RESET_MASK, 0);
|
|
+ break;
|
|
+ case SND_SOC_DAPM_POST_PMD:
|
|
+ if (pm8916_wcd_is_pm8909(priv)) {
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
|
|
+ RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK, 0);
|
|
+ }
|
|
+ if (priv->is_cajon) {
|
|
+ snd_soc_component_update_bits(component, CDC_A_NCP_VCTRL,
|
|
+ 0x07, 0x04);
|
|
+ }
|
|
+ break;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int pm8916_wcd_analog_enable_hphr_dac(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_PRE_PMU:
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_R_PA_DAC_CTL,
|
|
+ RX_HPH_R_PA_DAC_CTL_DATA_RESET_MASK,
|
|
+ RX_HPH_R_PA_DAC_CTL_DATA_RESET);
|
|
+ break;
|
|
+ case SND_SOC_DAPM_POST_PMU:
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_R_PA_DAC_CTL,
|
|
+ RX_HPH_R_PA_DAC_CTL_DATA_RESET_MASK, 0);
|
|
+ break;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int pm8916_wcd_analog_enable_hph_pa(struct snd_soc_dapm_widget *w,
|
|
+ struct snd_kcontrol *kcontrol,
|
|
+ int event)
|
|
+{
|
|
+ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
|
|
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
|
|
+ unsigned int test_reg = (w->shift == 5) ? CDC_A_RX_HPH_L_TEST : CDC_A_RX_HPH_R_TEST;
|
|
+
|
|
+ if (!pm8916_wcd_is_pm8909(priv))
|
|
+ return 0;
|
|
+
|
|
+ switch (event) {
|
|
+ case SND_SOC_DAPM_PRE_PMU:
|
|
+ snd_soc_component_update_bits(component, CDC_A_NCP_FBCTRL,
|
|
+ CDC_A_NCP_FBCTRL_FB_CLK_INV_MASK,
|
|
+ CDC_A_NCP_FBCTRL_FB_CLK_INV);
|
|
+ break;
|
|
+ case SND_SOC_DAPM_POST_PMU:
|
|
+ usleep_range(7000, 7100);
|
|
+ snd_soc_component_update_bits(component, test_reg,
|
|
+ RX_HPH_TEST_PA_EN,
|
|
+ RX_HPH_TEST_PA_EN);
|
|
+ break;
|
|
+ case SND_SOC_DAPM_PRE_PMD:
|
|
+ snd_soc_component_update_bits(component, test_reg,
|
|
+ RX_HPH_TEST_PA_EN, 0);
|
|
+ if (priv->is_cajon)
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_BIAS_CNP,
|
|
+ 0xF0, 0x30);
|
|
+ break;
|
|
+ case SND_SOC_DAPM_POST_PMD:
|
|
+ if (priv->is_cajon)
|
|
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_BIAS_CNP,
|
|
+ 0xF0, 0x20);
|
|
+ usleep_range(5000, 5200);
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static const struct reg_default wcd_reg_defaults_2_0[] = {
|
|
- {CDC_A_RX_COM_OCP_CTL, 0xD1},
|
|
+ {CDC_A_RX_COM_OCP_CTL, 0x12},
|
|
{CDC_A_RX_COM_OCP_COUNT, 0xFF},
|
|
{CDC_D_SEC_ACCESS, 0xA5},
|
|
{CDC_D_PERPH_RESET_CTL3, 0x0F},
|
|
@@ -787,10 +1013,83 @@ static const struct reg_default wcd_reg_defaults_2_0[] = {
|
|
{CDC_A_MASTER_BIAS_CTL, 0x30},
|
|
};
|
|
|
|
+static const struct reg_default wcd_reg_defaults_cajon_2_0[] = {
|
|
+ {CDC_A_RX_COM_OCP_CTL, 0x12},
|
|
+ {CDC_A_RX_COM_OCP_COUNT, 0xFF},
|
|
+ {CDC_D_SEC_ACCESS, 0xA5},
|
|
+ {CDC_D_PERPH_RESET_CTL3, 0x0F},
|
|
+ {CDC_A_SEC_ACCESS, 0xA5},
|
|
+ {CDC_A_PERPH_RESET_CTL3, 0x0F},
|
|
+ {CDC_A_TX_1_2_OPAMP_BIAS, 0x4C},
|
|
+ {CDC_A_NCP_FBCTRL, 0xA8},
|
|
+ {CDC_A_NCP_VCTRL, 0xA4},
|
|
+ {CDC_A_RX_HPH_BIAS_PA, 0xFA},
|
|
+ {CDC_A_SPKR_ANA_BIAS_SET, 0x41},
|
|
+ {CDC_A_SPKR_DRV_CTL, 0x69},
|
|
+ {CDC_A_SPKR_DRV_DBG, 0x01},
|
|
+ {CDC_A_SPKR_OCP_CTL, 0xE1},
|
|
+ {CDC_A_SPKR_DAC_CTL, 0x03},
|
|
+ {CDC_A_RX_EAR_STATUS, 0x10},
|
|
+ {CDC_A_MASTER_BIAS_CTL, 0x30},
|
|
+};
|
|
+
|
|
+static const struct reg_default wcd_reg_defaults_conga[] = {
|
|
+ {CDC_A_RX_COM_OCP_CTL, 0x12},
|
|
+ {CDC_A_RX_COM_OCP_COUNT, 0xFF},
|
|
+ {CDC_D_SEC_ACCESS, 0xA5},
|
|
+ {CDC_D_PERPH_RESET_CTL3, 0x0F},
|
|
+ {CDC_A_SEC_ACCESS, 0xA5},
|
|
+ {CDC_A_PERPH_RESET_CTL3, 0x0F},
|
|
+ {CDC_A_TX_1_2_OPAMP_BIAS, 0x4C},
|
|
+ {CDC_A_NCP_FBCTRL, 0x28},
|
|
+ {CDC_A_SPKR_DRV_CTL, 0x69},
|
|
+ {CDC_A_SPKR_DRV_DBG, 0x01},
|
|
+ {CDC_A_SPKR_DAC_CTL, 0x03},
|
|
+ {CDC_A_SPKR_OCP_CTL, 0xE1},
|
|
+ {CDC_A_MASTER_BIAS_CTL, 0x30},
|
|
+};
|
|
+
|
|
+static void pm8916_wcd_analog_apply_defaults(struct snd_soc_component *component,
|
|
+ bool preserve_switch)
|
|
+{
|
|
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
|
|
+ const struct reg_default *defs;
|
|
+ size_t count;
|
|
+
|
|
+ if (priv->is_conga) {
|
|
+ defs = wcd_reg_defaults_conga;
|
|
+ count = ARRAY_SIZE(wcd_reg_defaults_conga);
|
|
+ } else if (priv->is_cajon) {
|
|
+ defs = wcd_reg_defaults_cajon_2_0;
|
|
+ count = ARRAY_SIZE(wcd_reg_defaults_cajon_2_0);
|
|
+ } else {
|
|
+ defs = wcd_reg_defaults_2_0;
|
|
+ count = ARRAY_SIZE(wcd_reg_defaults_2_0);
|
|
+ }
|
|
+ size_t i;
|
|
+
|
|
+ for (i = 0; i < count; i++) {
|
|
+ if (preserve_switch && defs[i].reg == CDC_A_SPKR_DAC_CTL) {
|
|
+ snd_soc_component_update_bits(component, defs[i].reg,
|
|
+ 0x7F, defs[i].def & 0x7F);
|
|
+ } else if (preserve_switch && defs[i].reg == CDC_A_SPKR_DRV_CTL) {
|
|
+ snd_soc_component_update_bits(component, defs[i].reg,
|
|
+ SPKR_DRV_CTL_DEF_MASK &
|
|
+ ~SPKR_DRV_CLASSD_PA_EN_MASK &
|
|
+ ~SPKR_DRV_CAL_EN,
|
|
+ defs[i].def &
|
|
+ ~SPKR_DRV_CLASSD_PA_EN_MASK &
|
|
+ ~SPKR_DRV_CAL_EN);
|
|
+ } else {
|
|
+ snd_soc_component_write(component, defs[i].reg, defs[i].def);
|
|
+ }
|
|
+ }
|
|
+}
|
|
+
|
|
static int pm8916_wcd_analog_probe(struct snd_soc_component *component)
|
|
{
|
|
struct pm8916_wcd_analog_priv *priv = dev_get_drvdata(component->dev);
|
|
- int err, reg;
|
|
+ int err;
|
|
|
|
err = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
|
|
if (err != 0) {
|
|
@@ -806,16 +1105,27 @@ static int pm8916_wcd_analog_probe(struct snd_soc_component *component)
|
|
snd_soc_component_set_drvdata(component, priv);
|
|
priv->pmic_rev = snd_soc_component_read(component, CDC_D_REVISION1);
|
|
priv->codec_version = snd_soc_component_read(component, CDC_D_PERPH_SUBTYPE);
|
|
+ priv->is_conga = (priv->codec_version == CDC_D_PERPH_SUBTYPE_CONGA);
|
|
+ priv->is_cajon = !priv->is_conga &&
|
|
+ (snd_soc_component_read(component, CDC_A_PERPH_SUBTYPE) ==
|
|
+ CDC_A_PERPH_SUBTYPE_CAJON);
|
|
|
|
- dev_info(component->dev, "PMIC REV: %d\t CODEC Version: %d\n",
|
|
- priv->pmic_rev, priv->codec_version);
|
|
+ dev_info(component->dev, "PMIC REV: %d\t CODEC Version: %d%s\n",
|
|
+ priv->pmic_rev, priv->codec_version,
|
|
+ priv->is_conga ? " (CONGA)" : (priv->is_cajon ? " (CAJON)" : ""));
|
|
|
|
+ snd_soc_component_write(component, CDC_D_SEC_ACCESS, 0xA5);
|
|
snd_soc_component_write(component, CDC_D_PERPH_RESET_CTL4, 0x01);
|
|
+ snd_soc_component_write(component, CDC_A_SEC_ACCESS, 0xA5);
|
|
snd_soc_component_write(component, CDC_A_PERPH_RESET_CTL4, 0x01);
|
|
+ usleep_range(500, 1000);
|
|
+ snd_soc_component_write(component, CDC_D_SEC_ACCESS, 0xA5);
|
|
+ snd_soc_component_write(component, CDC_D_PERPH_RESET_CTL4, 0x00);
|
|
+ snd_soc_component_write(component, CDC_A_SEC_ACCESS, 0xA5);
|
|
+ snd_soc_component_write(component, CDC_A_PERPH_RESET_CTL4, 0x00);
|
|
+ usleep_range(500, 1000);
|
|
|
|
- for (reg = 0; reg < ARRAY_SIZE(wcd_reg_defaults_2_0); reg++)
|
|
- snd_soc_component_write(component, wcd_reg_defaults_2_0[reg].reg,
|
|
- wcd_reg_defaults_2_0[reg].def);
|
|
+ pm8916_wcd_analog_apply_defaults(component, false);
|
|
|
|
priv->component = component;
|
|
|
|
@@ -824,24 +1134,21 @@ static int pm8916_wcd_analog_probe(struct snd_soc_component *component)
|
|
RST_CTL_DIG_SW_RST_N_REMOVE_RESET);
|
|
|
|
pm8916_wcd_setup_mbhc(priv);
|
|
- usleep_range(1000, 1500);
|
|
+ usleep_range(5000, 6000);
|
|
|
|
- mutex_lock(&priv->power_lock);
|
|
- if (!priv->jack_inserted) {
|
|
- u32 det_ctl = snd_soc_component_read(component, CDC_A_MBHC_DET_CTL_1);
|
|
- u32 rt_sts = snd_soc_component_read(component, CDC_D_INT_RT_STS);
|
|
-
|
|
- if (!(det_ctl & CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK) ||
|
|
- (rt_sts & MBHC_SWITCH_INT))
|
|
- priv->jack_inserted = true;
|
|
+ if (!priv->jack_gpio.report && pm8916_mbhc_plug_present(component)) {
|
|
+ pm8916_wcd_analog_switch_check(priv, true);
|
|
+ } else {
|
|
+ mutex_lock(&priv->power_lock);
|
|
+ if (!priv->jack_inserted && priv->mbhc_btn_enabled)
|
|
+ snd_soc_component_write(component, CDC_D_INT_EN_CLR,
|
|
+ MBHC_BUTTON_PRESS_DET |
|
|
+ MBHC_BUTTON_RELEASE_DET);
|
|
+ err = pm8916_wcd_analog_update_power_locked(component);
|
|
+ mutex_unlock(&priv->power_lock);
|
|
+ if (err)
|
|
+ dev_warn(component->dev, "failed initial wcd power sync (%d)\n", err);
|
|
}
|
|
- if (!priv->jack_inserted && priv->mbhc_btn_enabled)
|
|
- snd_soc_component_write(component, CDC_D_INT_EN_CLR,
|
|
- MBHC_BUTTON_PRESS_DET | MBHC_BUTTON_RELEASE_DET);
|
|
- err = pm8916_wcd_analog_update_power_locked(component);
|
|
- mutex_unlock(&priv->power_lock);
|
|
- if (err)
|
|
- dev_warn(component->dev, "failed initial wcd power sync (%d)\n", err);
|
|
|
|
return 0;
|
|
}
|
|
@@ -981,14 +1288,27 @@ static const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = {
|
|
SND_SOC_DAPM_MUX("EAR_S", SND_SOC_NOPM, 0, 0, &ear_mux),
|
|
SND_SOC_DAPM_SUPPLY("EAR CP", CDC_A_NCP_EN, 4, 0, NULL, 0),
|
|
|
|
- SND_SOC_DAPM_PGA("HPHL PA", CDC_A_RX_HPH_CNP_EN, 5, 0, NULL, 0),
|
|
+ SND_SOC_DAPM_PGA_E("HPHL PA", CDC_A_RX_HPH_CNP_EN,
|
|
+ 5, 0, NULL, 0,
|
|
+ pm8916_wcd_analog_enable_hph_pa,
|
|
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
|
|
+ SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
|
|
SND_SOC_DAPM_MUX("HPHL", SND_SOC_NOPM, 0, 0, &hphl_mux),
|
|
- SND_SOC_DAPM_MIXER("HPHL DAC", CDC_A_RX_HPH_L_PA_DAC_CTL, 3, 0, NULL,
|
|
- 0),
|
|
- SND_SOC_DAPM_PGA("HPHR PA", CDC_A_RX_HPH_CNP_EN, 4, 0, NULL, 0),
|
|
+ SND_SOC_DAPM_MIXER_E("HPHL DAC", CDC_A_RX_HPH_L_PA_DAC_CTL,
|
|
+ 3, 0, NULL, 0,
|
|
+ pm8916_wcd_analog_enable_hphl_dac,
|
|
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
|
|
+ SND_SOC_DAPM_POST_PMD),
|
|
+ SND_SOC_DAPM_PGA_E("HPHR PA", CDC_A_RX_HPH_CNP_EN,
|
|
+ 4, 0, NULL, 0,
|
|
+ pm8916_wcd_analog_enable_hph_pa,
|
|
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
|
|
+ SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
|
|
SND_SOC_DAPM_MUX("HPHR", SND_SOC_NOPM, 0, 0, &hphr_mux),
|
|
- SND_SOC_DAPM_MIXER("HPHR DAC", CDC_A_RX_HPH_R_PA_DAC_CTL, 3, 0, NULL,
|
|
- 0),
|
|
+ SND_SOC_DAPM_MIXER_E("HPHR DAC", CDC_A_RX_HPH_R_PA_DAC_CTL,
|
|
+ 3, 0, NULL, 0,
|
|
+ pm8916_wcd_analog_enable_hphr_dac,
|
|
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
|
|
SND_SOC_DAPM_MIXER("SPK DAC", SND_SOC_NOPM, 0, 0,
|
|
spkr_switch, ARRAY_SIZE(spkr_switch)),
|
|
|
|
@@ -1094,6 +1414,14 @@ static int pm8916_wcd_analog_set_jack(struct snd_soc_component *component,
|
|
}
|
|
|
|
wcd->jack = jack;
|
|
+ if (jack && !wcd->jack_gpio.report) {
|
|
+ int initial_report;
|
|
+
|
|
+ mutex_lock(&wcd->power_lock);
|
|
+ initial_report = wcd->jack_inserted ? wcd->jack_report : 0;
|
|
+ mutex_unlock(&wcd->power_lock);
|
|
+ snd_soc_jack_report(jack, initial_report, hs_jack_mask);
|
|
+ }
|
|
|
|
return 0;
|
|
}
|
|
@@ -1164,9 +1492,14 @@ static int pm8916_wcd_analog_switch_check(struct pm8916_wcd_analog_priv *priv, b
|
|
CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK,
|
|
(!ins << CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_SHIFT));
|
|
|
|
-
|
|
if (ins) { /* hs insertion */
|
|
bool micbias_enabled = false;
|
|
+ int rt_sts;
|
|
+
|
|
+ if (priv->mbhc_btn_enabled)
|
|
+ snd_soc_component_write(component, CDC_D_INT_EN_CLR,
|
|
+ MBHC_BUTTON_PRESS_DET |
|
|
+ MBHC_BUTTON_RELEASE_DET);
|
|
|
|
mutex_lock(&priv->power_lock);
|
|
priv->jack_inserted = true;
|
|
@@ -1176,33 +1509,56 @@ static int pm8916_wcd_analog_switch_check(struct pm8916_wcd_analog_priv *priv, b
|
|
snd_soc_component_update_bits(component, CDC_D_CDC_DIG_CLK_CTL,
|
|
DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
|
|
DIG_CLK_CTL_D_MBHC_CLK_EN);
|
|
- if (priv->mbhc_btn_enabled)
|
|
- snd_soc_component_update_bits(component, CDC_D_INT_EN_SET,
|
|
- MBHC_BUTTON_PRESS_DET |
|
|
- MBHC_BUTTON_RELEASE_DET,
|
|
- MBHC_BUTTON_PRESS_DET |
|
|
- MBHC_BUTTON_RELEASE_DET);
|
|
|
|
if (snd_soc_component_read(component, CDC_A_MICB_2_EN) &
|
|
CDC_A_MICB_2_EN_ENABLE)
|
|
micbias_enabled = true;
|
|
|
|
+ snd_soc_component_update_bits(component, CDC_A_MBHC_FSM_CTL,
|
|
+ CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN_MASK,
|
|
+ 0);
|
|
pm8916_mbhc_configure_bias(priv, micbias_enabled);
|
|
+ msleep(25);
|
|
+ rt_sts = snd_soc_component_read(component, CDC_D_INT_RT_STS);
|
|
+ if (rt_sts >= 0 && (rt_sts & MBHC_BUTTON_PRESS_DET)) {
|
|
+ msleep(75);
|
|
+ rt_sts = snd_soc_component_read(component, CDC_D_INT_RT_STS);
|
|
+ }
|
|
+
|
|
+ if (!priv->jack_gpio.report && !pm8916_mbhc_plug_present(component)) {
|
|
+ snd_soc_component_update_bits(component, CDC_A_MBHC_DET_CTL_1,
|
|
+ CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK,
|
|
+ CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_INSERTION);
|
|
+ goto remove;
|
|
+ }
|
|
|
|
/*
|
|
- * if only a btn0 press event is receive just before
|
|
- * insert event then its a 3 pole headphone else if
|
|
- * both press and release event received then its
|
|
- * a headset.
|
|
+ * After MBHC FSM settling, a 4-pole headset pulls MIC above BTN0
|
|
+ * (no BTN_PRESS_DET) or releases BTN0; a 3-pole headphone shorts
|
|
+ * MIC to GND (BTN_PRESS_DET stays asserted), so keep 100uA ISRC
|
|
+ * and button IRQs disabled on 3-pole plugs.
|
|
*/
|
|
- if (priv->mbhc_btn0_released)
|
|
+ if (priv->mbhc_btn0_released ||
|
|
+ (rt_sts >= 0 && !(rt_sts & MBHC_BUTTON_PRESS_DET))) {
|
|
report = SND_JACK_HEADSET;
|
|
- else
|
|
+ if (priv->mbhc_btn_enabled)
|
|
+ snd_soc_component_update_bits(component, CDC_D_INT_EN_SET,
|
|
+ MBHC_BUTTON_PRESS_DET |
|
|
+ MBHC_BUTTON_RELEASE_DET,
|
|
+ MBHC_BUTTON_PRESS_DET |
|
|
+ MBHC_BUTTON_RELEASE_DET);
|
|
+ } else {
|
|
report = SND_JACK_HEADPHONE;
|
|
+ pm8916_mbhc_disable_btn_bias(component);
|
|
+ }
|
|
|
|
priv->detect_accessory_type = false;
|
|
+ mutex_lock(&priv->power_lock);
|
|
+ priv->jack_report = report;
|
|
+ mutex_unlock(&priv->power_lock);
|
|
|
|
} else { /* removal */
|
|
+remove:
|
|
report = 0;
|
|
priv->detect_accessory_type = true;
|
|
priv->mbhc_btn0_released = false;
|
|
@@ -1210,8 +1566,10 @@ static int pm8916_wcd_analog_switch_check(struct pm8916_wcd_analog_priv *priv, b
|
|
snd_soc_component_write(component, CDC_D_INT_EN_CLR,
|
|
MBHC_BUTTON_PRESS_DET |
|
|
MBHC_BUTTON_RELEASE_DET);
|
|
+ pm8916_mbhc_disable_btn_bias(component);
|
|
mutex_lock(&priv->power_lock);
|
|
priv->jack_inserted = false;
|
|
+ priv->jack_report = 0;
|
|
pm8916_wcd_analog_update_power_locked(component);
|
|
mutex_unlock(&priv->power_lock);
|
|
}
|
|
@@ -1223,15 +1581,22 @@ static irqreturn_t pm8916_mbhc_switch_irq_handler(int irq, void *arg)
|
|
{
|
|
struct pm8916_wcd_analog_priv *priv = arg;
|
|
struct snd_soc_component *component = priv->component;
|
|
- bool ins = false;
|
|
+ u32 det_ctl;
|
|
+ bool waiting_ins, phys_ins;
|
|
int report;
|
|
|
|
- if (snd_soc_component_read(component, CDC_A_MBHC_DET_CTL_1) &
|
|
- CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK)
|
|
- ins = true;
|
|
+ if (!component)
|
|
+ return IRQ_HANDLED;
|
|
+
|
|
+ det_ctl = snd_soc_component_read(component, CDC_A_MBHC_DET_CTL_1);
|
|
+ waiting_ins = !!(det_ctl & CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK);
|
|
+ phys_ins = pm8916_mbhc_plug_present(component);
|
|
+ if (phys_ins != waiting_ins)
|
|
+ return IRQ_HANDLED;
|
|
|
|
- report = pm8916_wcd_analog_switch_check(priv, ins);
|
|
- snd_soc_jack_report(priv->jack, report, hs_jack_mask);
|
|
+ report = pm8916_wcd_analog_switch_check(priv, phys_ins);
|
|
+ if (priv->jack)
|
|
+ snd_soc_jack_report(priv->jack, report, hs_jack_mask);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
diff --git a/sound/soc/codecs/msm8916-wcd-digital.c b/sound/soc/codecs/msm8916-wcd-digital.c
|
|
index 81d1134..074a319 100644
|
|
--- a/sound/soc/codecs/msm8916-wcd-digital.c
|
|
+++ b/sound/soc/codecs/msm8916-wcd-digital.c
|
|
@@ -85,6 +85,9 @@
|
|
#define LPASS_CDC_RX1_B5_CTL (0x050)
|
|
#define LPASS_CDC_RX2_B5_CTL (0x070)
|
|
#define LPASS_CDC_RX3_B5_CTL (0x090)
|
|
+#define RXn_B5_CTL_INTERP_FS_RATE_MASK GENMASK(7, 5)
|
|
+#define RXn_B5_CTL_INTERP_FS_RATE_SHIFT 5
|
|
+#define RXn_B5_CTL_INTERP_HALFBAND_EN BIT(3)
|
|
#define LPASS_CDC_RX1_B6_CTL (0x054)
|
|
#define RXn_B6_CTL_MUTE_MASK BIT(0)
|
|
#define RXn_B6_CTL_MUTE_ENABLE BIT(0)
|
|
@@ -172,6 +175,7 @@
|
|
#define LPASS_CDC_TX2_MUX_CTL (0x2AC)
|
|
#define LPASS_CDC_TX1_CLK_FS_CTL (0x290)
|
|
#define LPASS_CDC_TX2_CLK_FS_CTL (0x2B0)
|
|
+#define TXn_CLK_FS_CTL_FS_RATE_MASK GENMASK(2, 0)
|
|
#define LPASS_CDC_TX1_DMIC_CTL (0x294)
|
|
#define LPASS_CDC_TX2_DMIC_CTL (0x2B4)
|
|
#define TXN_DMIC_CTL_CLK_SEL_MASK GENMASK(2, 0)
|
|
@@ -236,6 +240,12 @@ static const unsigned long rx_gain_reg[] = {
|
|
LPASS_CDC_RX3_VOL_CTL_B2_CTL,
|
|
};
|
|
|
|
+static const unsigned long rx_b5_reg[] = {
|
|
+ LPASS_CDC_RX1_B5_CTL,
|
|
+ LPASS_CDC_RX2_B5_CTL,
|
|
+ LPASS_CDC_RX3_B5_CTL,
|
|
+};
|
|
+
|
|
static const unsigned long tx_gain_reg[] = {
|
|
LPASS_CDC_TX1_VOL_CTL_GAIN,
|
|
LPASS_CDC_TX2_VOL_CTL_GAIN,
|
|
@@ -580,19 +590,26 @@ static int msm8916_wcd_digital_enable_interpolator(
|
|
int event)
|
|
{
|
|
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
|
|
+ struct msm8916_wcd_digital_priv *priv = snd_soc_component_get_drvdata(component);
|
|
|
|
switch (event) {
|
|
+ case SND_SOC_DAPM_PRE_PMU:
|
|
+ regmap_write_bits(priv->regmap, rx_b5_reg[w->shift], ~0U,
|
|
+ snd_soc_component_read(component, rx_b5_reg[w->shift]));
|
|
+ break;
|
|
case SND_SOC_DAPM_POST_PMU:
|
|
/* apply the digital gain after the interpolator is enabled */
|
|
usleep_range(10000, 10100);
|
|
+ regmap_write_bits(priv->regmap, rx_b5_reg[w->shift], ~0U,
|
|
+ snd_soc_component_read(component, rx_b5_reg[w->shift]));
|
|
snd_soc_component_write(component, rx_gain_reg[w->shift],
|
|
snd_soc_component_read(component, rx_gain_reg[w->shift]));
|
|
break;
|
|
case SND_SOC_DAPM_POST_PMD:
|
|
- snd_soc_component_update_bits(component, LPASS_CDC_CLK_RX_RESET_CTL,
|
|
- 1 << w->shift, 1 << w->shift);
|
|
- snd_soc_component_update_bits(component, LPASS_CDC_CLK_RX_RESET_CTL,
|
|
- 1 << w->shift, 0x0);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_CLK_RX_RESET_CTL,
|
|
+ BIT(w->shift), BIT(w->shift));
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_CLK_RX_RESET_CTL,
|
|
+ BIT(w->shift), 0);
|
|
break;
|
|
}
|
|
return 0;
|
|
@@ -603,6 +620,7 @@ static int msm8916_wcd_digital_enable_dec(struct snd_soc_dapm_widget *w,
|
|
int event)
|
|
{
|
|
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
|
|
+ struct msm8916_wcd_digital_priv *priv = snd_soc_component_get_drvdata(component);
|
|
unsigned int decimator = w->shift + 1;
|
|
u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
|
|
u8 dec_hpf_cut_of_freq;
|
|
@@ -647,9 +665,9 @@ static int msm8916_wcd_digital_enable_dec(struct snd_soc_dapm_widget *w,
|
|
TX_MUX_CTL_HPF_BP_SEL_BYPASS);
|
|
break;
|
|
case SND_SOC_DAPM_POST_PMD:
|
|
- snd_soc_component_update_bits(component, dec_reset_reg, 1 << w->shift,
|
|
- 1 << w->shift);
|
|
- snd_soc_component_update_bits(component, dec_reset_reg, 1 << w->shift, 0x0);
|
|
+ regmap_write_bits(priv->regmap, dec_reset_reg, BIT(w->shift),
|
|
+ BIT(w->shift));
|
|
+ regmap_write_bits(priv->regmap, dec_reset_reg, BIT(w->shift), 0);
|
|
snd_soc_component_update_bits(component, tx_mux_ctl_reg,
|
|
TX_MUX_CTL_HPF_BP_SEL_MASK,
|
|
TX_MUX_CTL_HPF_BP_SEL_BYPASS);
|
|
@@ -741,13 +759,16 @@ static const struct snd_soc_dapm_widget msm8916_wcd_digital_dapm_widgets[] = {
|
|
/* Interpolator */
|
|
SND_SOC_DAPM_MIXER_E("RX1 INT", LPASS_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
|
|
0, msm8916_wcd_digital_enable_interpolator,
|
|
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
|
|
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
|
|
+ SND_SOC_DAPM_POST_PMD),
|
|
SND_SOC_DAPM_MIXER_E("RX2 INT", LPASS_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
|
|
0, msm8916_wcd_digital_enable_interpolator,
|
|
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
|
|
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
|
|
+ SND_SOC_DAPM_POST_PMD),
|
|
SND_SOC_DAPM_MIXER_E("RX3 INT", LPASS_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
|
|
0, msm8916_wcd_digital_enable_interpolator,
|
|
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
|
|
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
|
|
+ SND_SOC_DAPM_POST_PMD),
|
|
SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
|
|
&rx_mix1_inp1_mux),
|
|
SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
|
|
@@ -865,6 +886,7 @@ static int msm8916_wcd_digital_hw_params(struct snd_pcm_substream *substream,
|
|
struct snd_pcm_hw_params *params,
|
|
struct snd_soc_dai *dai)
|
|
{
|
|
+ struct msm8916_wcd_digital_priv *priv = snd_soc_component_get_drvdata(dai->component);
|
|
u8 tx_fs_rate;
|
|
u8 rx_fs_rate;
|
|
|
|
@@ -893,12 +915,31 @@ static int msm8916_wcd_digital_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
switch (substream->stream) {
|
|
case SNDRV_PCM_STREAM_CAPTURE:
|
|
- snd_soc_component_update_bits(dai->component, LPASS_CDC_CLK_TX_I2S_CTL,
|
|
- TX_I2S_CTL_TX_I2S_FS_RATE_MASK, tx_fs_rate);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_CLK_TX_I2S_CTL,
|
|
+ TX_I2S_CTL_TX_I2S_FS_RATE_MASK, tx_fs_rate);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_TX1_CLK_FS_CTL,
|
|
+ TXn_CLK_FS_CTL_FS_RATE_MASK, tx_fs_rate);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_TX2_CLK_FS_CTL,
|
|
+ TXn_CLK_FS_CTL_FS_RATE_MASK, tx_fs_rate);
|
|
break;
|
|
case SNDRV_PCM_STREAM_PLAYBACK:
|
|
- snd_soc_component_update_bits(dai->component, LPASS_CDC_CLK_RX_I2S_CTL,
|
|
- RX_I2S_CTL_RX_I2S_FS_RATE_MASK, rx_fs_rate);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_CLK_RX_I2S_CTL,
|
|
+ RX_I2S_CTL_RX_I2S_FS_RATE_MASK, rx_fs_rate);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_RX1_B5_CTL,
|
|
+ RXn_B5_CTL_INTERP_FS_RATE_MASK |
|
|
+ RXn_B5_CTL_INTERP_HALFBAND_EN,
|
|
+ (rx_fs_rate << RXn_B5_CTL_INTERP_FS_RATE_SHIFT) |
|
|
+ RXn_B5_CTL_INTERP_HALFBAND_EN);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_RX2_B5_CTL,
|
|
+ RXn_B5_CTL_INTERP_FS_RATE_MASK |
|
|
+ RXn_B5_CTL_INTERP_HALFBAND_EN,
|
|
+ (rx_fs_rate << RXn_B5_CTL_INTERP_FS_RATE_SHIFT) |
|
|
+ RXn_B5_CTL_INTERP_HALFBAND_EN);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_RX3_B5_CTL,
|
|
+ RXn_B5_CTL_INTERP_FS_RATE_MASK |
|
|
+ RXn_B5_CTL_INTERP_HALFBAND_EN,
|
|
+ (rx_fs_rate << RXn_B5_CTL_INTERP_FS_RATE_SHIFT) |
|
|
+ RXn_B5_CTL_INTERP_HALFBAND_EN);
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
@@ -906,21 +947,21 @@ static int msm8916_wcd_digital_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
switch (params_format(params)) {
|
|
case SNDRV_PCM_FORMAT_S16_LE:
|
|
- snd_soc_component_update_bits(dai->component, LPASS_CDC_CLK_TX_I2S_CTL,
|
|
- TX_I2S_CTL_TX_I2S_MODE_MASK,
|
|
- TX_I2S_CTL_TX_I2S_MODE_16);
|
|
- snd_soc_component_update_bits(dai->component, LPASS_CDC_CLK_RX_I2S_CTL,
|
|
- RX_I2S_CTL_RX_I2S_MODE_MASK,
|
|
- RX_I2S_CTL_RX_I2S_MODE_16);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_CLK_TX_I2S_CTL,
|
|
+ TX_I2S_CTL_TX_I2S_MODE_MASK,
|
|
+ TX_I2S_CTL_TX_I2S_MODE_16);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_CLK_RX_I2S_CTL,
|
|
+ RX_I2S_CTL_RX_I2S_MODE_MASK,
|
|
+ RX_I2S_CTL_RX_I2S_MODE_16);
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S32_LE:
|
|
- snd_soc_component_update_bits(dai->component, LPASS_CDC_CLK_TX_I2S_CTL,
|
|
- TX_I2S_CTL_TX_I2S_MODE_MASK,
|
|
- TX_I2S_CTL_TX_I2S_MODE_32);
|
|
- snd_soc_component_update_bits(dai->component, LPASS_CDC_CLK_RX_I2S_CTL,
|
|
- RX_I2S_CTL_RX_I2S_MODE_MASK,
|
|
- RX_I2S_CTL_RX_I2S_MODE_32);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_CLK_TX_I2S_CTL,
|
|
+ TX_I2S_CTL_TX_I2S_MODE_MASK,
|
|
+ TX_I2S_CTL_TX_I2S_MODE_32);
|
|
+ regmap_write_bits(priv->regmap, LPASS_CDC_CLK_RX_I2S_CTL,
|
|
+ RX_I2S_CTL_RX_I2S_MODE_MASK,
|
|
+ RX_I2S_CTL_RX_I2S_MODE_32);
|
|
break;
|
|
default:
|
|
dev_err(dai->dev, "%s: wrong format selected\n", __func__);
|
|
@@ -1071,6 +1112,8 @@ static const struct snd_soc_dapm_route msm8916_wcd_digital_audio_map[] = {
|
|
|
|
};
|
|
|
|
+static void msm8916_wcd_digital_force_sync_ctl(struct regmap *map);
|
|
+
|
|
static int msm8916_wcd_digital_startup(struct snd_pcm_substream *substream,
|
|
struct snd_soc_dai *dai)
|
|
{
|
|
@@ -1079,29 +1122,30 @@ static int msm8916_wcd_digital_startup(struct snd_pcm_substream *substream,
|
|
unsigned long mclk_rate;
|
|
|
|
msm8916_wcd = snd_soc_component_get_drvdata(component);
|
|
- snd_soc_component_update_bits(component, LPASS_CDC_CLK_MCLK_CTL,
|
|
- MCLK_CTL_MCLK_EN_MASK,
|
|
- MCLK_CTL_MCLK_EN_ENABLE);
|
|
- snd_soc_component_update_bits(component, LPASS_CDC_CLK_PDM_CTL,
|
|
- LPASS_CDC_CLK_PDM_CTL_PDM_CLK_SEL_MASK,
|
|
- LPASS_CDC_CLK_PDM_CTL_PDM_CLK_SEL_FB);
|
|
+ regmap_write_bits(msm8916_wcd->regmap, LPASS_CDC_CLK_MCLK_CTL,
|
|
+ MCLK_CTL_MCLK_EN_MASK,
|
|
+ MCLK_CTL_MCLK_EN_ENABLE);
|
|
+ regmap_write_bits(msm8916_wcd->regmap, LPASS_CDC_CLK_PDM_CTL,
|
|
+ LPASS_CDC_CLK_PDM_CTL_PDM_CLK_SEL_MASK,
|
|
+ LPASS_CDC_CLK_PDM_CTL_PDM_CLK_SEL_FB);
|
|
|
|
mclk_rate = clk_get_rate(msm8916_wcd->mclk);
|
|
switch (mclk_rate) {
|
|
case 12288000:
|
|
- snd_soc_component_update_bits(component, LPASS_CDC_TOP_CTL,
|
|
- TOP_CTL_DIG_MCLK_FREQ_MASK,
|
|
- TOP_CTL_DIG_MCLK_FREQ_F_12_288MHZ);
|
|
+ regmap_write_bits(msm8916_wcd->regmap, LPASS_CDC_TOP_CTL,
|
|
+ TOP_CTL_DIG_MCLK_FREQ_MASK,
|
|
+ TOP_CTL_DIG_MCLK_FREQ_F_12_288MHZ);
|
|
break;
|
|
case 9600000:
|
|
- snd_soc_component_update_bits(component, LPASS_CDC_TOP_CTL,
|
|
- TOP_CTL_DIG_MCLK_FREQ_MASK,
|
|
- TOP_CTL_DIG_MCLK_FREQ_F_9_6MHZ);
|
|
+ regmap_write_bits(msm8916_wcd->regmap, LPASS_CDC_TOP_CTL,
|
|
+ TOP_CTL_DIG_MCLK_FREQ_MASK,
|
|
+ TOP_CTL_DIG_MCLK_FREQ_F_9_6MHZ);
|
|
break;
|
|
default:
|
|
dev_err(component->dev, "Invalid mclk rate %ld\n", mclk_rate);
|
|
break;
|
|
}
|
|
+ msm8916_wcd_digital_force_sync_ctl(msm8916_wcd->regmap);
|
|
return 0;
|
|
}
|
|
|
|
@@ -1155,18 +1199,168 @@ static const struct snd_soc_component_driver msm8916_wcd_digital = {
|
|
.dapm_routes = msm8916_wcd_digital_audio_map,
|
|
.num_dapm_routes = ARRAY_SIZE(msm8916_wcd_digital_audio_map),
|
|
.idle_bias_on = 0,
|
|
- .use_pmdown_time = 1,
|
|
+ .use_pmdown_time = 0,
|
|
.endianness = 1,
|
|
};
|
|
|
|
+static const struct reg_default msm8916_wcd_digital_reg_defaults[] = {
|
|
+ { LPASS_CDC_CLK_RX_RESET_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_TX_RESET_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_DMIC_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_RX_I2S_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_TX_I2S_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_OTHR_RESET_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_TX_CLK_EN_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_OTHR_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_RX_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_MCLK_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_PDM_CTL, 0x00 },
|
|
+ { LPASS_CDC_CLK_SD_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX1_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX1_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX1_B3_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX1_B4_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX1_B5_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX1_B6_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX1_VOL_CTL_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX1_VOL_CTL_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX2_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX2_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX2_B3_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX2_B4_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX2_B5_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX2_B6_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX2_VOL_CTL_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX2_VOL_CTL_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX3_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX3_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX3_B3_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX3_B4_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX3_B5_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX3_B6_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX3_VOL_CTL_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_RX3_VOL_CTL_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_TOP_GAIN_UPDATE, 0x00 },
|
|
+ { LPASS_CDC_TOP_CTL, 0x00 },
|
|
+ { LPASS_CDC_DEBUG_DESER1_CTL, 0x00 },
|
|
+ { LPASS_CDC_DEBUG_DESER2_CTL, 0x00 },
|
|
+ { LPASS_CDC_DEBUG_B1_CTL_CFG, 0x00 },
|
|
+ { LPASS_CDC_DEBUG_B2_CTL_CFG, 0x00 },
|
|
+ { LPASS_CDC_DEBUG_B3_CTL_CFG, 0x00 },
|
|
+ { LPASS_CDC_IIR1_GAIN_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_GAIN_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_GAIN_B3_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_GAIN_B4_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_GAIN_B5_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_GAIN_B6_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_GAIN_B7_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_GAIN_B8_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_GAIN_TIMER_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_COEF_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR1_COEF_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_GAIN_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_GAIN_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_GAIN_B3_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_GAIN_B4_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_GAIN_B5_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_GAIN_B6_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_GAIN_B7_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_GAIN_B8_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_GAIN_TIMER_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_COEF_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_IIR2_COEF_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_RX1_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_RX1_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_RX1_B3_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_RX2_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_RX2_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_RX2_B3_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_RX3_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_RX3_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_TX_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_EQ1_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_EQ1_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_EQ1_B3_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_EQ1_B4_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_EQ2_B1_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_EQ2_B2_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_EQ2_B3_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_EQ2_B4_CTL, 0x00 },
|
|
+ { LPASS_CDC_CONN_TX_I2S_SD1_CTL, 0x00 },
|
|
+ { LPASS_CDC_TX1_VOL_CTL_TIMER, 0x00 },
|
|
+ { LPASS_CDC_TX1_VOL_CTL_GAIN, 0x00 },
|
|
+ { LPASS_CDC_TX1_VOL_CTL_CFG, 0x00 },
|
|
+ { LPASS_CDC_TX1_MUX_CTL, 0x00 },
|
|
+ { LPASS_CDC_TX1_CLK_FS_CTL, 0x00 },
|
|
+ { LPASS_CDC_TX1_DMIC_CTL, 0x00 },
|
|
+ { LPASS_CDC_TX2_VOL_CTL_TIMER, 0x00 },
|
|
+ { LPASS_CDC_TX2_VOL_CTL_GAIN, 0x00 },
|
|
+ { LPASS_CDC_TX2_VOL_CTL_CFG, 0x00 },
|
|
+ { LPASS_CDC_TX2_MUX_CTL, 0x00 },
|
|
+ { LPASS_CDC_TX2_CLK_FS_CTL, 0x00 },
|
|
+ { LPASS_CDC_TX2_DMIC_CTL, 0x00 },
|
|
+};
|
|
+
|
|
+static bool msm8916_wcd_digital_valid_reg(struct device *dev, unsigned int reg)
|
|
+{
|
|
+ switch (reg) {
|
|
+ case LPASS_CDC_CLK_RX_RESET_CTL ... LPASS_CDC_CLK_SD_CTL:
|
|
+ case LPASS_CDC_RX1_B1_CTL ... LPASS_CDC_RX1_VOL_CTL_B2_CTL:
|
|
+ case LPASS_CDC_RX2_B1_CTL ... LPASS_CDC_RX2_VOL_CTL_B2_CTL:
|
|
+ case LPASS_CDC_RX3_B1_CTL ... LPASS_CDC_TOP_CTL:
|
|
+ case LPASS_CDC_DEBUG_DESER1_CTL ... LPASS_CDC_DEBUG_B3_CTL_CFG:
|
|
+ case LPASS_CDC_IIR1_GAIN_B1_CTL ... LPASS_CDC_IIR1_COEF_B2_CTL:
|
|
+ case LPASS_CDC_IIR2_GAIN_B1_CTL ... LPASS_CDC_IIR2_COEF_B2_CTL:
|
|
+ case LPASS_CDC_CONN_RX1_B1_CTL ... LPASS_CDC_CONN_TX_B1_CTL:
|
|
+ case LPASS_CDC_CONN_EQ1_B1_CTL ... LPASS_CDC_CONN_TX_I2S_SD1_CTL:
|
|
+ case LPASS_CDC_TX1_VOL_CTL_TIMER ... LPASS_CDC_TX1_DMIC_CTL:
|
|
+ case LPASS_CDC_TX2_VOL_CTL_TIMER ... LPASS_CDC_TX2_DMIC_CTL:
|
|
+ return true;
|
|
+ default:
|
|
+ return false;
|
|
+ }
|
|
+}
|
|
+
|
|
static const struct regmap_config msm8916_codec_regmap_config = {
|
|
.reg_bits = 32,
|
|
.reg_stride = 4,
|
|
.val_bits = 32,
|
|
.max_register = LPASS_CDC_TX2_DMIC_CTL,
|
|
+ .readable_reg = msm8916_wcd_digital_valid_reg,
|
|
+ .writeable_reg = msm8916_wcd_digital_valid_reg,
|
|
+ .reg_defaults = msm8916_wcd_digital_reg_defaults,
|
|
+ .num_reg_defaults = ARRAY_SIZE(msm8916_wcd_digital_reg_defaults),
|
|
.cache_type = REGCACHE_FLAT,
|
|
};
|
|
|
|
+static void msm8916_wcd_digital_force_sync_ctl(struct regmap *map)
|
|
+{
|
|
+ unsigned int val;
|
|
+ size_t i;
|
|
+
|
|
+ for (i = 0; i < ARRAY_SIZE(msm8916_wcd_digital_reg_defaults); i++) {
|
|
+ unsigned int reg = msm8916_wcd_digital_reg_defaults[i].reg;
|
|
+
|
|
+ switch (reg) {
|
|
+ case LPASS_CDC_CLK_RX_RESET_CTL:
|
|
+ case LPASS_CDC_CLK_TX_RESET_B1_CTL:
|
|
+ case LPASS_CDC_CLK_OTHR_RESET_B1_CTL:
|
|
+ case LPASS_CDC_TOP_GAIN_UPDATE:
|
|
+ case LPASS_CDC_IIR1_COEF_B1_CTL:
|
|
+ case LPASS_CDC_IIR1_COEF_B2_CTL:
|
|
+ case LPASS_CDC_IIR2_COEF_B1_CTL:
|
|
+ case LPASS_CDC_IIR2_COEF_B2_CTL:
|
|
+ continue;
|
|
+ default:
|
|
+ if (regmap_read(map, reg, &val) == 0)
|
|
+ regmap_write_bits(map, reg, ~0U, val);
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+}
|
|
+
|
|
static int msm8916_wcd_digital_runtime_suspend(struct device *dev)
|
|
{
|
|
struct msm8916_wcd_digital_priv *priv = dev_get_drvdata(dev);
|
|
@@ -1195,7 +1389,11 @@ static int msm8916_wcd_digital_runtime_resume(struct device *dev)
|
|
}
|
|
|
|
regcache_cache_only(priv->regmap, false);
|
|
- return regcache_sync(priv->regmap);
|
|
+ ret = regcache_sync(priv->regmap);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+ msm8916_wcd_digital_force_sync_ctl(priv->regmap);
|
|
+ return 0;
|
|
}
|
|
|
|
static const struct dev_pm_ops msm8916_wcd_digital_pm_ops = {
|
|
@@ -1209,7 +1407,6 @@ static int msm8916_wcd_digital_probe(struct platform_device *pdev)
|
|
struct device *dev = &pdev->dev;
|
|
void __iomem *base;
|
|
struct regmap *digital_map;
|
|
- unsigned int reg, val;
|
|
int ret;
|
|
|
|
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
|
@@ -1244,8 +1441,17 @@ static int msm8916_wcd_digital_probe(struct platform_device *pdev)
|
|
goto err_clk;
|
|
}
|
|
|
|
- for (reg = 0; reg <= LPASS_CDC_TX2_DMIC_CTL; reg += 4)
|
|
- regmap_read(digital_map, reg, &val);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_CLK_RX_I2S_CTL, ~0U, 0x13);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_CLK_TX_I2S_CTL, ~0U, 0x13);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_CLK_OTHR_CTL, ~0U, 0x04);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_RX1_B5_CTL, ~0U, 0x68);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_RX2_B5_CTL, ~0U, 0x68);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_RX3_B5_CTL, ~0U, 0x68);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_TOP_CTL, ~0U, 0x01);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_IIR1_CTL, ~0U, 0x40);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_IIR2_CTL, ~0U, 0x40);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_TX1_CLK_FS_CTL, ~0U, 0x03);
|
|
+ regmap_write_bits(digital_map, LPASS_CDC_TX2_CLK_FS_CTL, ~0U, 0x03);
|
|
|
|
dev_set_drvdata(dev, priv);
|
|
|
|
diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c
|
|
index a5b0c48..08f6b28 100644
|
|
--- a/sound/soc/qcom/qdsp6/q6afe.c
|
|
+++ b/sound/soc/qcom/qdsp6/q6afe.c
|
|
@@ -373,6 +373,7 @@ struct q6afe {
|
|
wait_queue_head_t wait;
|
|
struct list_head port_list;
|
|
spinlock_t port_list_lock;
|
|
+ unsigned int digital_cdc_clk_freq;
|
|
};
|
|
|
|
struct afe_port_cmd_device_start {
|
|
@@ -1032,13 +1033,12 @@ static int q6afe_port_set_param(struct q6afe_port *port, void *data,
|
|
}
|
|
|
|
static int q6afe_set_param_v2(struct q6afe *afe, struct q6afe_port *port,
|
|
- void *data, int param_id, int module_id, int psize,
|
|
- int token)
|
|
+ u16 port_id, void *data, int param_id,
|
|
+ int module_id, int psize, int token)
|
|
{
|
|
struct afe_port_cmd_set_param_v2 *param;
|
|
struct afe_port_param_data_v2 *pdata;
|
|
struct apr_pkt *pkt;
|
|
- u16 port_id = port ? port->id : 0;
|
|
int ret, pkt_size;
|
|
void *p, *pl;
|
|
|
|
@@ -1083,8 +1083,8 @@ static int q6afe_set_param_v2(struct q6afe *afe, struct q6afe_port *port,
|
|
static int q6afe_port_set_param_v2(struct q6afe_port *port, void *data,
|
|
int param_id, int module_id, int psize)
|
|
{
|
|
- return q6afe_set_param_v2(port->afe, port, data, param_id, module_id,
|
|
- psize, port->token);
|
|
+ return q6afe_set_param_v2(port->afe, port, port->id, data, param_id,
|
|
+ module_id, psize, port->token);
|
|
}
|
|
|
|
static int q6afe_port_set_lpass_clock(struct q6afe_port *port,
|
|
@@ -1120,6 +1120,7 @@ int q6afe_set_lpass_clock(struct device *dev, int clk_id, int attri,
|
|
|
|
if (q6core_get_adsp_version() < Q6_ADSP_VERSION_2_7) {
|
|
struct afe_digital_clk_cfg dcfg = {0,};
|
|
+ int ret;
|
|
|
|
switch (clk_id) {
|
|
/*
|
|
@@ -1130,11 +1131,18 @@ int q6afe_set_lpass_clock(struct device *dev, int clk_id, int attri,
|
|
dcfg.i2s_cfg_minor_version = AFE_API_VERSION_I2S_CONFIG;
|
|
dcfg.clk_val = freq;
|
|
dcfg.clk_root = 5;
|
|
- return q6afe_set_param_v2(afe, NULL, &dcfg,
|
|
- AFE_PARAM_ID_INT_DIGITAL_CDC_CLK_CONFIG,
|
|
- AFE_MODULE_AUDIO_DEV_INTERFACE,
|
|
- sizeof(dcfg),
|
|
- AFE_CLK_TOKEN);
|
|
+ if (freq == 0)
|
|
+ afe->digital_cdc_clk_freq = 0;
|
|
+ ret = q6afe_set_param_v2(afe, NULL,
|
|
+ AFE_PORT_ID_PRIMARY_MI2S_RX,
|
|
+ &dcfg,
|
|
+ AFE_PARAM_ID_INT_DIGITAL_CDC_CLK_CONFIG,
|
|
+ AFE_MODULE_AUDIO_DEV_INTERFACE,
|
|
+ sizeof(dcfg),
|
|
+ AFE_CLK_TOKEN);
|
|
+ if (!ret && freq > 0)
|
|
+ afe->digital_cdc_clk_freq = freq;
|
|
+ return ret;
|
|
default:
|
|
break;
|
|
}
|
|
@@ -1254,6 +1262,27 @@ int q6afe_port_stop(struct q6afe_port *port)
|
|
dev_err(afe->dev, "AFE close failed %d\n", ret);
|
|
|
|
kfree(pkt);
|
|
+ if (!ret && port_id == AFE_PORT_ID_PRIMARY_MI2S_RX &&
|
|
+ q6core_get_adsp_version() < Q6_ADSP_VERSION_2_7 &&
|
|
+ afe->digital_cdc_clk_freq > 0) {
|
|
+ struct afe_digital_clk_cfg dcfg = {0,};
|
|
+ int clk_ret;
|
|
+
|
|
+ dcfg.i2s_cfg_minor_version = AFE_API_VERSION_I2S_CONFIG;
|
|
+ dcfg.clk_val = afe->digital_cdc_clk_freq;
|
|
+ dcfg.clk_root = 5;
|
|
+ clk_ret = q6afe_set_param_v2(afe, NULL,
|
|
+ AFE_PORT_ID_PRIMARY_MI2S_RX,
|
|
+ &dcfg,
|
|
+ AFE_PARAM_ID_INT_DIGITAL_CDC_CLK_CONFIG,
|
|
+ AFE_MODULE_AUDIO_DEV_INTERFACE,
|
|
+ sizeof(dcfg),
|
|
+ AFE_CLK_TOKEN);
|
|
+ if (clk_ret)
|
|
+ dev_warn(afe->dev,
|
|
+ "Failed to retain digital codec clk after PRI_MI2S_RX stop (%d)\n",
|
|
+ clk_ret);
|
|
+ }
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(q6afe_port_stop);
|
|
diff --git a/sound/soc/qcom/qdsp6/q6core.c b/sound/soc/qcom/qdsp6/q6core.c
|
|
index 855ab4f..7200330 100644
|
|
--- a/sound/soc/qcom/qdsp6/q6core.c
|
|
+++ b/sound/soc/qcom/qdsp6/q6core.c
|
|
@@ -275,6 +275,18 @@ static bool __q6core_is_adsp_ready(struct q6core *core)
|
|
return false;
|
|
}
|
|
|
|
+static void q6core_query_versions_locked(struct q6core *core)
|
|
+{
|
|
+ if (core->is_version_requested)
|
|
+ return;
|
|
+
|
|
+ if (q6core_get_fwk_versions(core) || !core->fwk_version_supported)
|
|
+ q6core_get_svc_versions(core);
|
|
+
|
|
+ if (core->adsp_version != Q6_ADSP_VERSION_UNKNOWN)
|
|
+ core->is_version_requested = true;
|
|
+}
|
|
+
|
|
/**
|
|
* q6core_get_svc_api_info() - Get version number of a service.
|
|
*
|
|
@@ -292,11 +304,7 @@ int q6core_get_svc_api_info(int svc_id, struct q6core_svc_api_info *ainfo)
|
|
return 0;
|
|
|
|
mutex_lock(&g_core->lock);
|
|
- if (!g_core->is_version_requested) {
|
|
- if (q6core_get_fwk_versions(g_core) == -ENOTSUPP)
|
|
- q6core_get_svc_versions(g_core);
|
|
- g_core->is_version_requested = true;
|
|
- }
|
|
+ q6core_query_versions_locked(g_core);
|
|
|
|
if (g_core->fwk_version_supported) {
|
|
for (i = 0; i < g_core->fwk_version->num_services; i++) {
|
|
@@ -345,10 +353,6 @@ enum q6core_version q6core_get_adsp_version(void)
|
|
return Q6_ADSP_VERSION_UNKNOWN;
|
|
|
|
mutex_lock(&g_core->lock);
|
|
- if (!g_core->is_version_requested) {
|
|
- if (q6core_get_fwk_versions(g_core) == -ENOTSUPP)
|
|
- q6core_get_svc_versions(g_core);
|
|
- g_core->is_version_requested = true;
|
|
- }
|
|
+ q6core_query_versions_locked(g_core);
|
|
ret = g_core->adsp_version;
|
|
mutex_unlock(&g_core->lock);
|