[U-Boot] [PATCH 26/30] dm: sound: Start i2c IDs from 0

Simon Glass sjg at chromium.org
Mon Dec 3 11:37:42 UTC 2018


The current ID enums start from 1 but there does not seem to be any reason
that they cannot start with 0. Adjust the code to avoid the +1 in
codec_init() and elsewhere.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/sound/max98095.h  |  2 +-
 drivers/sound/sound-i2s.c |  6 ++----
 drivers/sound/wm8994.c    | 23 ++++++++++++-----------
 drivers/sound/wm8994.h    |  2 +-
 4 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/drivers/sound/max98095.h b/drivers/sound/max98095.h
index 44b1e3a97b4..13ae177a86b 100644
--- a/drivers/sound/max98095.h
+++ b/drivers/sound/max98095.h
@@ -13,7 +13,7 @@
 
 /*  Available audio interface ports in wm8994 codec */
 enum en_max_audio_interface {
-	AIF1 = 1,
+	AIF1,
 	AIF2,
 };
 
diff --git a/drivers/sound/sound-i2s.c b/drivers/sound/sound-i2s.c
index ed130750b2e..a2fc78154f1 100644
--- a/drivers/sound/sound-i2s.c
+++ b/drivers/sound/sound-i2s.c
@@ -120,13 +120,11 @@ static int codec_init(const void *blob, struct i2s_uc_priv *pi2s_tx)
 	debug("device = %s\n", codectype);
 	if (!strcmp(codectype, "wm8994")) {
 		/* Check the codec type and initialise the same */
-		ret = wm8994_init(blob, pi2s_tx->id + 1,
-				  pi2s_tx->samplingrate,
+		ret = wm8994_init(blob, pi2s_tx->id, pi2s_tx->samplingrate,
 				  (pi2s_tx->samplingrate * (pi2s_tx->rfs)),
 				  pi2s_tx->bitspersample, pi2s_tx->channels);
 	} else if (!strcmp(codectype, "max98095")) {
-		ret = max98095_init(blob, pi2s_tx->id + 1,
-				    pi2s_tx->samplingrate,
+		ret = max98095_init(blob, pi2s_tx->id, pi2s_tx->samplingrate,
 				    (pi2s_tx->samplingrate * (pi2s_tx->rfs)),
 				    pi2s_tx->bitspersample);
 	} else {
diff --git a/drivers/sound/wm8994.c b/drivers/sound/wm8994.c
index 1714f430f39..b8c3ffb67eb 100644
--- a/drivers/sound/wm8994.c
+++ b/drivers/sound/wm8994.c
@@ -285,7 +285,6 @@ static int wm8994_hw_params(struct wm8994_priv *priv, int aif_id,
 	int aif1 = 0;
 	int aif2 = 0;
 	int rate_val = 0;
-	int id = aif_id - 1;
 	int i, cur_val, best_val, bclk_rate, best;
 	unsigned short reg_data;
 	int ret = 0;
@@ -343,10 +342,11 @@ static int wm8994_hw_params(struct wm8994_priv *priv, int aif_id,
 
 	/* AIFCLK/fs ratio; look for a close match in either direction */
 	best = 0;
-	best_val = abs((fs_ratios[0] * sampling_rate) - priv->aifclk[id]);
+	best_val = abs((fs_ratios[0] * sampling_rate) - priv->aifclk[aif_id]);
 
 	for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
-		cur_val = abs(fs_ratios[i] * sampling_rate - priv->aifclk[id]);
+		cur_val = abs(fs_ratios[i] * sampling_rate -
+			      priv->aifclk[aif_id]);
 		if (cur_val >= best_val)
 			continue;
 		best = i;
@@ -363,7 +363,8 @@ static int wm8994_hw_params(struct wm8994_priv *priv, int aif_id,
 	 */
 	best = 0;
 	for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
-		cur_val = (priv->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
+		cur_val = (priv->aifclk[aif_id] * 10 / bclk_divs[i]) -
+				bclk_rate;
 		if (cur_val < 0) /* BCLK table is sorted */
 			break;
 		best = i;
@@ -375,7 +376,7 @@ static int wm8994_hw_params(struct wm8994_priv *priv, int aif_id,
 		return -1;
 	}
 
-	bclk_rate = priv->aifclk[id] * 10 / bclk_divs[best];
+	bclk_rate = priv->aifclk[aif_id] * 10 / bclk_divs[best];
 	bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
 
 	if (wm8994_i2c_read(priv, aif1_reg, &reg_data) != 0) {
@@ -386,7 +387,7 @@ static int wm8994_hw_params(struct wm8994_priv *priv, int aif_id,
 	if ((channels == 1) && ((reg_data & 0x18) == 0x18))
 		aif2 |= WM8994_AIF1_MONO;
 
-	if (priv->aifclk[id] == 0) {
+	if (priv->aifclk[aif_id] == 0) {
 		debug("%s:Audio interface clock not set\n", __func__);
 		return -1;
 	}
@@ -424,12 +425,12 @@ static int configure_aif_clock(struct wm8994_priv *priv, int aif)
 	int ret;
 
 	/* AIF(1/0) register adress offset calculated */
-	if (aif-1)
+	if (aif)
 		offset = 4;
 	else
 		offset = 0;
 
-	switch (priv->sysclk[aif - 1]) {
+	switch (priv->sysclk[aif]) {
 	case WM8994_SYSCLK_MCLK1:
 		reg1 |= SEL_MCLK1;
 		rate = priv->mclk[0];
@@ -452,7 +453,7 @@ static int configure_aif_clock(struct wm8994_priv *priv, int aif)
 
 	default:
 		debug("%s: Invalid input clock selection [%d]\n",
-		      __func__, priv->sysclk[aif - 1]);
+		      __func__, priv->sysclk[aif]);
 		return -1;
 	}
 
@@ -462,7 +463,7 @@ static int configure_aif_clock(struct wm8994_priv *priv, int aif)
 		reg1 |= WM8994_AIF1CLK_DIV;
 	}
 
-	priv->aifclk[aif - 1] = rate;
+	priv->aifclk[aif] = rate;
 
 	ret = wm8994_bic_or(priv, WM8994_AIF1_CLOCKING_1 + offset,
 			    WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
@@ -502,7 +503,7 @@ static int wm8994_set_sysclk(struct wm8994_priv *priv, int aif_id, int clk_id,
 	int i;
 	int ret = 0;
 
-	priv->sysclk[aif_id - 1] = clk_id;
+	priv->sysclk[aif_id] = clk_id;
 
 	switch (clk_id) {
 	case WM8994_SYSCLK_MCLK1:
diff --git a/drivers/sound/wm8994.h b/drivers/sound/wm8994.h
index ef2878f87ca..e36e6269f00 100644
--- a/drivers/sound/wm8994.h
+++ b/drivers/sound/wm8994.h
@@ -15,7 +15,7 @@
 
 /*  Avilable audi interface ports in wm8994 codec */
 enum en_audio_interface {
-	 WM8994_AIF1 = 1,
+	 WM8994_AIF1,
 	 WM8994_AIF2,
 	 WM8994_AIF3
 };
-- 
2.20.0.rc1.387.gf8505762e3-goog



More information about the U-Boot mailing list