Prechádzať zdrojové kódy

asoc: optimize the logic of aux/ear gain pa set

Optimize the logic of aux/ear pa gain set.

Change-Id: I2a13d1790173b60e4de808ab27a0128833c47221
Signed-off-by: Yuhui Zhao <[email protected]>
Yuhui Zhao 1 rok pred
rodič
commit
c10a5615b3
1 zmenil súbory, kde vykonal 129 pridanie a 61 odobranie
  1. 129 61
      asoc/codecs/wcd9378/wcd9378.c

+ 129 - 61
asoc/codecs/wcd9378/wcd9378.c

@@ -175,8 +175,6 @@ enum {
 	ADC_MODE_LP,
 };
 
-static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(ear_pa_gain, 600, -1800);
-static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(aux_pa_gain, 600, -600);
 static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(analog_gain, 0, 3000);
 
 static int wcd9378_reset(struct device *dev);
@@ -2787,6 +2785,96 @@ static int wcd9378_hph_get_gain(struct snd_kcontrol *kcontrol,
 	return 0;
 }
 
+static int wcd9378_ear_pa_gain_get(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+				snd_soc_kcontrol_component(kcontrol);
+	int ear_gain = 0;
+
+	if (component == NULL)
+		return -EINVAL;
+
+	ear_gain =
+		snd_soc_component_read(component, WCD9378_ANA_EAR_COMPANDER_CTL) &
+				WCD9378_ANA_EAR_COMPANDER_CTL_EAR_GAIN_MASK;
+
+	ucontrol->value.enumerated.item[0] = ear_gain;
+	dev_dbg(component->dev, "%s: get ear_gain val: 0x%x\n",
+			__func__, ear_gain);
+	return 0;
+}
+
+static int wcd9378_ear_pa_gain_put(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+				snd_soc_kcontrol_component(kcontrol);
+	int ear_gain = 0;
+
+	if (component == NULL)
+		return -EINVAL;
+
+	if (ucontrol->value.integer.value[0] < 0 ||
+		ucontrol->value.integer.value[0] > 0x10) {
+		dev_err(component->dev, "%s: Unsupported gain val %ld\n",
+			 __func__, ucontrol->value.integer.value[0]);
+		return -EINVAL;
+	}
+
+	ear_gain = ucontrol->value.integer.value[0];
+	snd_soc_component_update_bits(component, WCD9378_ANA_EAR_COMPANDER_CTL,
+				WCD9378_ANA_EAR_COMPANDER_CTL_EAR_GAIN_MASK,
+				ear_gain);
+	dev_dbg(component->dev, "%s: set ear_gain val: 0x%x\n",
+			__func__, ear_gain);
+	return 0;
+}
+
+static int wcd9378_aux_pa_gain_get(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+				snd_soc_kcontrol_component(kcontrol);
+	int aux_gain = 0;
+
+	if (component == NULL)
+		return -EINVAL;
+
+	aux_gain = snd_soc_component_read(component, WCD9378_AUX_INT_MISC) &
+			WCD9378_AUX_INT_MISC_PA_GAIN_MASK;
+
+	ucontrol->value.enumerated.item[0] = aux_gain;
+	dev_dbg(component->dev, "%s: get aux_gain val: 0x%x\n",
+			__func__, aux_gain);
+	return 0;
+}
+
+static int wcd9378_aux_pa_gain_put(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+				snd_soc_kcontrol_component(kcontrol);
+	int aux_gain = 0;
+
+	if (component == NULL)
+		return -EINVAL;
+
+	if (ucontrol->value.integer.value[0] < 0 ||
+		ucontrol->value.integer.value[0] > 0x8) {
+		dev_err(component->dev, "%s: Unsupported gain val %ld\n",
+			__func__, ucontrol->value.integer.value[0]);
+		return -EINVAL;
+	}
+
+	aux_gain = ucontrol->value.integer.value[0];
+	snd_soc_component_update_bits(component, WCD9378_AUX_INT_MISC,
+				WCD9378_AUX_INT_MISC_PA_GAIN_MASK,
+				aux_gain);
+	dev_dbg(component->dev, "%s: set aux_gain val: 0x%x\n",
+			 __func__, aux_gain);
+	return 0;
+}
 
 static int wcd9378_rx2_mode_put(struct snd_kcontrol *kcontrol,
 				   struct snd_ctl_elem_value *ucontrol)
