Skip to content

Commit f3da7f1

Browse files
xlnx-hyunkwonMichal Simek
authored and
Michal Simek
committed
sound: soc: xilinx: Call set_rate()
Instead of using the given clock rate, this patch is trying to set the clock rate to specific audio frequency. With this patch, the clock frequency doesn't have to be preconfigured to specific frequency. Signed-off-by: Hyun Kwon <[email protected]> Signed-off-by: Michal Simek <[email protected]>
1 parent 0934f2c commit f3da7f1

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

sound/soc/xilinx/xilinx-dp-codec.c

+36-9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ struct xilinx_dp_codec {
3030
struct clk *aud_clk;
3131
};
3232

33+
struct xilinx_dp_codec_fmt {
34+
unsigned long rate;
35+
unsigned int snd_rate;
36+
};
37+
3338
static struct snd_soc_dai_driver xilinx_dp_codec_dai = {
3439
.name = "xilinx-dp-snd-codec-dai",
3540
.playback = {
@@ -40,13 +45,26 @@ static struct snd_soc_dai_driver xilinx_dp_codec_dai = {
4045
},
4146
};
4247

48+
static const struct xilinx_dp_codec_fmt rates[] = {
49+
{
50+
.rate = 48000 * 512,
51+
.snd_rate = SNDRV_PCM_RATE_48000
52+
},
53+
{
54+
.rate = 44100 * 512,
55+
.snd_rate = SNDRV_PCM_RATE_44100
56+
}
57+
};
58+
4359
static const struct snd_soc_codec_driver xilinx_dp_codec_codec_driver = {
4460
};
4561

4662
static int xilinx_dp_codec_probe(struct platform_device *pdev)
4763
{
4864
struct xilinx_dp_codec *codec;
49-
int rate, ret;
65+
unsigned int i;
66+
unsigned long rate;
67+
int ret;
5068

5169
codec = devm_kzalloc(&pdev->dev, sizeof(*codec), GFP_KERNEL);
5270
if (!codec)
@@ -62,15 +80,24 @@ static int xilinx_dp_codec_probe(struct platform_device *pdev)
6280
return ret;
6381
}
6482

65-
rate = clk_get_rate(codec->aud_clk) / 512;
66-
/* Ignore some offset */
67-
rate = ALIGN(rate, 100);
68-
if (rate == 44100) {
69-
xilinx_dp_codec_dai.playback.rates = SNDRV_PCM_RATE_44100;
70-
} else if (rate == 48000) {
71-
xilinx_dp_codec_dai.playback.rates = SNDRV_PCM_RATE_48000;
72-
} else {
83+
for (i = 0; i < ARRAY_SIZE(rates); i++) {
84+
clk_disable_unprepare(codec->aud_clk);
85+
ret = clk_set_rate(codec->aud_clk, rates[i].rate);
86+
clk_prepare_enable(codec->aud_clk);
87+
if (ret)
88+
continue;
89+
90+
rate = clk_get_rate(codec->aud_clk);
91+
/* Ignore some offset +- 10 */
92+
if (abs(rates[i].rate - rate) < 10) {
93+
xilinx_dp_codec_dai.playback.rates = rates[i].snd_rate;
94+
break;
95+
}
7396
ret = -EINVAL;
97+
}
98+
99+
if (ret) {
100+
dev_err(&pdev->dev, "Failed to get required clock freq\n");
74101
goto error_clk;
75102
}
76103

0 commit comments

Comments
 (0)