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/module.h>
14 #include <linux/device.h>
15 #include <linux/clk.h>
17 #include <plat/devs.h>
19 #include <sound/soc.h>
24 /* Audio clock settings are belonged to board specific part. Every
25 * board can set audio source clock setting which is matched with H/W
26 * like this function-'set_audio_clock_heirachy'.
28 static int set_audio_clock_heirachy(struct platform_device
*pdev
)
30 struct clk
*fout_epll
, *mout_epll
, *sclk_audio0
, *sclk_spdif
;
33 fout_epll
= clk_get(NULL
, "fout_epll");
34 if (IS_ERR(fout_epll
)) {
35 printk(KERN_WARNING
"%s: Cannot find fout_epll.\n",
40 mout_epll
= clk_get(NULL
, "mout_epll");
41 if (IS_ERR(mout_epll
)) {
42 printk(KERN_WARNING
"%s: Cannot find mout_epll.\n",
48 sclk_audio0
= clk_get(&pdev
->dev
, "sclk_audio");
49 if (IS_ERR(sclk_audio0
)) {
50 printk(KERN_WARNING
"%s: Cannot find sclk_audio.\n",
56 sclk_spdif
= clk_get(NULL
, "sclk_spdif");
57 if (IS_ERR(sclk_spdif
)) {
58 printk(KERN_WARNING
"%s: Cannot find sclk_spdif.\n",
64 /* Set audio clock hierarchy for S/PDIF */
65 clk_set_parent(mout_epll
, fout_epll
);
66 clk_set_parent(sclk_audio0
, mout_epll
);
67 clk_set_parent(sclk_spdif
, sclk_audio0
);
80 /* We should haved to set clock directly on this part because of clock
81 * scheme of Samsudng SoCs did not support to set rates from abstrct
82 * clock of it's hierarchy.
84 static int set_audio_clock_rate(unsigned long epll_rate
,
85 unsigned long audio_rate
)
87 struct clk
*fout_epll
, *sclk_spdif
;
89 fout_epll
= clk_get(NULL
, "fout_epll");
90 if (IS_ERR(fout_epll
)) {
91 printk(KERN_ERR
"%s: failed to get fout_epll\n", __func__
);
95 clk_set_rate(fout_epll
, epll_rate
);
98 sclk_spdif
= clk_get(NULL
, "sclk_spdif");
99 if (IS_ERR(sclk_spdif
)) {
100 printk(KERN_ERR
"%s: failed to get sclk_spdif\n", __func__
);
104 clk_set_rate(sclk_spdif
, audio_rate
);
110 static int smdk_hw_params(struct snd_pcm_substream
*substream
,
111 struct snd_pcm_hw_params
*params
)
113 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
114 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
115 unsigned long pll_out
, rclk_rate
;
118 switch (params_rate(params
)) {
131 /* Setting ratio to 512fs helps to use S/PDIF with HDMI without
132 * modify S/PDIF ASoC machine driver.
135 rclk_rate
= params_rate(params
) * ratio
;
137 /* Set audio source clock rates */
138 ret
= set_audio_clock_rate(pll_out
, rclk_rate
);
142 /* Set S/PDIF uses internal source clock */
143 ret
= snd_soc_dai_set_sysclk(cpu_dai
, SND_SOC_SPDIF_INT_MCLK
,
144 rclk_rate
, SND_SOC_CLOCK_IN
);
151 static struct snd_soc_ops smdk_spdif_ops
= {
152 .hw_params
= smdk_hw_params
,
155 static struct snd_soc_dai_link smdk_dai
= {
157 .stream_name
= "S/PDIF PCM Playback",
158 .platform_name
= "samsung-audio",
159 .cpu_dai_name
= "samsung-spdif",
160 .codec_dai_name
= "dit-hifi",
161 .codec_name
= "spdif-dit",
162 .ops
= &smdk_spdif_ops
,
165 static struct snd_soc_card smdk
= {
166 .name
= "SMDK-S/PDIF",
167 .dai_link
= &smdk_dai
,
171 static struct platform_device
*smdk_snd_spdif_dit_device
;
172 static struct platform_device
*smdk_snd_spdif_device
;
174 static int __init
smdk_init(void)
178 smdk_snd_spdif_dit_device
= platform_device_alloc("spdif-dit", -1);
179 if (!smdk_snd_spdif_dit_device
)
182 ret
= platform_device_add(smdk_snd_spdif_dit_device
);
186 smdk_snd_spdif_device
= platform_device_alloc("soc-audio", -1);
187 if (!smdk_snd_spdif_device
) {
192 platform_set_drvdata(smdk_snd_spdif_device
, &smdk
);
194 ret
= platform_device_add(smdk_snd_spdif_device
);
198 /* Set audio clock hierarchy manually */
199 ret
= set_audio_clock_heirachy(smdk_snd_spdif_device
);
205 platform_device_del(smdk_snd_spdif_device
);
207 platform_device_put(smdk_snd_spdif_device
);
209 platform_device_del(smdk_snd_spdif_dit_device
);
211 platform_device_put(smdk_snd_spdif_dit_device
);
215 static void __exit
smdk_exit(void)
217 platform_device_unregister(smdk_snd_spdif_device
);
218 platform_device_unregister(smdk_snd_spdif_dit_device
);
221 module_init(smdk_init
);
222 module_exit(smdk_exit
);
224 MODULE_AUTHOR("Seungwhan Youn, <sw.youn@samsung.com>");
225 MODULE_DESCRIPTION("ALSA SoC SMDK+S/PDIF");
226 MODULE_LICENSE("GPL");