From: Cezary Rojewski <cezary.rojewski@intel.com>
To: broonie@kernel.org
Cc: alsa-devel@alsa-project.org, linux-sound@vger.kernel.org,
tiwai@suse.com, perex@perex.cz,
amadeuszx.slawinski@linux.intel.com,
Cezary Rojewski <cezary.rojewski@intel.com>
Subject: [PATCH 8/8] ASoC: Intel: avs: Clean up hw constraints initialization
Date: Fri, 26 Apr 2024 11:57:33 +0200 [thread overview]
Message-ID: <20240426095733.3946951-9-cezary.rojewski@intel.com> (raw)
In-Reply-To: <20240426095733.3946951-1-cezary.rojewski@intel.com>
Provide a separate function that initializes all PCM hardware
constraints for the driver. No functional changes.
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
sound/soc/intel/avs/pcm.c | 84 ++++++++++++++++++++-------------------
1 file changed, 44 insertions(+), 40 deletions(-)
diff --git a/sound/soc/intel/avs/pcm.c b/sound/soc/intel/avs/pcm.c
index 168e16e82116..845b5ed9eb1b 100644
--- a/sound/soc/intel/avs/pcm.c
+++ b/sound/soc/intel/avs/pcm.c
@@ -448,19 +448,6 @@ static const struct snd_soc_dai_ops avs_dai_hda_be_ops = {
.trigger = avs_dai_hda_be_trigger,
};
-static const unsigned int rates[] = {
- 8000, 11025, 12000, 16000,
- 22050, 24000, 32000, 44100,
- 48000, 64000, 88200, 96000,
- 128000, 176400, 192000,
-};
-
-static const struct snd_pcm_hw_constraint_list hw_rates = {
- .count = ARRAY_SIZE(rates),
- .list = rates,
- .mask = 0,
-};
-
static int hw_rule_param_size(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)
{
struct snd_interval *interval = hw_param_interval(params, rule->var);
@@ -481,40 +468,33 @@ static int hw_rule_param_size(struct snd_pcm_hw_params *params, struct snd_pcm_h
return snd_interval_refine(interval, &to);
}
-static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
+static int avs_pcm_hw_constraints_init(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
- struct avs_dma_data *data;
- struct hdac_bus *bus;
- struct hdac_ext_stream *host_stream;
+ static const unsigned int rates[] = {
+ 8000, 11025, 12000, 16000,
+ 22050, 24000, 32000, 44100,
+ 48000, 64000, 88200, 96000,
+ 128000, 176400, 192000,
+ };
+ static const struct snd_pcm_hw_constraint_list rate_list = {
+ .count = ARRAY_SIZE(rates),
+ .list = rates,
+ };
int ret;
- ret = avs_dai_startup(substream, dai);
- if (ret)
- return ret;
-
- data = snd_soc_dai_get_dma_data(dai, substream);
- bus = &data->adev->base.core;
-
- host_stream = snd_hdac_ext_stream_assign(bus, substream, HDAC_EXT_STREAM_TYPE_HOST);
- if (!host_stream) {
- ret = -EBUSY;
- goto err;
- }
-
- data->host_stream = host_stream;
ret = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
if (ret < 0)
- goto err;
+ return ret;
- /* avoid wrap-around with wall-clock */
+ /* Avoid wrap-around with wall-clock. */
ret = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME, 20, 178000000);
if (ret < 0)
- goto err;
+ return ret;
- ret = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_rates);
+ ret = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &rate_list);
if (ret < 0)
- goto err;
+ return ret;
/* Adjust buffer and period size based on the audio format. */
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, hw_rule_param_size, NULL,
@@ -524,16 +504,40 @@ static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_so
SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_CHANNELS,
SNDRV_PCM_HW_PARAM_RATE, -1);
+ return ret;
+}
+
+static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
+{
+ struct hdac_ext_stream *host_stream;
+ struct avs_dma_data *data;
+ struct hdac_bus *bus;
+ int ret;
+
+ ret = avs_pcm_hw_constraints_init(substream);
+ if (ret)
+ return ret;
+
+ ret = avs_dai_startup(substream, dai);
+ if (ret)
+ return ret;
+
+ data = snd_soc_dai_get_dma_data(dai, substream);
+ bus = &data->adev->base.core;
+
+ host_stream = snd_hdac_ext_stream_assign(bus, substream, HDAC_EXT_STREAM_TYPE_HOST);
+ if (!host_stream) {
+ avs_dai_shutdown(substream, dai);
+ return -EBUSY;
+ }
+
+ data->host_stream = host_stream;
snd_pcm_set_sync(substream);
dev_dbg(dai->dev, "%s fe STARTUP tag %d str %p",
__func__, hdac_stream(host_stream)->stream_tag, substream);
return 0;
-
-err:
- kfree(data);
- return ret;
}
static void avs_dai_fe_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
--
2.25.1
next prev parent reply other threads:[~2024-04-26 9:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-26 9:57 [PATCH 0/8] ASoC: Intel: avs: PCM code cleanup Cezary Rojewski
2024-04-26 9:57 ` [PATCH 1/8] ASoC: pcm: Reverse iterate DAIs when shutting them down Cezary Rojewski
2024-04-26 9:57 ` [PATCH 2/8] ASoC: Intel: avs: Relocate HDA BE DAI specific operations Cezary Rojewski
2024-04-26 9:57 ` [PATCH 3/8] ASoC: Intel: avs: Remove redundancy around DAI shutdown Cezary Rojewski
2024-04-26 9:57 ` [PATCH 4/8] ASoC: Intel: avs: Store pointer to adev in DAI dma_data Cezary Rojewski
2024-04-26 9:57 ` [PATCH 5/8] ASoC: Intel: avs: Remove redundancy around DAI startup Cezary Rojewski
2024-04-26 9:57 ` [PATCH 6/8] ASoC: Intel: avs: Remove redundancy around DAI prepare Cezary Rojewski
2024-04-26 9:57 ` [PATCH 7/8] ASoC: Intel: avs: Store pointer to link_stream in dma_data Cezary Rojewski
2024-04-26 9:57 ` Cezary Rojewski [this message]
2024-05-01 13:43 ` [PATCH 0/8] ASoC: Intel: avs: PCM code cleanup Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240426095733.3946951-9-cezary.rojewski@intel.com \
--to=cezary.rojewski@intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=amadeuszx.slawinski@linux.intel.com \
--cc=broonie@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox