diff mbox series

ALSA: hda: use azx_stream() helper in all places

Message ID 20240131151001.737372-1-perex@perex.cz (mailing list archive)
State New, archived
Headers show
Series ALSA: hda: use azx_stream() helper in all places | expand

Commit Message

Jaroslav Kysela Jan. 31, 2024, 3:10 p.m. UTC
Make code more readable with azx_stream() helper. No functional change.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 sound/pci/hda/hda_controller.c | 20 +++++++-------
 sound/pci/hda/hda_intel.c      | 50 +++++++++++++++++-----------------
 2 files changed, 35 insertions(+), 35 deletions(-)

Comments

Takashi Iwai Feb. 1, 2024, 12:54 p.m. UTC | #1
On Wed, 31 Jan 2024 16:10:01 +0100,
Jaroslav Kysela wrote:
> 
> Make code more readable with azx_stream() helper. No functional change.
> 
> Signed-off-by: Jaroslav Kysela <perex@perex.cz>

I have no much preference, but using the macro doesn't look like a
significant improvement to me, honestly speaking...

But I'm open for those.  If you have further changes based on those
updates, I can take now, too.


thanks,

Takashi
Jaroslav Kysela Feb. 1, 2024, 1:21 p.m. UTC | #2
On 01. 02. 24 13:54, Takashi Iwai wrote:
> On Wed, 31 Jan 2024 16:10:01 +0100,
> Jaroslav Kysela wrote:
>>
>> Make code more readable with azx_stream() helper. No functional change.
>>
>> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
> 
> I have no much preference, but using the macro doesn't look like a
> significant improvement to me, honestly speaking...

If you look to some functions, there's a mixture of azx_stream() and ->core. 
access to the same structure members. I found that it's an extra step for the 
reader to identify that both are same source. I don't mind to remove 
azx_stream macro or use it everywhere as I proposed, too.

I just dig to the sources wondering if 192k analog support is possible and 
this was visible mismatch.

More patches will probably follow.

						Jaroslav
diff mbox series

Patch

diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c
index 3e7bfeee84fd..0ec1e7192d72 100644
--- a/sound/pci/hda/hda_controller.c
+++ b/sound/pci/hda/hda_controller.c
@@ -117,9 +117,9 @@  static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
 		goto unlock;
 	}
 
-	azx_dev->core.bufsize = 0;
-	azx_dev->core.period_bytes = 0;
-	azx_dev->core.format_val = 0;
+	azx_stream(azx_dev)->bufsize = 0;
+	azx_stream(azx_dev)->period_bytes = 0;
+	azx_stream(azx_dev)->format_val = 0;
 
 unlock:
 	dsp_unlock(azx_dev);
@@ -182,13 +182,13 @@  static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 
 	snd_hdac_stream_setup(azx_stream(azx_dev), false);
 
-	stream_tag = azx_dev->core.stream_tag;
+	stream_tag = azx_stream(azx_dev)->stream_tag;
 	/* CA-IBG chips need the playback stream starting from 1 */
 	if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) &&
 	    stream_tag > chip->capture_streams)
 		stream_tag -= chip->capture_streams;
 	err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
-				     azx_dev->core.format_val, substream);
+				     azx_stream(azx_dev)->format_val, substream);
 
  unlock:
 	if (!err)
@@ -240,7 +240,7 @@  static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 		if (s->pcm->card != substream->pcm->card)
 			continue;
 		azx_dev = get_azx_dev(s);
-		sbits |= 1 << azx_dev->core.index;
+		sbits |= 1 << azx_stream(azx_dev)->index;
 		snd_pcm_trigger_done(s, substream);
 	}
 
