1212
1313#include "axg-tdm.h"
1414
15+ /* Maximum bit clock frequency according the datasheets */
16+ #define MAX_SCLK 100000000 /* Hz */
17+
1518enum {
1619 TDM_IFACE_PAD ,
1720 TDM_IFACE_LOOPBACK ,
@@ -130,7 +133,7 @@ static int axg_tdm_iface_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
130133
131134 case SND_SOC_DAIFMT_BP_FC :
132135 case SND_SOC_DAIFMT_BC_FP :
133- dev_err (dai -> dev , "only CBS_CFS and CBM_CFM are supported\n" );
136+ dev_err (dai -> dev , "only BP_FP and BC_FC are supported\n" );
134137 fallthrough ;
135138 default :
136139 return - EINVAL ;
@@ -153,19 +156,27 @@ static int axg_tdm_iface_startup(struct snd_pcm_substream *substream,
153156 return - EINVAL ;
154157 }
155158
156- /* Apply component wide rate symmetry */
157159 if (snd_soc_component_active (dai -> component )) {
160+ /* Apply component wide rate symmetry */
158161 ret = snd_pcm_hw_constraint_single (substream -> runtime ,
159162 SNDRV_PCM_HW_PARAM_RATE ,
160163 iface -> rate );
161- if (ret < 0 ) {
162- dev_err (dai -> dev ,
163- "can't set iface rate constraint\n" );
164- return ret ;
165- }
164+
165+ } else {
166+ /* Limit rate according to the slot number and width */
167+ unsigned int max_rate =
168+ MAX_SCLK / (iface -> slots * iface -> slot_width );
169+ ret = snd_pcm_hw_constraint_minmax (substream -> runtime ,
170+ SNDRV_PCM_HW_PARAM_RATE ,
171+ 0 , max_rate );
166172 }
167173
168- return 0 ;
174+ if (ret < 0 )
175+ dev_err (dai -> dev , "can't set iface rate constraint\n" );
176+ else
177+ ret = 0 ;
178+
179+ return ret ;
169180}
170181
171182static int axg_tdm_iface_set_stream (struct snd_pcm_substream * substream ,
@@ -264,8 +275,8 @@ static int axg_tdm_iface_set_sclk(struct snd_soc_dai *dai,
264275 srate = iface -> slots * iface -> slot_width * params_rate (params );
265276
266277 if (!iface -> mclk_rate ) {
267- /* If no specific mclk is requested, default to bit clock * 4 */
268- clk_set_rate (iface -> mclk , 4 * srate );
278+ /* If no specific mclk is requested, default to bit clock * 2 */
279+ clk_set_rate (iface -> mclk , 2 * srate );
269280 } else {
270281 /* Check if we can actually get the bit clock from mclk */
271282 if (iface -> mclk_rate % srate ) {
0 commit comments