@@ -2850,46 +2938,6 @@ int wcd9378_codec_get_dev_num(struct snd_soc_component *component)
 }
 EXPORT_SYMBOL_GPL(wcd9378_codec_get_dev_num);
 
-static int wcd9378_ear_pa_put_gain(struct snd_kcontrol *kcontrol,
-				   struct snd_ctl_elem_value *ucontrol)
-{
-	struct snd_soc_component *component =
-				snd_soc_kcontrol_component(kcontrol);
-	struct wcd9378_priv *wcd9378 =
-				snd_soc_component_get_drvdata(component);
-
-	if (wcd9378->comp1_enable) {
-		dev_err(component->dev, "Can not set EAR PA Gain, compander1 is enabled\n");
-		return -EINVAL;
-	}
-
-	snd_soc_component_update_bits(component, WCD9378_AUX_INT_MISC,
-				      WCD9378_ANA_EAR_COMPANDER_CTL_EAR_GAIN_MASK,
-				      ucontrol->value.integer.value[0]);
-
-	return 1;
-}
-
-static int wcd9378_aux_pa_put_gain(struct snd_kcontrol *kcontrol,
-				   struct snd_ctl_elem_value *ucontrol)
-{
-	struct snd_soc_component *component =
-				snd_soc_kcontrol_component(kcontrol);
-	struct wcd9378_priv *wcd9378 =
-				snd_soc_component_get_drvdata(component);
-
-	if (wcd9378->comp1_enable) {
-		dev_err(component->dev, "Can not set EAR PA Gain, compander1 is enabled\n");
-		return -EINVAL;
-	}
-
-	snd_soc_component_update_bits(component, WCD9378_ANA_EAR_COMPANDER_CTL,
-				      WCD9378_AUX_INT_MISC_PA_GAIN_MASK,
-				      ucontrol->value.integer.value[0]);
-
-	return 1;
-}
-
 static int wcd9378_get_compander(struct snd_kcontrol *kcontrol,
 				 struct snd_ctl_elem_value *ucontrol)
 {
@@ -2990,17 +3038,6 @@ static int wcd9378_codec_enable_vdd_buck(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
-const char * const tx_master_ch_text[] = {
-	"ZERO", "SWRM_TX1_CH1", "SWRM_TX1_CH2", "SWRM_TX1_CH3", "SWRM_TX1_CH4",
-	"SWRM_TX2_CH1", "SWRM_TX2_CH2", "SWRM_TX2_CH3", "SWRM_TX2_CH4",
-	"SWRM_TX3_CH1", "SWRM_TX3_CH2", "SWRM_TX3_CH3", "SWRM_TX3_CH4",
-	"SWRM_PCM_IN",
-};
-
-const struct soc_enum tx_master_ch_enum =
-	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_master_ch_text),
-					tx_master_ch_text);
-
 static void wcd9378_tx_get_slave_ch_type_idx(const char *wname, int *ch_idx)
 {
 	u8 ch_type = 0;
@@ -3166,6 +3203,38 @@ static const struct soc_enum rx_hph_mode_mux_enum =
 	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
 			    rx_hph_mode_mux_text);
 
+
+static const char * const ear_pa_gain_text[] = {
+	"GAIN_6DB", "GAIN_4P5DB", "GAIN_3DB", "GAIN_1P5DB", "GAIN_0DB",
+	"GAIN_M1P5DB", "GAIN_M3DB", "GAIN_M4P5DB", "GAIN_M6DB",
+	"GAIN_M7P5DB", "GAIN_M9DB", "GAIN_M10P5DB", "GAIN_M12DB",
+	"GAIN_M13P5DB", "GAIN_M15DB", "GAIN_M16P5DB", "GAIN_M18DB",
+};
+
+static const struct soc_enum ear_pa_gain_enum =
+	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ear_pa_gain_text),
+			    ear_pa_gain_text);
+
+static const char * const aux_pa_gain_text[] = {
+	"GAIN_6DB", "GAIN_4P5DB", "GAIN_3DB", "GAIN_1P5DB", "GAIN_0DB",
+	"GAIN_M1P5DB", "GAIN_M3DB", "GAIN_M4P5DB", "GAIN_M6DB",
+};
+
+static const struct soc_enum aux_pa_gain_enum =
+	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aux_pa_gain_text),
+			    aux_pa_gain_text);
+
+const char * const tx_master_ch_text[] = {
+	"ZERO", "SWRM_TX1_CH1", "SWRM_TX1_CH2", "SWRM_TX1_CH3", "SWRM_TX1_CH4",
+	"SWRM_TX2_CH1", "SWRM_TX2_CH2", "SWRM_TX2_CH3", "SWRM_TX2_CH4",
+	"SWRM_TX3_CH1", "SWRM_TX3_CH2", "SWRM_TX3_CH3", "SWRM_TX3_CH4",
+	"SWRM_PCM_IN",
+};
+
+const struct soc_enum tx_master_ch_enum =
+	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_master_ch_text),
+					tx_master_ch_text);
+
 static const struct snd_kcontrol_new wcd9378_snd_controls[] = {
 	SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
 		wcd9378_get_compander, wcd9378_set_compander),
@@ -3189,15 +3258,15 @@ static const struct snd_kcontrol_new wcd9378_snd_controls[] = {
 		     wcd9378_tx_mode_get, wcd9378_tx_mode_put),
 
 	SOC_ENUM_EXT("RX2 Mode", rx2_mode_enum,
-		       NULL, wcd9378_rx2_mode_put),
+			NULL, wcd9378_rx2_mode_put),
 	SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
-		     wcd9378_rx_hph_mode_get, wcd9378_rx_hph_mode_put),
+			wcd9378_rx_hph_mode_get, wcd9378_rx_hph_mode_put),
 	SOC_SINGLE_EXT("HPH Volume", SND_SOC_NOPM, 0, 0x14, 0,
-		       wcd9378_hph_get_gain, wcd9378_hph_put_gain),
-	WCD9378_EAR_PA_GAIN_TLV("EAR_PA Volume", WCD9378_ANA_EAR_COMPANDER_CTL,
-		       2, 0x10, 0, ear_pa_gain),
-	WCD9378_AUX_PA_GAIN_TLV("AUX_PA Volume", WCD9378_AUX_INT_MISC,
-		       0, 0x8, 0, aux_pa_gain),
+			wcd9378_hph_get_gain, wcd9378_hph_put_gain),
+	SOC_ENUM_EXT("EAR_PA Gain", ear_pa_gain_enum,
+			wcd9378_ear_pa_gain_get, wcd9378_ear_pa_gain_put),
+	SOC_ENUM_EXT("AUX_PA Gain", aux_pa_gain_enum,
+			wcd9378_aux_pa_gain_get, wcd9378_aux_pa_gain_put),
 
 	SOC_SINGLE_TLV("ADC1 Volume", WCD9378_ANA_TX_CH1, 0, 20, 0,
 			analog_gain),
@@ -3228,7 +3297,6 @@ static const struct snd_kcontrol_new wcd9378_snd_controls[] = {
 			wcd9378_tx_master_ch_get, wcd9378_tx_master_ch_put),
 };
 
-
 static const struct snd_kcontrol_new amic1_switch[] = {
 	SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
 };