Skip to contentSkip to conversation

ALSA: hda: Abstract and update HOST-stream setup procedure

PATCH Superseded Cezary Rojewski 3 participants 9 messages Sep 25, 2023

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Cezary Rojewski

author maintainer
#0 lore raw

cover ALSA: hda: Abstract and update HOST-stream setup procedure

The patchset targets two intertwined topics:

The driver shall poll SDxFIFOS to ensure a valid value is set by the controller after programming SDxFMT. Due to amount of users and limited-number of configuration available in our CI when compared to overall possibilities on the market, the check is non-blocking.

Second topic relates to stream setup procedure. The procedure differs between HDAudio controller device revisions. Right now those differences are handled directly by a platform driver. Existing top-level 'if (pci->device == APL)' could be replaced by a abstraction in lower parts of the code instead.

With that done, the two users are updated accordingly. In avs-driver case, this updates the flow to the recommended one.

Cezary Rojewski (4):
ALSA: hda: Poll SDxFIFOS after programming SDxFMT
ALSA: hda: Introduce HOST stream setup mechanism
ASoC: Intel: avs: Use helper to setup HOST stream
ASoC: Intel: Skylake: Use helper to setup HOST stream

 include/sound/hda_register.h      |  2 ++
 include/sound/hdaudio.h           |  3 +++
 include/sound/hdaudio_ext.h       |  3 +++
 sound/hda/ext/hdac_ext_stream.c   | 41 +++++++++++++++++++++++++++++++
 sound/hda/hdac_stream.c           |  8 ++++++
 sound/soc/intel/avs/pcm.c         |  2 +-
 sound/soc/intel/skylake/skl-pcm.c | 14 +----------
 7 files changed, 59 insertions(+), 14 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH 2/4 ALSA: hda: Introduce HOST stream setup mechanism

HDAudio stream setup procedure differs between revisions of the controller device. Currently the differences are handled directly within AudioDSP platform drivers with if-statements. Implement a more generic approach and expose a function that a platform driver may use to ensure the correct procedure is followed each time.

---
 include/sound/hdaudio_ext.h     |  3 +++
 sound/hda/ext/hdac_ext_stream.c | 41 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
include/sound/hdaudio_ext.h +3 -0
index 511211f4a2b6..d32959cb71d2 100644
@@ -60,6 +60,8 @@ struct hdac_ext_stream {
 	bool link_locked:1;
 	bool link_prepared;
 
+	int (*host_setup)(struct hdac_stream *);
+
 	struct snd_pcm_substream *link_substream;
 };
 
@@ -86,6 +88,7 @@ void snd_hdac_ext_stream_start(struct hdac_ext_stream *hext_stream);
 void snd_hdac_ext_stream_clear(struct hdac_ext_stream *hext_stream);
 void snd_hdac_ext_stream_reset(struct hdac_ext_stream *hext_stream);
 int snd_hdac_ext_stream_setup(struct hdac_ext_stream *hext_stream, int fmt);
