Skip to content

Commit d80c400

Browse files
crojewsk-inteltiwai
authored andcommitted
ALSA: hda: Transfer firmware in two chunks
As per specification, SDxLVI shall be at least 1 i.e.: two chunks to perform a valid transfer. This is true for the PCM transfer code but not firmware-transfer one. Technical background: - the LVI > 0 rule shall be obeyed in PCM transfer - HW permits LVI == 0 when transfer is SW-controlled (SPIB) - FW download is not a PCM transfer and is SW-controlled (SPIB) The above is the fundament which AudioDSP firmware loading functions have been built upon and worked since 2016. The presented changes are to align the loading flows and avoid rising more questions in the future. Achieve the goal by splitting snd_hdac_stream_setup_periods() into substream-dependent and -independent part. Let snd_hdac_dsp_prepare() utilize the latter so that both DSP-loading and PCM flows utilize same BLDE setup loop which already takes care of cutting the buffer based on azx_dev->period_bytes. Signed-off-by: Cezary Rojewski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 3846699 commit d80c400

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

sound/hda/hdac_stream.c

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -492,32 +492,21 @@ static int setup_bdle(struct hdac_bus *bus,
492492
}
493493

494494
/**
495-
* snd_hdac_stream_setup_periods - set up BDL entries
495+
* snd_hdac_stream_setup_bdle - set up BDL entries
496496
* @azx_dev: HD-audio core stream to set up
497+
* @dmab: allocated DMA buffer
498+
* @runtime: substream runtime, optional
497499
*
498500
* Set up the buffer descriptor table of the given stream based on the
499501
* period and buffer sizes of the assigned PCM substream.
500502
*/
501-
int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev)
503+
static int snd_hdac_stream_setup_bdle(struct hdac_stream *azx_dev, struct snd_dma_buffer *dmab,
504+
struct snd_pcm_runtime *runtime)
502505
{
503506
struct hdac_bus *bus = azx_dev->bus;
504-
struct snd_pcm_substream *substream = azx_dev->substream;
505-
struct snd_compr_stream *cstream = azx_dev->cstream;
506-
struct snd_pcm_runtime *runtime = NULL;
507-
struct snd_dma_buffer *dmab;
508-
__le32 *bdl;
509507
int i, ofs, periods, period_bytes;
510508
int pos_adj, pos_align;
511-
512-
if (substream) {
513-
runtime = substream->runtime;
514-
dmab = snd_pcm_get_dma_buf(substream);
515-
} else if (cstream) {
516-
dmab = snd_pcm_get_dma_buf(cstream);
517-
} else {
518-
WARN(1, "No substream or cstream assigned\n");
519-
return -EINVAL;
520-
}
509+
__le32 *bdl;
521510

522511
/* reset BDL address */
523512
snd_hdac_stream_writel(azx_dev, SD_BDLPL, 0);
@@ -571,6 +560,33 @@ int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev)
571560
azx_dev->bufsize, period_bytes);
572561
return -EINVAL;
573562
}
563+
564+
/**
565+
* snd_hdac_stream_setup_periods - set up BDL entries
566+
* @azx_dev: HD-audio core stream to set up
567+
*
568+
* Set up the buffer descriptor table of the given stream based on the
569+
* period and buffer sizes of the assigned PCM substream.
570+
*/
571+
int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev)
572+
{
573+
struct snd_pcm_substream *substream = azx_dev->substream;
574+
struct snd_compr_stream *cstream = azx_dev->cstream;
575+
struct snd_pcm_runtime *runtime = NULL;
576+
struct snd_dma_buffer *dmab;
577+
578+
if (substream) {
579+
runtime = substream->runtime;
580+
dmab = snd_pcm_get_dma_buf(substream);
581+
} else if (cstream) {
582+
dmab = snd_pcm_get_dma_buf(cstream);
583+
} else {
584+
WARN(1, "No substream or cstream assigned\n");
585+
return -EINVAL;
586+
}
587+
588+
return snd_hdac_stream_setup_bdle(azx_dev, dmab, runtime);
589+
}
574590
EXPORT_SYMBOL_GPL(snd_hdac_stream_setup_periods);
575591

576592
/**
@@ -923,7 +939,6 @@ int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format,
923939
unsigned int byte_size, struct snd_dma_buffer *bufp)
924940
{
925941
struct hdac_bus *bus = azx_dev->bus;
926-
__le32 *bdl;
927942
int err;
928943

929944
snd_hdac_dsp_lock(azx_dev);
@@ -943,18 +958,14 @@ int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format,
943958

944959
azx_dev->substream = NULL;
945960
azx_dev->bufsize = byte_size;
946-
azx_dev->period_bytes = byte_size;
961+
/* It is recommended to transfer the firmware in two or more chunks. */
962+
azx_dev->period_bytes = byte_size / 2;
947963
azx_dev->format_val = format;
964+
azx_dev->no_period_wakeup = 1;
948965

949966
snd_hdac_stream_reset(azx_dev);
950967

951-
/* reset BDL address */
952-
snd_hdac_stream_writel(azx_dev, SD_BDLPL, 0);
953-
snd_hdac_stream_writel(azx_dev, SD_BDLPU, 0);
954-
955-
azx_dev->frags = 0;
956-
bdl = (__le32 *)azx_dev->bdl.area;
957-
err = setup_bdle(bus, bufp, azx_dev, &bdl, 0, byte_size, 0);
968+
err = snd_hdac_stream_setup_bdle(azx_dev, bufp, NULL);
958969
if (err < 0)
959970
goto error;
960971

0 commit comments

Comments
 (0)