ASoC: qcom: sdw: Add TDM support
Subsystems (3)
RFC PATCH v2 1/2 ASoC: qcom: sdw: Add TDM support
Add qcom TDM setup function to support TDM ports for qcom platform.
---
Changes in v2:
1. remove EXPORT_SYMBOL_GPL
2. remove static modifier
sound/soc/qcom/sdw.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
sound/soc/qcom/sdw.c +63 -0
@@ -4,6 +4,7 @@#include <dt-bindings/sound/qcom,q6afe.h> #include <linux/module.h> +#include <sound/pcm_params.h> #include <sound/soc.h> #include "sdw.h"
@@ -101,6 +102,65 @@ int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, }EXPORT_SYMBOL_GPL (qcom_snd_sdw_prepare); +int qcom_snd_tdm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); +unsigned int tdm_slot_offset[8 ] = {0 ,4 ,8 ,12 ,16 ,20 ,24 ,28 }; +int channels, slot_width; +int ret; + +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : + slot_width =16 ; +break ; +case SNDRV_PCM_FORMAT_S24_LE : + slot_width =24 ; +break ; +case SNDRV_PCM_FORMAT_S32_LE : + slot_width =32 ; +break ; +default : +dev_err (rtd->dev,"%s: invalid param format 0x%x\n" , __func__, +params_format (params)); +return -EINVAL ; + } + + channels =params_channels (params); +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { + ret =snd_soc_dai_set_tdm_slot (cpu_dai,0 ,0x3 ,8 , slot_width); +if (ret <0 ) { +dev_err (rtd->dev,"%s: failed to set tdm slot, err:%d\n" , + __func__, ret); +return ret; + } + + ret =snd_soc_dai_set_channel_map (cpu_dai,0 ,NULL , channels, + tdm_slot_offset); +if (ret <0 ) { +dev_err (rtd->dev,"%s: failed to set channel map, err:%d\n" , + __func__, ret); +return ret; + } + }else { + ret =snd_soc_dai_set_tdm_slot (cpu_dai,0xf ,0 ,8 , slot_width); +if (ret <0 ) { +dev_err (rtd->dev,"%s: failed to set tdm slot, err:%d\n" , + __func__, ret); +return ret; + } + + ret =snd_soc_dai_set_channel_map (cpu_dai, channels, + tdm_slot_offset,0 ,NULL ); +if (ret <0 ) { +dev_err (rtd->dev,"%s: failed to set channel map, err:%d\n" , + __func__, ret); +return ret; + } + } +} +int qcom_snd_sdw_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params,struct sdw_stream_runtime **psruntime)
@@ -125,6 +185,9 @@ int qcom_snd_sdw_hw_params(struct snd_pcm_substream *substream, *psruntime = sruntime; }break ; + case PRIMARY_TDM_RX_0...QUINARY_TDM_TX_7: +qcom_snd_tdm_hw_params (substream, params); +break ; }return 0 ;
Signature · 1 line
2.41.0
RFC PATCH v2 2/2 ASoC: qcom: sm8250: Add TERTIARY_TDM_RX_0 support
Add TERTIARY_TDM_RX_0 case to make speaker amplifiers working on xiaomi-elish tablet.
---
No changes in v2.
sound/soc/qcom/sm8250.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
sound/soc/qcom/sm8250.c +19 -0
@@ -16,6 +16,7 @@#define DRIVER_NAME "sm8250"#define MI2S_BCLK_RATE 1536000 +#define TDM_BCLK_RATE 12288000struct sm8250_snd_data {bool stream_prepared[AFE_PORT_MAX ];
@@ -53,6 +54,7 @@ static int sm8250_snd_startup(struct snd_pcm_substream *substream)struct snd_soc_pcm_runtime *rtd = substream->private_data;struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 );struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtd,0 ); +int ret, j;switch (cpu_dai->id) {case TERTIARY_MI2S_RX :
@@ -63,6 +65,23 @@ static int sm8250_snd_startup(struct snd_pcm_substream *substream)snd_soc_dai_set_fmt (cpu_dai, fmt);snd_soc_dai_set_fmt (codec_dai, codec_dai_fmt);break ; +case TERTIARY_TDM_RX_0 : + codec_dai_fmt |=SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_DSP_A ; +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_TER_TDM_IBIT , +TDM_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); + +for_each_rtd_codec_dais (rtd, j, codec_dai) { + ret =snd_soc_dai_set_fmt (codec_dai, codec_dai_fmt); +snd_soc_dai_set_sysclk (codec_dai, +0 , +TDM_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); +if (ret <0 ) { +dev_err (rtd->dev,"TDM fmt err:%d\n" , ret); +return ret; + } + } +break ;default :break ; }
Signature · 1 line
2.41.0
Thankyou for the patch,
Quoted 24 lines · Jianhua Lu
Add qcom TDM setup function to support TDM ports for qcom platform.
Signed-off-by Jianhua Lu <[email protected]>---
Changes in v2:
1. removeEXPORT_SYMBOL_GPL
2. remove static modifiersound/soc/qcom/sdw.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)sound/soc/qcom/sdw.c +1
-0@@ -4,6 +4,7 @@#include <dt-bindings/sound/qcom,q6afe.h> #include <linux/module.h> +#include <sound/pcm_params.h> #include <sound/soc.h> #include "sdw.h"
sound/soc/qcom/sdw.c int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, · line 107
Quoted 6 lines
sound/soc/qcom/sdw.c +3
-0@@ -101,6 +102,65 @@ int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, }EXPORT_SYMBOL_GPL (qcom_snd_sdw_prepare); +int qcom_snd_tdm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{
TBH, this should not be part of sdw.c file, its intended for more of soundwire specific helpers, pl consider moving this to common.c for now. Because, Not all old qcom platforms have soundwire controllers.
Quoted 15 lines
sound/soc/qcom/sdw.c +15
-0+struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); +unsigned int tdm_slot_offset[8 ] = {0 ,4 ,8 ,12 ,16 ,20 ,24 ,28 }; +int channels, slot_width; +int ret; + +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : + slot_width =16 ; +break ; +case SNDRV_PCM_FORMAT_S24_LE : + slot_width =24 ; +break ; +case SNDRV_PCM_FORMAT_S32_LE : + slot_width =32 ;
sound/soc/qcom/sdw.c int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, · line 132
Quoted 10 lines
sound/soc/qcom/sdw.c +10
-0+break ; +default : +dev_err (rtd->dev,"%s: invalid param format 0x%x\n" , __func__, +params_format (params)); +return -EINVAL ; + } + + channels =params_channels (params); +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { + ret =snd_soc_dai_set_tdm_slot (cpu_dai,0 ,0x3 ,8 , slot_width);
slot mask is always set to 2 channels in this case, should you not check the number of channels to determine the correct one?
These magic number 0, 0x3, 8 seems to make the code unreadable, can you do something like this:snd_soc_dai_set_tdm_slot(cpu_dai, tx_mask, rx_mask, ARRAY_SIZE(tdm_slot_offset), slot_width);
Quoted 19 lines
sound/soc/qcom/sdw.c +19
-0+if (ret <0 ) { +dev_err (rtd->dev,"%s: failed to set tdm slot, err:%d\n" , + __func__, ret); +return ret; + } + + ret =snd_soc_dai_set_channel_map (cpu_dai,0 ,NULL , channels, + tdm_slot_offset); +if (ret <0 ) { +dev_err (rtd->dev,"%s: failed to set channel map, err:%d\n" , + __func__, ret); +return ret; + } + }else { + ret =snd_soc_dai_set_tdm_slot (cpu_dai,0xf ,0 ,8 , slot_width); +if (ret <0 ) { +dev_err (rtd->dev,"%s: failed to set tdm slot, err:%d\n" , + __func__, ret); +return ret;
sound/soc/qcom/sdw.c int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, · line 161
Quoted 10 lines
sound/soc/qcom/sdw.c +10
-0+ } + + ret =snd_soc_dai_set_channel_map (cpu_dai, channels, + tdm_slot_offset,0 ,NULL ); +if (ret <0 ) { +dev_err (rtd->dev,"%s: failed to set channel map, err:%d\n" , + __func__, ret); +return ret; + } + }
Finally ./sound/soc/qcom/sdm845.c does have exactly same code, can you consider removing this and make use of this new helper in that file too.
Quoted 15 lines
sound/soc/qcom/sdw.c +5
-0+} +int qcom_snd_sdw_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params,struct sdw_stream_runtime **psruntime)@@ -125,6 +185,9 @@ int qcom_snd_sdw_hw_params(struct snd_pcm_substream *substream, *psruntime = sruntime; }break ; + case PRIMARY_TDM_RX_0...QUINARY_TDM_TX_7: +qcom_snd_tdm_hw_params (substream, params); +break ; }return 0 ;
Quoted 7 lines · Srinivas Kandagatla
sound/soc/qcom/sdw.c int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, · line 107
Quoted 3 lines
sound/soc/qcom/sdw.c +3
-0+int qcom_snd_tdm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{TBH, this should not be part of
sdw.cfile, its intended for more of soundwire specific helpers, pl consider moving this tocommon.cfor now. Because, Not all old qcom platforms have soundwire controllers.
Acked.
Quoted 11 lines
sound/soc/qcom/sdw.c int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, · line 132
Quoted 2 lines
sound/soc/qcom/sdw.c +1
-0+ ret =snd_soc_dai_set_tdm_slot (cpu_dai,0 ,0x3 ,8 , slot_width);slot mask is always set to 2 channels in this case, should you not check the number of channels to determine the correct one?
These magic number 0,
0x3, 8 seems to make the code unreadable, can you do something like this:snd_soc_dai_set_tdm_slot(cpu_dai, tx_mask, rx_mask, ARRAY_SIZE(tdm_slot_offset), slot_width);
Acked.
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ } + }Finally
./sound/soc/qcom/sdm845.cdoes have exactly same code, can you consider removing this and make use of this new helper in that file too.
Acked.
Thanks for your reveiw very much, I will do it in patch v3.
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Jianhua,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on linus/master v6.7-rc5 next-20231214] [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/Jianhua-Lu/ASoC-qcom-sm8250-Add-TERTIARY_TDM_RX_0-support/20231212-180109 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next patch link: https://lore.kernel.org/r/20231212095850.26482-1-lujianhua000%40gmail.com patch subject: [RFC, PATCH v2 1/2] ASoC: qcom: sdw: Add TDM support config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20231215/[email protected]/config) compiler: s390-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231215/[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/soc/qcom/sdw.c:105:5: warning: no previous prototype for 'qcom_snd_tdm_hw_params' [-Wmissing-prototypes]
105 | int qcom_snd_tdm_hw_params(struct snd_pcm_substream *substream,
| ^~~~~~~~~~~~~~~~~~~~~~
sound/soc/qcom/sdw.c: In function 'qcom_snd_tdm_hw_params':
>> sound/soc/qcom/sdw.c:162:1: warning: control reaches end of non-void function [-Wreturn-type]
162 | }
| ^vim +/qcom_snd_tdm_hw_params +105 sound/soc/qcom/sdw.c
104
> 105 int qcom_snd_tdm_hw_params(struct snd_pcm_substream *substream,
106 struct snd_pcm_hw_params *params)
107 {
108 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
109 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
110 unsigned int tdm_slot_offset[8] = { 0, 4, 8, 12, 16, 20, 24, 28 };
111 int channels, slot_width;
112 int ret;
113
114 switch (params_format(params)) {
115 case SNDRV_PCM_FORMAT_S16_LE:
116 slot_width = 16;
117 break;
118 case SNDRV_PCM_FORMAT_S24_LE:
119 slot_width = 24;
120 break;
121 case SNDRV_PCM_FORMAT_S32_LE:
122 slot_width = 32;
123 break;
124 default:
125 dev_err(rtd->dev, "%s: invalid param format 0x%x\n", __func__,
126 params_format(params));
127 return -EINVAL;
128 }
129
130 channels = params_channels(params);
131 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
132 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, 0x3, 8, slot_width);
133 if (ret < 0) {
134 dev_err(rtd->dev, "%s: failed to set tdm slot, err:%d\n",
135 __func__, ret);
136 return ret;
137 }
138
139 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL, channels,
140 tdm_slot_offset);
141 if (ret < 0) {
142 dev_err(rtd->dev, "%s: failed to set channel map, err:%d\n",
143 __func__, ret);
144 return ret;
145 }
146 } else {
147 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xf, 0, 8, slot_width);
148 if (ret < 0) {
149 dev_err(rtd->dev, "%s: failed to set tdm slot, err:%d\n",
150 __func__, ret);
151 return ret;
152 }
153
154 ret = snd_soc_dai_set_channel_map(cpu_dai, channels,
155 tdm_slot_offset, 0, NULL);
156 if (ret < 0) {
157 dev_err(rtd->dev, "%s: failed to set channel map, err:%d\n",
158 __func__, ret);
159 return ret;
160 }
161 }
> 162 }163
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki