1 // SPDX-License-Identifier: GPL-2.0+
3 // smdk_spdif.c - S/PDIF audio for SMDK
5 // Copyright (C) 2010 Samsung Electronics Co., Ltd.
8 #include <linux/module.h>
10 #include <sound/soc.h>
14 /* Audio clock settings are belonged to board specific part. Every
15 * board can set audio source clock setting which is matched with H/W
16 * like this function-'set_audio_clock_heirachy'.
18 static int set_audio_clock_heirachy(struct platform_device
*pdev
)
20 struct clk
*fout_epll
, *mout_epll
, *sclk_audio0
, *sclk_spdif
;
23 fout_epll
= clk_get(NULL
, "fout_epll");
24 if (IS_ERR(fout_epll
)) {
25 printk(KERN_WARNING
"%s: Cannot find fout_epll.\n",
30 mout_epll
= clk_get(NULL
, "mout_epll");
31 if (IS_ERR(mout_epll
)) {
32 printk(KERN_WARNING
"%s: Cannot find mout_epll.\n",
38 sclk_audio0
= clk_get(&pdev
->dev
, "sclk_audio");
39 if (IS_ERR(sclk_audio0
)) {
40 printk(KERN_WARNING
"%s: Cannot find sclk_audio.\n",
46 sclk_spdif
= clk_get(NULL
, "sclk_spdif");
47 if (IS_ERR(sclk_spdif
)) {
48 printk(KERN_WARNING
"%s: Cannot find sclk_spdif.\n",
54 /* Set audio clock hierarchy for S/PDIF */
55 clk_set_parent(mout_epll
, fout_epll
);
56 clk_set_parent(sclk_audio0
, mout_epll
);
57 clk_set_parent(sclk_spdif
, sclk_audio0
);
70 /* We should haved to set clock directly on this part because of clock
71 * scheme of Samsudng SoCs did not support to set rates from abstrct
72 * clock of it's hierarchy.
74 static int set_audio_clock_rate(unsigned long epll_rate
,
75 unsigned long audio_rate
)
77 struct clk
*fout_epll
, *sclk_spdif
;
79 fout_epll
= clk_get(NULL
, "fout_epll");
80 if (IS_ERR(fout_epll
)) {
81 printk(KERN_ERR
"%s: failed to get fout_epll\n", __func__
);
85 clk_set_rate(fout_epll
, epll_rate
);
88 sclk_spdif
= clk_get(NULL
, "sclk_spdif");
89 if (IS_ERR(sclk_spdif
)) {
90 printk(KERN_ERR
"%s: failed to get sclk_spdif\n", __func__
);
94 clk_set_rate(sclk_spdif
, audio_rate
);
100 static int smdk_hw_params(struct snd_pcm_substream
*substream
,
101 struct snd_pcm_hw_params
*params
)
103 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
104 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
105 unsigned long pll_out
, rclk_rate
;
108 switch (params_rate(params
)) {
121 /* Setting ratio to 512fs helps to use S/PDIF with HDMI without
122 * modify S/PDIF ASoC machine driver.
125 rclk_rate
= params_rate(params
) * ratio
;
127 /* Set audio source clock rates */
128 ret
= set_audio_clock_rate(pll_out
, rclk_rate
);
132 /* Set S/PDIF uses internal source clock */
133 ret
= snd_soc_dai_set_sysclk(cpu_dai
, SND_SOC_SPDIF_INT_MCLK
,
134 rclk_rate
, SND_SOC_CLOCK_IN
);
141 static const struct snd_soc_ops smdk_spdif_ops
= {
142 .hw_params
= smdk_hw_params
,
145 SND_SOC_DAILINK_DEFS(spdif
,
146 DAILINK_COMP_ARRAY(COMP_CPU("samsung-spdif")),
147 DAILINK_COMP_ARRAY(COMP_CODEC("spdif-dit", "dit-hifi")),
148 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-spdif")));
150 static struct snd_soc_dai_link smdk_dai
= {
152 .stream_name
= "S/PDIF PCM Playback",
153 .ops
= &smdk_spdif_ops
,
154 SND_SOC_DAILINK_REG(spdif
),
157 static struct snd_soc_card smdk
= {
158 .name
= "SMDK-S/PDIF",
159 .owner
= THIS_MODULE
,
160 .dai_link
= &smdk_dai
,
164 static struct platform_device
*smdk_snd_spdif_dit_device
;
165 static struct platform_device
*smdk_snd_spdif_device
;
167 static int __init
smdk_init(void)
171 smdk_snd_spdif_dit_device
= platform_device_alloc("spdif-dit", -1);
172 if (!smdk_snd_spdif_dit_device
)
175 ret
= platform_device_add(smdk_snd_spdif_dit_device
);
179 smdk_snd_spdif_device
= platform_device_alloc("soc-audio", -1);
180 if (!smdk_snd_spdif_device
) {
185 platform_set_drvdata(smdk_snd_spdif_device
, &smdk
);
187 ret
= platform_device_add(smdk_snd_spdif_device
);
191 /* Set audio clock hierarchy manually */
192 ret
= set_audio_clock_heirachy(smdk_snd_spdif_device
);
198 platform_device_del(smdk_snd_spdif_device
);
200 platform_device_put(smdk_snd_spdif_device
);
202 platform_device_del(smdk_snd_spdif_dit_device
);
204 platform_device_put(smdk_snd_spdif_dit_device
);
208 static void __exit
smdk_exit(void)
210 platform_device_unregister(smdk_snd_spdif_device
);
211 platform_device_unregister(smdk_snd_spdif_dit_device
);
214 module_init(smdk_init
);
215 module_exit(smdk_exit
);
217 MODULE_AUTHOR("Seungwhan Youn, <sw.youn@samsung.com>");
218 MODULE_DESCRIPTION("ALSA SoC SMDK+S/PDIF");
219 MODULE_LICENSE("GPL");