[U-Boot] [PATCH 12/30] dm: sound: max98095: Split out interface setup code

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


With driver model we want to do a minimal probe when the device is probed
and then set up the codec interface later when a sound is actully played.

Split this setup code out into its own function to help with this.

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

 drivers/sound/max98095.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/sound/max98095.c b/drivers/sound/max98095.c
index 6edf3736d79..51556c07f5e 100644
--- a/drivers/sound/max98095.c
+++ b/drivers/sound/max98095.c
@@ -384,12 +384,14 @@ static int max98095_reset(struct max98095_priv *priv)
  *
  * @returns -1 for error  and 0 Success.
  */
-static int max98095_device_init(struct max98095_priv *priv,
-				enum en_max_audio_interface aif_id)
+static int max98095_device_init(struct max98095_priv *priv)
 {
 	unsigned char id;
 	int error = 0;
 
+	/* Enable codec clock */
+	set_xclkout();
+
 	/* reset the codec, the DSP core, and disable all interrupts */
 	error = max98095_reset(priv);
 	if (error != 0) {
@@ -406,11 +408,19 @@ static int max98095_device_init(struct max98095_priv *priv,
 	if (error < 0) {
 		debug("%s: Failure reading hardware revision: %d\n",
 		      __func__, id);
-		goto err_access;
+		return error;
 	}
 	debug("%s: Hardware revision: %c\n", __func__, (id - 0x40) + 'A');
 
-	error |= max98095_i2c_write(priv, M98095_097_PWR_SYS, M98095_PWRSV);
+	return 0;
+}
+
+static int max98095_setup_interface(struct max98095_priv *priv,
+				    enum en_max_audio_interface aif_id)
+{
+	int error;
+
+	error = max98095_i2c_write(priv, M98095_097_PWR_SYS, M98095_PWRSV);
 
 	/*
 	 * initialize registers to hardware default configuring audio
@@ -463,7 +473,6 @@ static int max98095_device_init(struct max98095_priv *priv,
 	else
 		error |= max98095_i2c_write(priv, M98095_096_PWR_DAC_CK, 0x07);
 
-err_access:
 	if (error < 0)
 		return -1;
 
@@ -477,13 +486,7 @@ static int max98095_do_init(struct sound_codec_info *pcodec_info,
 {
 	int ret = 0;
 
-	/* Enable codec clock */
-	set_xclkout();
-
-	/* shift the device address by 1 for 7 bit addressing */
-	g_max98095_i2c_dev_addr = pcodec_info->i2c_dev_addr >> 1;
-
-	ret = max98095_device_init(&g_max98095_info, aif_id);
+	ret = max98095_setup_interface(&g_max98095_info, aif_id);
 	if (ret < 0) {
 		debug("%s: max98095 codec chip init failed\n", __func__);
 		return ret;
@@ -569,6 +572,15 @@ int max98095_init(const void *blob, enum en_max_audio_interface aif_id,
 	}
 
 	i2c_set_bus_num(pcodec_info->i2c_bus);
+
+	/* shift the device address by 1 for 7 bit addressing */
+	g_max98095_i2c_dev_addr = pcodec_info->i2c_dev_addr >> 1;
+	ret = max98095_device_init(&g_max98095_info);
+	if (ret < 0) {
+		debug("%s: max98095 codec chip init failed\n", __func__);
+		return ret;
+	}
+
 	ret = max98095_do_init(pcodec_info, aif_id, sampling_rate, mclk_freq,
 			       bits_per_sample);
 	i2c_set_bus_num(old_bus);
-- 
2.20.0.rc1.387.gf8505762e3-goog



More information about the U-Boot mailing list