Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: pcm: Add a standalone version of snd_pcm_limit_hw_rates

It can be useful to derive min/max rates of a snd_pcm_hardware without
having a snd_pcm_runtime, such as before constructing an ASoC DAI link.

Create a new helper that takes a pointer to a snd_pcm_hardware directly,
and refactor the original function as a wrapper around it, to avoid
needing to update any call sites.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20200305051143.60691-2-samuel@sholland.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Samuel Holland and committed by
Mark Brown
4769bfb9 6e02feb0

+17 -10
+8 -1
include/sound/pcm.h
··· 1127 1127 return __snd_pcm_lib_xfer(substream, bufs, false, frames, true); 1128 1128 } 1129 1129 1130 - int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime); 1130 + int snd_pcm_hw_limit_rates(struct snd_pcm_hardware *hw); 1131 + 1132 + static inline int 1133 + snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime) 1134 + { 1135 + return snd_pcm_hw_limit_rates(&runtime->hw); 1136 + } 1137 + 1131 1138 unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate); 1132 1139 unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit); 1133 1140 unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
+9 -9
sound/core/pcm_misc.c
··· 474 474 EXPORT_SYMBOL(snd_pcm_format_set_silence); 475 475 476 476 /** 477 - * snd_pcm_limit_hw_rates - determine rate_min/rate_max fields 478 - * @runtime: the runtime instance 477 + * snd_pcm_hw_limit_rates - determine rate_min/rate_max fields 478 + * @hw: the pcm hw instance 479 479 * 480 480 * Determines the rate_min and rate_max fields from the rates bits of 481 - * the given runtime->hw. 481 + * the given hw. 482 482 * 483 483 * Return: Zero if successful. 484 484 */ 485 - int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime) 485 + int snd_pcm_hw_limit_rates(struct snd_pcm_hardware *hw) 486 486 { 487 487 int i; 488 488 for (i = 0; i < (int)snd_pcm_known_rates.count; i++) { 489 - if (runtime->hw.rates & (1 << i)) { 490 - runtime->hw.rate_min = snd_pcm_known_rates.list[i]; 489 + if (hw->rates & (1 << i)) { 490 + hw->rate_min = snd_pcm_known_rates.list[i]; 491 491 break; 492 492 } 493 493 } 494 494 for (i = (int)snd_pcm_known_rates.count - 1; i >= 0; i--) { 495 - if (runtime->hw.rates & (1 << i)) { 496 - runtime->hw.rate_max = snd_pcm_known_rates.list[i]; 495 + if (hw->rates & (1 << i)) { 496 + hw->rate_max = snd_pcm_known_rates.list[i]; 497 497 break; 498 498 } 499 499 } 500 500 return 0; 501 501 } 502 - EXPORT_SYMBOL(snd_pcm_limit_hw_rates); 502 + EXPORT_SYMBOL(snd_pcm_hw_limit_rates); 503 503 504 504 /** 505 505 * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit