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.
This commit is contained in:
Tiago Medicci Serrano 2023-08-30 14:14:27 -03:00 committed by Xiang Xiao
parent d9169b84e4
commit 9357d70c25
1 changed files with 30 additions and 4 deletions

View File

@ -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;
}