Skip to content

Commit b9a8ecf

Browse files
TE-N-ShengjiuWangbroonie
authored andcommitted
ASoC: fsl_micfil: Add sample rate constraint
On some platforms, for example i.MX93, there is only one audio PLL source, so some sample rate can't be supported. If the PLL source is used for 8kHz series rates, then 11kHz series rates can't be supported. So add constraints according to the frequency of available clock sources, then alsa-lib will help to convert the unsupported rate for the driver. Signed-off-by: Shengjiu Wang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 038fa6d commit b9a8ecf

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

sound/soc/fsl/fsl_micfil.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828

2929
#define MICFIL_OSR_DEFAULT 16
3030

31+
#define MICFIL_NUM_RATES 7
32+
#define MICFIL_CLK_SRC_NUM 3
33+
/* clock source ids */
34+
#define MICFIL_AUDIO_PLL1 0
35+
#define MICFIL_AUDIO_PLL2 1
36+
#define MICFIL_CLK_EXT3 2
37+
3138
enum quality {
3239
QUALITY_HIGH,
3340
QUALITY_MEDIUM,
@@ -45,9 +52,12 @@ struct fsl_micfil {
4552
struct clk *mclk;
4653
struct clk *pll8k_clk;
4754
struct clk *pll11k_clk;
55+
struct clk *clk_src[MICFIL_CLK_SRC_NUM];
4856
struct snd_dmaengine_dai_dma_data dma_params_rx;
4957
struct sdma_peripheral_config sdmacfg;
5058
struct snd_soc_card *card;
59+
struct snd_pcm_hw_constraint_list constraint_rates;
60+
unsigned int constraint_rates_list[MICFIL_NUM_RATES];
5161
unsigned int dataline;
5262
char name[32];
5363
int irq[MICFIL_IRQ_LINES];
@@ -475,12 +485,34 @@ static int fsl_micfil_startup(struct snd_pcm_substream *substream,
475485
struct snd_soc_dai *dai)
476486
{
477487
struct fsl_micfil *micfil = snd_soc_dai_get_drvdata(dai);
488+
unsigned int rates[MICFIL_NUM_RATES] = {8000, 11025, 16000, 22050, 32000, 44100, 48000};
489+
int i, j, k = 0;
490+
u64 clk_rate;
478491

479492
if (!micfil) {
480493
dev_err(dai->dev, "micfil dai priv_data not set\n");
481494
return -EINVAL;
482495
}
483496

497+
micfil->constraint_rates.list = micfil->constraint_rates_list;
498+
micfil->constraint_rates.count = 0;
499+
500+
for (j = 0; j < MICFIL_NUM_RATES; j++) {
501+
for (i = 0; i < MICFIL_CLK_SRC_NUM; i++) {
502+
clk_rate = clk_get_rate(micfil->clk_src[i]);
503+
if (clk_rate != 0 && do_div(clk_rate, rates[j]) == 0) {
504+
micfil->constraint_rates_list[k++] = rates[j];
505+
micfil->constraint_rates.count++;
506+
break;
507+
}
508+
}
509+
}
510+
511+
if (micfil->constraint_rates.count > 0)
512+
snd_pcm_hw_constraint_list(substream->runtime, 0,
513+
SNDRV_PCM_HW_PARAM_RATE,
514+
&micfil->constraint_rates);
515+
484516
return 0;
485517
}
486518

@@ -1175,6 +1207,12 @@ static int fsl_micfil_probe(struct platform_device *pdev)
11751207
fsl_asoc_get_pll_clocks(&pdev->dev, &micfil->pll8k_clk,
11761208
&micfil->pll11k_clk);
11771209

1210+
micfil->clk_src[MICFIL_AUDIO_PLL1] = micfil->pll8k_clk;
1211+
micfil->clk_src[MICFIL_AUDIO_PLL2] = micfil->pll11k_clk;
1212+
micfil->clk_src[MICFIL_CLK_EXT3] = devm_clk_get(&pdev->dev, "clkext3");
1213+
if (IS_ERR(micfil->clk_src[MICFIL_CLK_EXT3]))
1214+
micfil->clk_src[MICFIL_CLK_EXT3] = NULL;
1215+
11781216
/* init regmap */
11791217
regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
11801218
if (IS_ERR(regs))

0 commit comments

Comments
 (0)