@@ -288,7 +288,7 @@  EXPORT_SYMBOL_GPL(azx_get_pos_posbuf);
 unsigned int azx_get_position(struct azx *chip,
 			      struct azx_dev *azx_dev)
 {
-	struct snd_pcm_substream *substream = azx_dev->core.substream;
+	struct snd_pcm_substream *substream = azx_stream(azx_dev)->substream;
 	unsigned int pos;
 	int stream = substream->stream;
 	int delay = 0;
@@ -298,7 +298,7 @@  unsigned int azx_get_position(struct azx *chip,
 	else /* use the position buffer as default */
 		pos = azx_get_pos_posbuf(chip, azx_dev);
 
-	if (pos >= azx_dev->core.bufsize)
+	if (pos >= azx_stream(azx_dev)->bufsize)
 		pos = 0;
 
 	if (substream->runtime) {
@@ -386,7 +386,7 @@  static int azx_get_sync_time(ktime_t *device,
 	do {
 		timeout = 100;
 		dma_select = (direction << GTSCC_CDMAS_DMA_DIR_SHIFT) |
-					(azx_dev->core.stream_tag - 1);
+					(azx_stream(azx_dev)->stream_tag - 1);
 		snd_hdac_chip_writel(azx_bus(chip), GTSCC, dma_select);
 
 		/* Enable the capture */
@@ -501,7 +501,7 @@  static int azx_get_time_info(struct snd_pcm_substream *substream,
 
 		snd_pcm_gettime(substream->runtime, system_ts);
 
-		nsec = timecounter_read(&azx_dev->core.tc);
+		nsec = timecounter_read(&azx_stream(azx_dev)->tc);
 		if (audio_tstamp_config->report_delay)
 			nsec = azx_adjust_codec_delay(substream, nsec);
 
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 2276adc84478..beca47989327 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -572,7 +572,7 @@  static void hda_intel_init_chip(struct azx *chip, bool full_reset)
 static int azx_get_delay_from_lpib(struct azx *chip, struct azx_dev *azx_dev,
 				   unsigned int pos)
 {
-	struct snd_pcm_substream *substream = azx_dev->core.substream;
+	struct snd_pcm_substream *substream = azx_stream(azx_dev)->substream;
 	int stream = substream->stream;
 	unsigned int lpib_pos = azx_get_pos_lpib(chip, azx_dev);
 	int delay;
@@ -582,16 +582,16 @@  static int azx_get_delay_from_lpib(struct azx *chip, struct azx_dev *azx_dev,
 	else
 		delay = lpib_pos - pos;
 	if (delay < 0) {
-		if (delay >= azx_dev->core.delay_negative_threshold)
+		if (delay >= azx_stream(azx_dev)->delay_negative_threshold)
 			delay = 0;
 		else
-			delay += azx_dev->core.bufsize;
+			delay += azx_stream(azx_dev)->bufsize;
 	}
 
-	if (delay >= azx_dev->core.period_bytes) {
+	if (delay >= azx_stream(azx_dev)->period_bytes) {
 		dev_info(chip->card->dev,
 			 "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n",
-			 delay, azx_dev->core.period_bytes);
+			 delay, azx_stream(azx_dev)->period_bytes);
 		delay = 0;
 		chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY;
 		chip->get_delay[stream] = NULL;
@@ -636,7 +636,7 @@  static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev)
  */
 static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
 {
-	struct snd_pcm_substream *substream = azx_dev->core.substream;
+	struct snd_pcm_substream *substream = azx_stream(azx_dev)->substream;
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	int stream = substream->stream;
 	u32 wallclk;
@@ -650,8 +650,8 @@  static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
 	if (chip->driver_type == AZX_DRIVER_LOONGSON)
 		return 1;
 
-	wallclk = azx_readl(chip, WALLCLK) - azx_dev->core.start_wallclk;
-	if (wallclk < (azx_dev->core.period_wallclk * 2) / 3)
+	wallclk = azx_readl(chip, WALLCLK) - azx_stream(azx_dev)->start_wallclk;
+	if (wallclk < (azx_stream(azx_dev)->period_wallclk * 2) / 3)
 		return -1;	/* bogus (too early) interrupt */
 
 	if (chip->get_position[stream])
@@ -674,19 +674,19 @@  static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
 		}
 	}
 
-	if (pos >= azx_dev->core.bufsize)
+	if (pos >= azx_stream(azx_dev)->bufsize)
 		pos = 0;
 
-	if (WARN_ONCE(!azx_dev->core.period_bytes,
+	if (WARN_ONCE(!azx_stream(azx_dev)->period_bytes,
 		      "hda-intel: zero azx_dev->period_bytes"))
 		return -1; /* this shouldn't happen! */
-	if (wallclk < (azx_dev->core.period_wallclk * 5) / 4 &&
-	    pos % azx_dev->core.period_bytes > azx_dev->core.period_bytes / 2)
+	if (wallclk < (azx_stream(azx_dev)->period_wallclk * 5) / 4 &&
+	    pos % azx_stream(azx_dev)->period_bytes > azx_stream(azx_dev)->period_bytes / 2)
 		/* NG - it's below the first next period boundary */
 		return chip->bdl_pos_adj ? 0 : -1;
-	azx_dev->core.start_wallclk += wallclk;
+	azx_stream(azx_dev)->start_wallclk += wallclk;
 
-	if (azx_dev->core.no_period_wakeup)
+	if (azx_stream(azx_dev)->no_period_wakeup)
 		return 1; /* OK, no need to check period boundary */
 
 	if (runtime->hw_ptr_base != runtime->hw_ptr_interrupt)
@@ -794,7 +794,7 @@  static unsigned int azx_via_get_position(struct azx *chip,
 	unsigned int fifo_size;
 
 	link_pos = snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev));
-	if (azx_dev->core.substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+	if (azx_stream(azx_dev)->substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
 		/* Playback, no problem using link position */
 		return link_pos;
 	}
@@ -803,8 +803,8 @@  static unsigned int azx_via_get_position(struct azx *chip,
 	/* For new chipset,
 	 * use mod to get the DMA position just like old chipset
 	 */
-	mod_dma_pos = le32_to_cpu(*azx_dev->core.posbuf);
-	mod_dma_pos %= azx_dev->core.period_bytes;
+	mod_dma_pos = le32_to_cpu(*azx_stream(azx_dev)->posbuf);
+	mod_dma_pos %= azx_stream(azx_dev)->period_bytes;
 
 	fifo_size = azx_stream(azx_dev)->fifo_size;
 
@@ -817,20 +817,20 @@  static unsigned int azx_via_get_position(struct azx *chip,
 	}
 
 	if (link_pos <= fifo_size)
-		mini_pos = azx_dev->core.bufsize + link_pos - fifo_size;
+		mini_pos = azx_stream(azx_dev)->bufsize + link_pos - fifo_size;
 	else
 		mini_pos = link_pos - fifo_size;
 
 	/* Find nearest previous boudary */
-	mod_mini_pos = mini_pos % azx_dev->core.period_bytes;
-	mod_link_pos = link_pos % azx_dev->core.period_bytes;
+	mod_mini_pos = mini_pos % azx_stream(azx_dev)->period_bytes;
+	mod_link_pos = link_pos % azx_stream(azx_dev)->period_bytes;
 	if (mod_link_pos >= fifo_size)
 		bound_pos = link_pos - mod_link_pos;
 	else if (mod_dma_pos >= mod_mini_pos)
 		bound_pos = mini_pos - mod_mini_pos;
 	else {
-		bound_pos = mini_pos - mod_mini_pos + azx_dev->core.period_bytes;
-		if (bound_pos >= azx_dev->core.bufsize)
+		bound_pos = mini_pos - mod_mini_pos + azx_stream(azx_dev)->period_bytes;
+		if (bound_pos >= azx_stream(azx_dev)->bufsize)
 			bound_pos = 0;
 	}
 
@@ -843,7 +843,7 @@  static unsigned int azx_via_get_position(struct azx *chip,
 /* get the current DMA position with FIFO size correction */
 static unsigned int azx_get_pos_fifo(struct azx *chip, struct azx_dev *azx_dev)
 {
-	struct snd_pcm_substream *substream = azx_dev->core.substream;
+	struct snd_pcm_substream *substream = azx_stream(azx_dev)->substream;
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	unsigned int pos, delay;
 
@@ -865,7 +865,7 @@  static unsigned int azx_get_pos_fifo(struct azx *chip, struct azx_dev *azx_dev)
 	/* correct the DMA position for capture stream */
 	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
 		if (pos < delay)
-			pos += azx_dev->core.bufsize;
+			pos += azx_stream(azx_dev)->bufsize;
 		pos -= delay;
 	}
 
@@ -875,7 +875,7 @@  static unsigned int azx_get_pos_fifo(struct azx *chip, struct azx_dev *azx_dev)
 static int azx_get_delay_from_fifo(struct azx *chip, struct azx_dev *azx_dev,
 				   unsigned int pos)
 {
-	struct snd_pcm_substream *substream = azx_dev->core.substream;
+	struct snd_pcm_substream *substream = azx_stream(azx_dev)->substream;
 
 	/* just read back the calculated value in the above */
 	return substream->runtime->delay;