Skip to content

Commit

Permalink
ASoC: fsl_asrc: Add initialization finishing check in runtime resume
Browse files Browse the repository at this point in the history
If the initialization is not finished, then filling input data to
the FIFO may fail. So it is better to add initialization finishing
check in the runtime resume for suspend & resume case.

And consider the case of three instances working in parallel,
increase the retry times to 50 for more initialization time.

Signed-off-by: Shengjiu Wang <[email protected]>
Reviewed-by: Nicolin Chen <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
TE-N-ShengjiuWang authored and broonie committed Sep 9, 2022
1 parent 985f03b commit d2de3f5
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion sound/soc/fsl/fsl_asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@

#define IDEAL_RATIO_DECIMAL_DEPTH 26
#define DIVIDER_NUM 64
#define INIT_RETRY_NUM 50

#define pair_err(fmt, ...) \
dev_err(&asrc->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__)

#define pair_dbg(fmt, ...) \
dev_dbg(&asrc->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__)

#define pair_warn(fmt, ...) \
dev_warn(&asrc->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__)

/* Corresponding to process_option */
static unsigned int supported_asrc_rate[] = {
5512, 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
Expand Down Expand Up @@ -579,7 +583,7 @@ static void fsl_asrc_start_pair(struct fsl_asrc_pair *pair)
{
struct fsl_asrc *asrc = pair->asrc;
enum asrc_pair_index index = pair->index;
int reg, retry = 10, i;
int reg, retry = INIT_RETRY_NUM, i;

/* Enable the current pair */
regmap_update_bits(asrc->regmap, REG_ASRCTR,
Expand All @@ -592,6 +596,10 @@ static void fsl_asrc_start_pair(struct fsl_asrc_pair *pair)
reg &= ASRCFG_INIRQi_MASK(index);
} while (!reg && --retry);

/* NOTE: Doesn't treat initialization timeout as an error */
if (!retry)
pair_warn("initialization isn't finished\n");

/* Make the input fifo to ASRC STALL level */
regmap_read(asrc->regmap, REG_ASRCNCR, &reg);
for (i = 0; i < pair->channels * 4; i++)
Expand Down Expand Up @@ -1257,6 +1265,7 @@ static int fsl_asrc_runtime_resume(struct device *dev)
{
struct fsl_asrc *asrc = dev_get_drvdata(dev);
struct fsl_asrc_priv *asrc_priv = asrc->private;
int reg, retry = INIT_RETRY_NUM;
int i, ret;
u32 asrctr;

Expand Down Expand Up @@ -1295,6 +1304,24 @@ static int fsl_asrc_runtime_resume(struct device *dev)
regmap_update_bits(asrc->regmap, REG_ASRCTR,
ASRCTR_ASRCEi_ALL_MASK, asrctr);

/* Wait for status of initialization for all enabled pairs */
do {
udelay(5);
regmap_read(asrc->regmap, REG_ASRCFG, &reg);
reg = (reg >> ASRCFG_INIRQi_SHIFT(0)) & 0x7;
} while ((reg != ((asrctr >> ASRCTR_ASRCEi_SHIFT(0)) & 0x7)) && --retry);

/*
* NOTE: Doesn't treat initialization timeout as an error
* Some of the pairs may success, then still can continue.
*/
if (!retry) {
for (i = ASRC_PAIR_A; i < ASRC_PAIR_MAX_NUM; i++) {
if ((asrctr & ASRCTR_ASRCEi_MASK(i)) && !(reg & (1 << i)))
dev_warn(dev, "Pair %c initialization isn't finished\n", 'A' + i);
}
}

return 0;

disable_asrck_clk:
Expand Down

0 comments on commit d2de3f5

Please sign in to comment.