2 * smdk_spdif.c -- S/PDIF audio for SMDK
4 * Copyright 2010 Samsung Electronics Co. Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
13 #include <linux/clk.h>
15 #include <sound/soc.h>
19 /* Audio clock settings are belonged to board specific part. Every
20 * board can set audio source clock setting which is matched with H/W
21 * like this function-'set_audio_clock_heirachy'.
23 static int set_audio_clock_heirachy(struct platform_device
*pdev
)
25 struct clk
*fout_epll
, *mout_epll
, *sclk_audio0
, *sclk_spdif
;
28 fout_epll
= clk_get(NULL
, "fout_epll");
29 if (IS_ERR(fout_epll
)) {
30 printk(KERN_WARNING
"%s: Cannot find fout_epll.\n",
35 mout_epll
= clk_get(NULL
, "mout_epll");
36 if (IS_ERR(mout_epll
)) {
37 printk(KERN_WARNING
"%s: Cannot find mout_epll.\n",
43 sclk_audio0
= clk_get(&pdev
->dev
, "sclk_audio");
44 if (IS_ERR(sclk_audio0
)) {
45 printk(KERN_WARNING
"%s: Cannot find sclk_audio.\n",
51 sclk_spdif
= clk_get(NULL
, "sclk_spdif");
52 if (IS_ERR(sclk_spdif
)) {
53 printk(KERN_WARNING
"%s: Cannot find sclk_spdif.\n",
59 /* Set audio clock hierarchy for S/PDIF */
60 clk_set_parent(mout_epll
, fout_epll
);
61 clk_set_parent(sclk_audio0
, mout_epll
);
62 clk_set_parent(sclk_spdif
, sclk_audio0
);
75 /* We should haved to set clock directly on this part because of clock
76 * scheme of Samsudng SoCs did not support to set rates from abstrct
77 * clock of it's hierarchy.
79 static int set_audio_clock_rate(unsigned long epll_rate
,
80 unsigned long audio_rate
)
82 struct clk
*fout_epll
, *sclk_spdif
;
84 fout_epll
= clk_get(NULL
, "fout_epll");
85 if (IS_ERR(fout_epll
)) {
86 printk(KERN_ERR
"%s: failed to get fout_epll\n", __func__
);
90 clk_set_rate(fout_epll
, epll_rate
);
93 sclk_spdif
= clk_get(NULL
, "sclk_spdif");
94 if (IS_ERR(sclk_spdif
)) {
95 printk(KERN_ERR
"%s: failed to get sclk_spdif\n", __func__
);
99 clk_set_rate(sclk_spdif
, audio_rate
);
105 static int smdk_hw_params(struct snd_pcm_substream
*substream
,
106 struct snd_pcm_hw_params
*params
)
108 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
109 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
110 unsigned long pll_out
, rclk_rate
;
113 switch (params_rate(params
)) {
126 /* Setting ratio to 512fs helps to use S/PDIF with HDMI without
127 * modify S/PDIF ASoC machine driver.
130 rclk_rate
= params_rate(params
) * ratio
;
132 /* Set audio source clock rates */
133 ret
= set_audio_clock_rate(pll_out
, rclk_rate
);
137 /* Set S/PDIF uses internal source clock */
138 ret
= snd_soc_dai_set_sysclk(cpu_dai
, SND_SOC_SPDIF_INT_MCLK
,
139 rclk_rate
, SND_SOC_CLOCK_IN
);
146 static struct snd_soc_ops smdk_spdif_ops
= {
147 .hw_params
= smdk_hw_params
,
150 static struct snd_soc_dai_link smdk_dai
= {
152 .stream_name
= "S/PDIF PCM Playback",
153 .platform_name
= "samsung-audio",
154 .cpu_dai_name
= "samsung-spdif",
155 .codec_dai_name
= "dit-hifi",
156 .codec_name
= "spdif-dit",
157 .ops
= &smdk_spdif_ops
,
160 static struct snd_soc_card smdk
= {
161 .name
= "SMDK-S/PDIF",
162 .dai_link
= &smdk_dai
,
166 static struct platform_device
*smdk_snd_spdif_dit_device
;
167 static struct platform_device
*smdk_snd_spdif_device
;
169 static int __init
smdk_init(void)
173 smdk_snd_spdif_dit_device
= platform_device_alloc("spdif-dit", -1);
174 if (!smdk_snd_spdif_dit_device
)
177 ret
= platform_device_add(smdk_snd_spdif_dit_device
);
181 smdk_snd_spdif_device
= platform_device_alloc("soc-audio", -1);
182 if (!smdk_snd_spdif_device
) {
187 platform_set_drvdata(smdk_snd_spdif_device
, &smdk
);
189 ret
= platform_device_add(smdk_snd_spdif_device
);
193 /* Set audio clock hierarchy manually */
194 ret
= set_audio_clock_heirachy(smdk_snd_spdif_device
);
200 platform_device_del(smdk_snd_spdif_device
);
202 platform_device_put(smdk_snd_spdif_device
);
204 platform_device_del(smdk_snd_spdif_dit_device
);
206 platform_device_put(smdk_snd_spdif_dit_device
);
210 static void __exit
smdk_exit(void)
212 platform_device_unregister(smdk_snd_spdif_device
);
213 platform_device_unregister(smdk_snd_spdif_dit_device
);
216 module_init(smdk_init
);
217 module_exit(smdk_exit
);
219 MODULE_AUTHOR("Seungwhan Youn, <sw.youn@samsung.com>");
220 MODULE_DESCRIPTION("ALSA SoC SMDK+S/PDIF");
221 MODULE_LICENSE("GPL");