Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/drivers/intel/ssp/ssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,18 @@ static void ssp_empty_rx_fifo(struct dai *dai)
uint64_t sample_ticks = clock_ticks_per_sample(PLATFORM_DEFAULT_CLOCK,
ssp->params.fsync_rate);
uint32_t retry = SSP_RX_FLUSH_RETRY_MAX;
bool direct_reads = ssp->state[DAI_DIR_CAPTURE] <= COMP_STATE_PREPARE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about COMP_STATE_PAUSED? it is not active, and seems will not read with this state.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@btian1 That's a good question. Earlier version of the patch broke PAUSE, so I did spend some time looking at this. Curiously, ssp_pause does not stop the hardware and it based on tests, this is not needed after pause. I can't fully explain why this is the case (and DMA is stopped on pause).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other patch fixes the pause by yanking the FIFO before resume (which is a start operation), it is really strange to be honest, but w/o the FIFO drain patch I had broken pause/resume and I think @kv2019i had a working one on his (identical) setup.

uint32_t entries;
uint32_t i;

#if CONFIG_DMA_SUSPEND_DRAIN
/*
* In drain mode, DMA is stopped before DAI, so flush must be
* always done with direct register read.
*/
direct_reads = true;
#endif

/*
* To make sure all the RX FIFO entries are read out for the flushing,
* we need to wait a minimal SSP port delay after entries are all read,
Expand All @@ -87,9 +96,12 @@ static void ssp_empty_rx_fifo(struct dai *dai)
while ((ssp_read(dai, SSSR) & SSSR_RNE) && retry--) {
entries = SSCR3_RFL_VAL(ssp_read(dai, SSCR3));
dai_dbg(dai, "ssp_empty_rx_fifo(), before flushing, entries %d", entries);
for (i = 0; i < entries + 1; i++)
/* read to try empty fifo */
ssp_read(dai, SSDR);

/* let DMA consume data or read RX FIFO directly */
if (direct_reads) {
for (i = 0; i < entries + 1; i++)
ssp_read(dai, SSDR);
}

/* wait to get valid fifo status and re-check */
wait_delay(sample_ticks);
Expand Down Expand Up @@ -963,6 +975,10 @@ static void ssp_early_start(struct dai *dai, int direction)

key = k_spin_lock(&dai->lock);

/* RX fifo must be cleared before start */
if (direction == DAI_DIR_CAPTURE)
ssp_empty_rx_fifo(dai);

/* request mclk/bclk */
ssp_pre_start(dai);

Expand Down