Skip to content

Commit 3a5d89a

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: cs42l42: Constrain sample rate to prevent illegal SCLK
The lowest valid SCLK corresponds to 44.1 kHz at 16-bit. Sample rates less than this would produce SCLK below the minimum when using a normal I2S frame. A constraint must be applied to prevent this. The constraint is not applied if the machine driver sets SCLK, to allow setups where the host generates additional bits per LRCLK phase to increase the SCLK frequency. In these cases the machine driver would always have to inform this driver of the actual SCLK, and it must select a legal SCLK. Signed-off-by: Richard Fitzgerald <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 0c2f2ad commit 3a5d89a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

sound/soc/codecs/cs42l42.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,25 @@ static int cs42l42_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
807807
return 0;
808808
}
809809

810+
static int cs42l42_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
811+
{
812+
struct snd_soc_component *component = dai->component;
813+
struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(component);
814+
815+
/*
816+
* Sample rates < 44.1 kHz would produce an out-of-range SCLK with
817+
* a standard I2S frame. If the machine driver sets SCLK it must be
818+
* legal.
819+
*/
820+
if (cs42l42->sclk)
821+
return 0;
822+
823+
/* Machine driver has not set a SCLK, limit bottom end to 44.1 kHz */
824+
return snd_pcm_hw_constraint_minmax(substream->runtime,
825+
SNDRV_PCM_HW_PARAM_RATE,
826+
44100, 192000);
827+
}
828+
810829
static int cs42l42_pcm_hw_params(struct snd_pcm_substream *substream,
811830
struct snd_pcm_hw_params *params,
812831
struct snd_soc_dai *dai)
@@ -966,8 +985,8 @@ static int cs42l42_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
966985
SNDRV_PCM_FMTBIT_S24_LE |\
967986
SNDRV_PCM_FMTBIT_S32_LE )
968987

969-
970988
static const struct snd_soc_dai_ops cs42l42_ops = {
989+
.startup = cs42l42_dai_startup,
971990
.hw_params = cs42l42_pcm_hw_params,
972991
.set_fmt = cs42l42_set_dai_fmt,
973992
.set_sysclk = cs42l42_set_sysclk,

0 commit comments

Comments
 (0)