Skip to contentSkip to conversation

Tegra Specific fixes

PATCH Applied Mohan Kumar 2 participants 5 messages Aug 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Tegra Specific fixes

This series proposes following fixes to Tegra HDA driver.
* Align the buffer to 128 bytes for Tegra.
* Add new behavior flag dma_stop_delay in hdac_bus structure.
* Add 100us as dma stop delay for Tegra.

Mohan Kumar (3):
ASoC: hda/tegra: Set buffer alignment to 128 bytes
ALSA: hda: Add dma stop delay variable
ALSA: hda/tegra: Add 100us dma stop delay

 include/sound/hdaudio.h   | 3 +++
 sound/hda/hdac_stream.c   | 7 +++++++
 sound/pci/hda/hda_tegra.c | 3 +++
 3 files changed, 13 insertions(+)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/3 ASoC: hda/tegra: Set buffer alignment to 128 bytes

Set chip->align_buffer_size to 1 for Tegra platforms to make the buffer alignment to be multiple of 128 bytes. This fix is applied as gstreamer alsasink gets stuck with the default buffer-time and latency-time parameters with 4 byte buffer alignment.

---
 sound/pci/hda/hda_tegra.c | 2 ++
 1 file changed, 2 insertions(+)
sound/pci/hda/hda_tegra.c +2 -0
index 5637f0129932..ecf98eb9df36 100644
@@ -333,6 +333,8 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
 	gcap = azx_readw(chip, GCAP);
 	dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
 
+	chip->align_buffer_size = 1;
+
 	/* read number of streams from GCAP register instead of using
 	 * hardcoded value
 	 */
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/3 ALSA: hda: Add dma stop delay variable

In reply to Mohan Kumar

A variable dma_stop_delay is added as a new member in hdac_bus structure to avoid memory decode error incase DMA RUN bit is not disabled in the given timeout from snd_hdac_stream_sync function and followed by stream reset which results in memory decode error between reset set and clear operation.

---
 include/sound/hdaudio.h | 3 +++
 sound/hda/hdac_stream.c | 7 +++++++
 2 files changed, 10 insertions(+)
include/sound/hdaudio.h +3 -0
index c1f78d9a6e47..6eed61e6cf8a 100644
@@ -347,6 +347,9 @@ struct hdac_bus {
 
 	int bdl_pos_adj;		/* BDL position adjustment */
 
+	/* delay time in us for dma stop */
+	unsigned int dma_stop_delay;
+
 	/* locks */
 	spinlock_t reg_lock;
 	struct mutex cmd_mutex;
sound/hda/hdac_stream.c +7 -0
index a38a2af1654f..abe7a1b16fe1 100644
@@ -150,9 +150,12 @@ void snd_hdac_stream_reset(struct hdac_stream *azx_dev)
 {
 	unsigned char val;
 	int timeout;
+	int dma_run_state;
 
 	snd_hdac_stream_clear(azx_dev);
 
+	dma_run_state = snd_hdac_stream_readb(azx_dev, SD_CTL) & SD_CTL_DMA_START;
+
 	snd_hdac_stream_updateb(azx_dev, SD_CTL, 0, SD_CTL_STREAM_RESET);
 	udelay(3);
 	timeout = 300;
@@ -162,6 +165,10 @@ void snd_hdac_stream_reset(struct hdac_stream *azx_dev)
 		if (val)
 			break;
 	} while (--timeout);
+
+	if (azx_dev->bus->dma_stop_delay && dma_run_state)
+		udelay(azx_dev->bus->dma_stop_delay);
+
 	val &= ~SD_CTL_STREAM_RESET;
 	snd_hdac_stream_writeb(azx_dev, SD_CTL, val);
 	udelay(3);
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 3/3 ALSA: hda/tegra: Add 100us dma stop delay

In reply to Mohan Kumar

Tegra HDA has audio data buffer for upto tens of frames, this buffer can help to avoid underflow. HW will keep issuing new data fetch request when buffers are not full and current BDL is not done. When SW disable DMA RUN bit for a stream, HW can't cancel the already issued data fetch request and hence it can't stop DMA. HW has to wait for all issued data fetch request get data returned before it stops DMA.

This HW behavior is not in sync with HDA spec which says DMA RUN bit should be cleared within 1 audio frame. For Tegra, DMA RUN bit was active for more than one audio frame, due to this the timeout in snd_hdac_stream_sync function is not helping. When Stream reset set and clear happens during DMA RUN bit active state it results in Memory Decode error.

Unfortunately, there is no way to detect when these data accesses have completed, but testing has shown that a 100us delay between Stream reset set and clear operation for Tegra avoids the memory decode error. Therefore, adding a 100us dma stop delay.

---
 sound/pci/hda/hda_tegra.c | 1 +
 1 file changed, 1 insertion(+)
sound/pci/hda/hda_tegra.c +1 -0
index ecf98eb9df36..c94553bcca88 100644
@@ -308,6 +308,7 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
 		return err;
 	}
 	bus->irq = irq_id;
+	bus->dma_stop_delay = 100;
 	card->sync_irq = bus->irq;
 
 	/*
Signature · 1 line
2.17.1
Applied
#4 lore raw
In reply to Mohan Kumar
Quoted 11 lines · Mohan Kumar

This series proposes following fixes to Tegra HDA driver.
* Align the buffer to 128 bytes for Tegra.
* Add new behavior flag dma_stop_delay in hdac_bus structure.
* Add 100us as dma stop delay for Tegra.

Mohan Kumar (3):
ASoC: hda/tegra: Set buffer alignment to 128 bytes
ALSA: hda: Add dma stop delay variable
ALSA: hda/tegra: Add 100us dma stop delay

Thanks, applied now all three patches.

Takashi