Skip to content

Commit 59c6a3a

Browse files
jbrun3tbroonie
authored andcommitted
ASoC: meson: axg-tdm-interface: add frame rate constraint
According to Amlogic datasheets for the SoCs supported by this driver, the maximum bit clock rate is 100MHz. The tdm interface allows the rates listed by the DAI driver, regardless of the number slots or their width. However, these will impact the bit clock rate. Hitting the 100MHz limit is very unlikely for most use cases but it is possible. For example with 32 slots / 32 bits wide, the maximum rate is no longer 384kHz but ~96kHz. Add the constraint accordingly if the component is not already active. If it is active, the rate is already constrained by the first stream rate. Fixes: d60e4f1 ("ASoC: meson: add tdm interface driver") Signed-off-by: Jerome Brunet <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent e3741a8 commit 59c6a3a

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

sound/soc/meson/axg-tdm-interface.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#include "axg-tdm.h"
1414

15+
/* Maximum bit clock frequency according the datasheets */
16+
#define MAX_SCLK 100000000 /* Hz */
17+
1518
enum {
1619
TDM_IFACE_PAD,
1720
TDM_IFACE_LOOPBACK,
@@ -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

171182
static int axg_tdm_iface_set_stream(struct snd_pcm_substream *substream,

0 commit comments

Comments
 (0)