+int snd_hdac_ext_host_stream_setup(struct hdac_ext_stream *hext_stream);
 
 struct hdac_ext_link {
 	struct hdac_bus *bus;
sound/hda/ext/hdac_ext_stream.c +41 -0

68 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/4 ALSA: hda: Poll SDxFIFOS after programming SDxFMT

In reply to Cezary Rojewski

Software shall read SDxFIFOS calculated by the hardware and notify if invalid value is programmed before continuing the stream preparation.

---
 include/sound/hda_register.h | 2 ++
 include/sound/hdaudio.h      | 3 +++
 sound/hda/hdac_stream.c      | 8 ++++++++
 3 files changed, 13 insertions(+)
include/sound/hda_register.h +2 -0
index 9c7872c0ca79..55958711d697 100644
@@ -91,6 +91,8 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
 #define AZX_REG_SD_BDLPL		0x18
 #define AZX_REG_SD_BDLPU		0x1c
 
+#define AZX_SD_FIFOSIZE_MASK		GENMASK(15, 0)
+
 /* GTS registers */
 #define AZX_REG_LLCH			0x14
 
include/sound/hdaudio.h +3 -0
index 32c59053b48e..41d725babf53 100644
@@ -624,6 +624,9 @@ int snd_hdac_stream_set_lpib(struct hdac_stream *azx_dev, u32 value);
 #define snd_hdac_stream_readb_poll(dev, reg, val, cond, delay_us, timeout_us) \
 	read_poll_timeout_atomic(snd_hdac_reg_readb, val, cond, delay_us, timeout_us, \
 				 false, (dev)->bus, (dev)->sd_addr + AZX_REG_ ## reg)
+#define snd_hdac_stream_readw_poll(dev, reg, val, cond, delay_us, timeout_us) \
+	read_poll_timeout_atomic(snd_hdac_reg_readw, val, cond, delay_us, timeout_us, \
+				 false, (dev)->bus, (dev)->sd_addr + AZX_REG_ ## reg)
 #define snd_hdac_stream_readl_poll(dev, reg, val, cond, delay_us, timeout_us) \
 	read_poll_timeout_atomic(snd_hdac_reg_readl, val, cond, delay_us, timeout_us, \
 				 false, (dev)->bus, (dev)->sd_addr + AZX_REG_ ## reg)
sound/hda/hdac_stream.c +8 -0
index 2633a4bb1d85..5382894bebab 100644
@@ -258,6 +258,8 @@ int snd_hdac_stream_setup(struct hdac_stream *azx_dev)
 	struct hdac_bus *bus = azx_dev->bus;
 	struct snd_pcm_runtime *runtime;
 	unsigned int val;
+	u16 reg;
+	int ret;
 
 	if (azx_dev->substream)
 		runtime = azx_dev->substream->runtime;
@@ -300,6 +302,12 @@ int snd_hdac_stream_setup(struct hdac_stream *azx_dev)
 	/* set the interrupt enable bits in the descriptor control register */
 	snd_hdac_stream_updatel(azx_dev, SD_CTL, 0, SD_INT_MASK);
 
+	/* Once SDxFMT is set, the controller programs SDxFIFOS to non-zero value. */
+	ret = snd_hdac_stream_readw_poll(azx_dev, SD_FIFOSIZE, reg, reg & AZX_SD_FIFOSIZE_MASK,
+					 3, 300);
+	if (ret)
+		dev_dbg(bus->dev, "polling SD_FIFOSIZE 0x%04x failed: %d\n",
+			AZX_REG_SD_FIFOSIZE, ret);
 	azx_dev->fifo_size = snd_hdac_stream_readw(azx_dev, SD_FIFOSIZE) + 1;
 
 	/* when LPIB delay correction gives a small negative value,
Signature · 1 line
2.25.1
author maintainer
#7 lore raw

PATCH 4/4 ASoC: Intel: Skylake: Use helper to setup HOST stream

In reply to Cezary Rojewski

snd_hdac_ext_host_stream_setup() abstracts the procedure details away. Simplify the code by using it.

---
 sound/soc/intel/skylake/skl-pcm.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
sound/soc/intel/skylake/skl-pcm.c +1 -13
index ac3dc8c63c26..7502b2e70e46 100644
@@ -124,7 +124,6 @@ static void skl_set_suspend_active(struct snd_pcm_substream *substream,
 int skl_pcm_host_dma_prepare(struct device *dev, struct skl_pipe_params *params)
 {
 	struct hdac_bus *bus = dev_get_drvdata(dev);
-	struct skl_dev *skl = bus_to_skl(bus);
 	unsigned int format_val;
 	struct hdac_stream *hstream;
 	struct hdac_ext_stream *stream;
@@ -149,18 +148,7 @@ int skl_pcm_host_dma_prepare(struct device *dev, struct skl_pipe_params *params)
 	if (err < 0)
 		return err;
 
-	/*
-	 * The recommended SDxFMT programming sequence for BXT
-	 * platforms is to couple the stream before writing the format
-	 */
-	if (HDA_CONTROLLER_IS_APL(skl->pci)) {
-		snd_hdac_ext_stream_decouple(bus, stream, false);
-		err = snd_hdac_stream_setup(hdac_stream(stream));
-		snd_hdac_ext_stream_decouple(bus, stream, true);
-	} else {
-		err = snd_hdac_stream_setup(hdac_stream(stream));
-	}
-
+	err = snd_hdac_ext_host_stream_setup(stream);
 	if (err < 0)
 		return err;
 
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH 3/4 ASoC: Intel: avs: Use helper to setup HOST stream

In reply to Cezary Rojewski

snd_hdac_ext_host_stream_setup() abstracts the procedure details away. Simplify the code by using it.

---
 sound/soc/intel/avs/pcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/intel/avs/pcm.c +1 -1
index 8565a530706d..e628fdfdc018 100644
@@ -625,7 +625,7 @@ static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_so
 	if (ret < 0)
 		return ret;
 
-	ret = snd_hdac_stream_setup(hdac_stream(host_stream));
+	ret = snd_hdac_ext_host_stream_setup(host_stream);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.25.1
maintainer Acked-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] ASoC: Intel: avs: Use helper to setup HOST stream

Quoted 2 lines · Cezary Rojewski

snd_hdac_ext_host_stream_setup() abstracts the procedure details away. Simplify the code by using it.

author maintainer
#3 lore raw

Re: [PATCH 2/4] ALSA: hda: Introduce HOST stream setup mechanism

In reply to Cezary Rojewski
Quoted 5 lines · Cezary Rojewski

HDAudio stream setup procedure differs between revisions of the controller device. Currently the differences are handled directly within AudioDSP platform drivers with if-statements. Implement a more generic approach and expose a function that a platform driver may use to ensure the correct procedure is followed each time.

...

sound/hda/ext/hdac_ext_stream.c static void snd_hdac_ext_stream_init(struct hdac_bus *bus, · line 99

Quoted 13 lines
sound/hda/ext/hdac_ext_stream.c +6 -0
@@ -55,9 +88,16 @@ static void snd_hdac_ext_stream_init(struct hdac_bus *bus,
  int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
  				 int num_stream, int dir)
  {
+	struct pci_dev *pci = to_pci_dev(bus->dev);
+	int (*setup_op)(struct hdac_stream *);
  	int stream_tag = 0;
  	int i, tag, idx = start_idx;
 
+	if (pci->device == PCI_DEVICE_ID_INTEL_HDA_APL)
+		setup_op = snd_hdac_stream_setup;
+	else
+		setup_op = snd_hdac_apl_host_stream_setup;

Sorry for this, due to renaming I did send incorrect revision of patchset. The if-statement was "negative" previously. Will send v2.

Quoted 11 lines
sound/hda/ext/hdac_ext_stream.c +1 -0
  	for (i = 0; i < num_stream; i++) {
  		struct hdac_ext_stream *hext_stream =
  				kzalloc(sizeof(*hext_stream), GFP_KERNEL);
@@ -66,6 +106,7 @@ int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
  		tag = ++stream_tag;
  		snd_hdac_ext_stream_init(bus, hext_stream, idx, dir, tag);
  		idx++;
+		hext_stream->host_setup = setup_op;
  	}
 
  	return 0;
#4 lore raw

Re: [PATCH 2/4] ALSA: hda: Introduce HOST stream setup mechanism

In reply to Cezary Rojewski
kernel test robot noticed the following build warnings:

Hi Cezary,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on tiwai-sound/for-linus broonie-sound/for-next linus/master v6.6-rc3 next-20230925] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Cezary-Rojewski/ALSA-hda-Poll-SDxFIFOS-after-programming-SDxFMT/20230925-200351
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20230925115844.18795-3-cezary.rojewski%40intel.com
patch subject: [PATCH 2/4] ALSA: hda: Introduce HOST stream setup mechanism
config: x86_64-buildonly-randconfig-002-20230925 (https://download.01.org/0day-ci/archive/20230925/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230925/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> sound/hda/ext/hdac_ext_stream.c:28: warning: Function parameter or member 'hext_stream' not described in 'snd_hdac_ext_host_stream_setup'
>> sound/hda/ext/hdac_ext_stream.c:41: warning: Function parameter or member 'hstream' not described in 'snd_hdac_apl_host_stream_setup'

vim +28 sound/hda/ext/hdac_ext_stream.c

20
21 /**
22 * snd_hdac_ext_host_stream_setup - Setup a HOST stream.
23 * @hext_stream - HDAudio stream to set up.
24 *
25 * Return: Zero on success or negative error code.
26 */
27 int snd_hdac_ext_host_stream_setup(struct hdac_ext_stream *hext_stream)

  > 28	{
    29		return hext_stream->host_setup(hdac_stream(hext_stream));
    30	}
    31	EXPORT_SYMBOL_GPL(snd_hdac_ext_host_stream_setup);
    32	
    33	/**
    34	 * snd_hdac_apl_host_stream_setup - Setup a HOST stream following procedure
    35	 *                                  recommended for ApolloLake devices.
    36	 * @hstream - HDAudio stream to set up.
    37	 *
    38	 * Return: Zero on success or negative error code.
    39	 */
    40	static int snd_hdac_apl_host_stream_setup(struct hdac_stream *hstream)
  > 41	{
    42		struct hdac_ext_stream *hext_stream = stream_to_hdac_ext_stream(hstream);
    43		int ret;
    44	
    45		snd_hdac_ext_stream_decouple(hstream->bus, hext_stream, false);
    46		ret = snd_hdac_stream_setup(hstream);
    47		snd_hdac_ext_stream_decouple(hstream->bus, hext_stream, true);
    48	
    49		return ret;
    50	}
    51	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki