You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/09/05 05:33:15 UTC

[nuttx] 02/11: audio/cs4344: Set master clock when resetting the device

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 9357d70c2520bc5aaa0f469874f61fb4be4a81b9
Author: Tiago Medicci Serrano <ti...@espressif.com>
AuthorDate: Wed Aug 30 14:14:27 2023 -0300

    audio/cs4344: Set master clock when resetting the device
    
    Whevenever the bit rate is going to be set, it's necessary to first
    set the master clock if the underlying device supports it. If it
    fails, just return the error code.
---
 drivers/audio/cs4344.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/audio/cs4344.c b/drivers/audio/cs4344.c
index e5ad55e85c..cfdc37c370 100644
--- a/drivers/audio/cs4344.c
+++ b/drivers/audio/cs4344.c
@@ -126,7 +126,7 @@ static void *cs4344_workerthread(pthread_addr_t pvarg);
 
 /* Initialization */
 
-static void cs4344_reset(FAR struct cs4344_dev_s *priv);
+static int cs4344_reset(FAR struct cs4344_dev_s *priv);
 
 /****************************************************************************
  * Private Data
@@ -1411,12 +1411,14 @@ static void *cs4344_workerthread(pthread_addr_t pvarg)
  *   priv - A reference to the driver state structure
  *
  * Returned Value:
- *   None
+ *   Returns OK or a negated errno value on failure.
  *
  ****************************************************************************/
 
-static void cs4344_reset(FAR struct cs4344_dev_s *priv)
+static int cs4344_reset(FAR struct cs4344_dev_s *priv)
 {
+  int ret;
+
   /* Put audio output back to its initial configuration */
 
   priv->samprate   = CS4344_DEFAULT_SAMPRATE;
@@ -1424,9 +1426,26 @@ static void cs4344_reset(FAR struct cs4344_dev_s *priv)
   priv->bpsamp     = CS4344_DEFAULT_BPSAMP;
   priv->mclk_freq  = 0;
 
+  ret = cs4344_setmclkfrequency(priv);
+  if (ret != OK)
+    {
+      if (ret != -ENOTTY)
+        {
+          auderr("ERROR: Unsupported combination of sample rate and"
+                 "data width\n");
+          return ret;
+        }
+      else
+        {
+          audwarn("WARNING: MCLK could not be set on lower half\n");
+        }
+    }
+
   /* Configure the FLL and the LRCLK */
 
   cs4344_setbitrate(priv);
+
+  return OK;
 }
 
 /****************************************************************************
@@ -1451,6 +1470,7 @@ static void cs4344_reset(FAR struct cs4344_dev_s *priv)
 FAR struct audio_lowerhalf_s *cs4344_initialize(FAR struct i2s_dev_s *i2s)
 {
   FAR struct cs4344_dev_s *priv;
+  int ret;
 
   /* Sanity check */
 
@@ -1474,7 +1494,13 @@ FAR struct audio_lowerhalf_s *cs4344_initialize(FAR struct i2s_dev_s *i2s)
 
       /* Reset and reconfigure the CS4344 hardware */
 
-      cs4344_reset(priv);
+      ret = cs4344_reset(priv);
+      if (ret != OK)
+        {
+          auderr("ERROR: Initialization failed: ret=%d\n", ret);
+          return NULL;
+        }
+
       return &priv->dev;
     }