diff mbox series

[02/14] ASoC: qcom: SC7280: audioreach: Add sc7280 hardware param fixup callback

Message ID 20230201134947.1638197-3-quic_mohs@quicinc.com (mailing list archive)
State Not Applicable
Headers show
Series Add support for compress offload and gapless playback. | expand

Commit Message

Mohammad Rafi Shaik Feb. 1, 2023, 1:49 p.m. UTC
Add support to set backend params such as sampling rate and
number of channels using backend params fixup callback.
Also remove hardware params constraints setting.

Signed-off-by: Mohammad Rafi Shaik <quic_mohs@quicinc.com>
Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 sound/soc/qcom/sc7280.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

Comments

Mark Brown Feb. 1, 2023, 2:40 p.m. UTC | #1
On Wed, Feb 01, 2023 at 07:19:35PM +0530, Mohammad Rafi Shaik wrote:

> +#define DEFAULT_SAMPLE_RATE_48K	48000

Why are we bothering with a define here given that the define also
encodes the value and it's only used in once place?

>  	for_each_card_prelinks(card, i, link) {
>  		link->init = sc7280_init;
>  		link->ops = &sc7280_ops;
> +		if (link->no_pcm == 1)
> +			link->be_hw_params_fixup = sc7280_snd_be_hw_params_fixup;

We only set the fixup in the case where there's no PCM but we removed
the constraint in all cases - isn't the constraint needed otherwise?
Mohammad Rafi Shaik Feb. 3, 2023, 6:33 a.m. UTC | #2
On 2/1/2023 8:10 PM, Mark Brown wrote:
> On Wed, Feb 01, 2023 at 07:19:35PM +0530, Mohammad Rafi Shaik wrote:
>
>> +#define DEFAULT_SAMPLE_RATE_48K	48000
> Why are we bothering with a define here given that the define also
> encodes the value and it's only used in once place?
okay, will remove it.
>
>>   	for_each_card_prelinks(card, i, link) {
>>   		link->init = sc7280_init;
>>   		link->ops = &sc7280_ops;
>> +		if (link->no_pcm == 1)
>> +			link->be_hw_params_fixup = sc7280_snd_be_hw_params_fixup;
> We only set the fixup in the case where there's no PCM but we removed
> the constraint in all cases - isn't the constraint needed otherwise?
okay, will add conditional check for constraint and will only do if 
no_pcm is zero.
diff mbox series

Patch

diff --git a/sound/soc/qcom/sc7280.c b/sound/soc/qcom/sc7280.c
index da7469a6a267..aaa95fe63d83 100644
--- a/sound/soc/qcom/sc7280.c
+++ b/sound/soc/qcom/sc7280.c
@@ -14,6 +14,7 @@ 
 #include <sound/soc.h>
 #include <sound/rt5682s.h>
 #include <linux/soundwire/sdw.h>
+#include <sound/pcm_params.h>
 
 #include "../codecs/rt5682.h"
 #include "../codecs/rt5682s.h"
@@ -24,6 +25,7 @@ 
 #define DEFAULT_MCLK_RATE              19200000
 #define RT5682_PLL_FREQ (48000 * 512)
 #define MI2S_BCLK_RATE		1536000
+#define DEFAULT_SAMPLE_RATE_48K	48000
 
 struct sc7280_snd_data {
 	struct snd_soc_card card;
@@ -188,7 +190,6 @@  static int sc7280_init(struct snd_soc_pcm_runtime *rtd)
 static int sc7280_snd_hw_params(struct snd_pcm_substream *substream,
 				struct snd_pcm_hw_params *params)
 {
-	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_dai *codec_dai;
 	const struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
@@ -196,8 +197,6 @@  static int sc7280_snd_hw_params(struct snd_pcm_substream *substream,
 	struct sdw_stream_runtime *sruntime;
 	int i;
 
-	snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2);
-	snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE, 48000, 48000);
 
 	switch (cpu_dai->id) {
 	case LPASS_CDC_DMA_TX3:
@@ -358,6 +357,20 @@  static const struct snd_soc_dapm_widget sc7280_snd_widgets[] = {
 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
 };
 
+static int sc7280_snd_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
+					 struct snd_pcm_hw_params *params)
+{
+	struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+	struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
+
+	rate->min = rate->max = DEFAULT_SAMPLE_RATE_48K;
+	channels->min = channels->max = 2;
+	snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
+
+	return 0;
+}
+
 static int sc7280_snd_platform_probe(struct platform_device *pdev)
 {
 	struct snd_soc_card *card;
@@ -387,6 +400,8 @@  static int sc7280_snd_platform_probe(struct platform_device *pdev)
 	for_each_card_prelinks(card, i, link) {
 		link->init = sc7280_init;
 		link->ops = &sc7280_ops;
+		if (link->no_pcm == 1)
+			link->be_hw_params_fixup = sc7280_snd_be_hw_params_fixup;
 	}
 
 	return devm_snd_soc_register_card(dev, card);