diff mbox series

[07/14] Remove the control of output format

Message ID 20230106091543.2440-8-kiseok.jo@irondevice.com (mailing list archive)
State New, archived
Headers show
Series ASoC: Add a driver the Iron Device SMA1303 AMP | expand

Commit Message

Kiseok Jo Jan. 6, 2023, 9:15 a.m. UTC
Remove output format like I2S, left justifed.
And then it add in hw_params.

Signed-off-by: Kiseok Jo <kiseok.jo@irondevice.com>
Reported-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/codecs/sma1303.c | 141 +++++++++++++------------------------
 1 file changed, 48 insertions(+), 93 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/codecs/sma1303.c b/sound/soc/codecs/sma1303.c
index 42352fa6de56..1199302af01d 100644
--- a/sound/soc/codecs/sma1303.c
+++ b/sound/soc/codecs/sma1303.c
@@ -432,71 +432,6 @@  static int sma1303_postscaler_config_put(struct snd_kcontrol *kcontrol,
 			SMA1303_90_POSTSCALER, SMA1303_BYP_POST_MASK, val);
 }
 
-static const char * const sma1303_o_format_text[] = {
-	"LJ", "I2S", "TDM"};
-
-static const struct soc_enum sma1303_o_format_enum =
-SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1303_o_format_text), sma1303_o_format_text);
-
-static int sma1303_o_format_get(struct snd_kcontrol *kcontrol,
-				struct snd_ctl_elem_value *ucontrol)
-{
-	struct snd_soc_component *component =
-		snd_soc_kcontrol_component(kcontrol);
-	struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
-	int val, data, ret;
-
-	ret = sma1303_regmap_read(sma1303, SMA1303_A4_TOP_MAN3, &data);
-	val = data & SMA1303_O_FORMAT_MASK;
-	switch (val) {
-	case SMA1303_O_FMT_LJ:
-		ucontrol->value.integer.value[0] = 0;
-		break;
-	case SMA1303_O_FMT_I2S:
-		ucontrol->value.integer.value[0] = 1;
-		break;
-	case SMA1303_O_FMT_TDM:
-		ucontrol->value.integer.value[0] = 2;
-		break;
-	default:
-		dev_err(component->dev,
-			"Invalid value, register: %x\n",
-				SMA1303_A4_TOP_MAN3);
-		return -EINVAL;
-	}
-
-	return ret;
-}
-static int sma1303_o_format_put(struct snd_kcontrol *kcontrol,
-				struct snd_ctl_elem_value *ucontrol)
-{
-	struct snd_soc_component *component =
-		snd_soc_kcontrol_component(kcontrol);
-	struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
-	int sel = (int)ucontrol->value.integer.value[0];
-	int val;
-
-	switch (sel) {
-	case 0:
-		val = SMA1303_O_FMT_LJ;
-		break;
-	case 1:
-		val = SMA1303_O_FMT_I2S;
-		break;
-	case 2:
-		val = SMA1303_O_FMT_TDM;
-		break;
-	default:
-		dev_err(component->dev,
-			"Invalid value, register: %x\n",
-				SMA1303_A4_TOP_MAN3);
-		return -EINVAL;
-	}
-
-	return sma1303_regmap_update_bits(sma1303,
-			SMA1303_A4_TOP_MAN3, SMA1303_O_FORMAT_MASK, val);
-}
-
 static const char * const sma1303_aif_in_source_text[] = {
 	"Mono", "Left", "Right"};
 static const char * const sma1303_aif_out_source_text[] = {
@@ -815,8 +750,6 @@  SND_SOC_BYTES_EXT("Postscaler Set", 1,
 		postscaler_get, postscaler_put),
 SOC_ENUM_EXT("Postscaler Config", sma1303_postscaler_config_enum,
 	sma1303_postscaler_config_get, sma1303_postscaler_config_put),
-SOC_ENUM_EXT("Output Format", sma1303_o_format_enum,
-	sma1303_o_format_get, sma1303_o_format_put),
 };
 
 static const struct snd_soc_dapm_widget sma1303_dapm_widgets[] = {
@@ -930,7 +863,6 @@  static int sma1303_dai_hw_params_amp(struct snd_pcm_substream *substream,
 {
 	struct snd_soc_component *component = dai->component;
 	struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
-	unsigned int input_format = 0;
 	unsigned int bclk = 0;
 	int ret = 0;
 
@@ -1041,35 +973,61 @@  static int sma1303_dai_hw_params_amp(struct snd_pcm_substream *substream,
 		}
 	}
 
-	switch (params_width(params)) {
-	case 16:
-		switch (sma1303->format) {
-		case SND_SOC_DAIFMT_I2S:
-			input_format |= SMA1303_STANDARD_I2S;
-			break;
-		case SND_SOC_DAIFMT_LEFT_J:
-			input_format |= SMA1303_LJ;
+	switch (sma1303->format) {
+	case SND_SOC_DAIFMT_I2S:
+		ret += sma1303_regmap_update_bits(sma1303,
+				SMA1303_01_INPUT1_CTRL1,
+				SMA1303_I2S_MODE_MASK,
+				SMA1303_STANDARD_I2S);
+		ret += sma1303_regmap_update_bits(sma1303,
+				SMA1303_A4_TOP_MAN3,
+				SMA1303_O_FORMAT_MASK,
+				SMA1303_O_FMT_I2S);
+		break;
+	case SND_SOC_DAIFMT_LEFT_J:
+		ret += sma1303_regmap_update_bits(sma1303,
+				SMA1303_01_INPUT1_CTRL1,
+				SMA1303_I2S_MODE_MASK,
+				SMA1303_LJ);
+		ret += sma1303_regmap_update_bits(sma1303,
+				SMA1303_A4_TOP_MAN3,
+				SMA1303_O_FORMAT_MASK,
+				SMA1303_O_FMT_LJ);
+		break;
+	case SND_SOC_DAIFMT_RIGHT_J:
+		switch (params_width(params)) {
+		case 16:
+			ret += sma1303_regmap_update_bits(sma1303,
+					SMA1303_01_INPUT1_CTRL1,
+					SMA1303_I2S_MODE_MASK,
+					SMA1303_RJ_16BIT);
 			break;
-		case SND_SOC_DAIFMT_RIGHT_J:
-			input_format |= SMA1303_RJ_16BIT;
+		case 24:
+		case 32:
+			ret += sma1303_regmap_update_bits(sma1303,
+					SMA1303_01_INPUT1_CTRL1,
+					SMA1303_I2S_MODE_MASK,
+					SMA1303_RJ_24BIT);
 			break;
 		}
 		break;
+	case SND_SOC_DAIFMT_DSP_A:
+		ret += sma1303_regmap_update_bits(sma1303,
+				SMA1303_01_INPUT1_CTRL1,
+				SMA1303_I2S_MODE_MASK,
+				SMA1303_STANDARD_I2S);
+		ret += sma1303_regmap_update_bits(sma1303,
+				SMA1303_A4_TOP_MAN3,
+				SMA1303_O_FORMAT_MASK,
+				SMA1303_O_FMT_TDM);
+		break;
+	}
+
+	switch (params_width(params)) {
+	case 16:
 	case 24:
 	case 32:
-		switch (sma1303->format) {
-		case SND_SOC_DAIFMT_I2S:
-			input_format |= SMA1303_STANDARD_I2S;
-			break;
-		case SND_SOC_DAIFMT_LEFT_J:
-			input_format |= SMA1303_LJ;
-			break;
-		case SND_SOC_DAIFMT_RIGHT_J:
-			input_format |= SMA1303_RJ_24BIT;
-			break;
-		}
 		break;
-
 	default:
 		dev_err(component->dev,
 			"%s not support data bit : %d\n", __func__,
@@ -1077,9 +1035,6 @@  static int sma1303_dai_hw_params_amp(struct snd_pcm_substream *substream,
 		return -EINVAL;
 	}
 
-	ret += sma1303_regmap_update_bits(sma1303,
-			SMA1303_01_INPUT1_CTRL1,
-			SMA1303_I2S_MODE_MASK, input_format);
 	return ret;
 }