aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/samsung/smdk_spdif.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 13:32:54 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 13:32:54 -0500
commit66dc918d42eaaa9afe42a47d07526765162017a9 (patch)
tree947411841773dfb076f1aa78bc5be868bc4281a6 /sound/soc/samsung/smdk_spdif.c
parentb2034d474b7e1e8578bd5c2977024b51693269d9 (diff)
parent6db9a0f326d3144d790d9479309df480a8f562e4 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6: (348 commits) ALSA: hda - Fix NULL-derefence with a single mic in STAC auto-mic detection ALSA: hda - Add missing NID 0x19 fixup for Sony VAIO ALSA: hda - Fix ALC275 enable hardware EQ for SONY VAIO ALSA: oxygen: fix Xonar DG input ALSA: hda - Fix EAPD on Lenovo NB ALC269 to low ALSA: hda - Fix missing EAPD for Acer 4930G ALSA: hda: Disable 4/6 channels on some NVIDIA GPUs. ALSA: hda - Add static_hdmi_pcm option to HDMI codec parser ALSA: hda - Don't refer ELD when unplugged ASoC: tpa6130a2: Fix compiler warning ASoC: tlv320dac33: Add DAPM selection for LOM invert ASoC: DMIC codec: Adding a generic DMIC codec ALSA: snd-usb-us122l: Fix missing NULL checks ALSA: snd-usb-us122l: Fix MIDI output ASoC: soc-cache: Fix invalid memory access during snd_soc_lzo_cache_sync() ASoC: Fix section mismatch in wm8995.c ALSA: oxygen: add S/PDIF source selection for Claro cards ALSA: oxygen: fix CD/MIDI for X-Meridian (2G) ASoC: fix migor audio build ALSA: include delay.h for msleep in Xonar DG support ...
Diffstat (limited to 'sound/soc/samsung/smdk_spdif.c')
-rw-r--r--sound/soc/samsung/smdk_spdif.c226
1 files changed, 226 insertions, 0 deletions
diff --git a/sound/soc/samsung/smdk_spdif.c b/sound/soc/samsung/smdk_spdif.c
new file mode 100644
index 000000000000..b5c3fad01bb8
--- /dev/null
+++ b/sound/soc/samsung/smdk_spdif.c
@@ -0,0 +1,226 @@
1/*
2 * smdk_spdif.c -- S/PDIF audio for SMDK
3 *
4 * Copyright 2010 Samsung Electronics Co. Ltd.
5 *
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.
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/device.h>
15#include <linux/clk.h>
16
17#include <plat/devs.h>
18
19#include <sound/soc.h>
20
21#include "dma.h"
22#include "spdif.h"
23
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'.
27 */
28static int set_audio_clock_heirachy(struct platform_device *pdev)
29{
30 struct clk *fout_epll, *mout_epll, *sclk_audio0, *sclk_spdif;
31 int ret = 0;
32
33 fout_epll = clk_get(NULL, "fout_epll");
34 if (IS_ERR(fout_epll)) {
35 printk(KERN_WARNING "%s: Cannot find fout_epll.\n",
36 __func__);
37 return -EINVAL;
38 }
39
40 mout_epll = clk_get(NULL, "mout_epll");
41 if (IS_ERR(mout_epll)) {
42 printk(KERN_WARNING "%s: Cannot find mout_epll.\n",
43 __func__);
44 ret = -EINVAL;
45 goto out1;
46 }
47
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",
51 __func__);
52 ret = -EINVAL;
53 goto out2;
54 }
55
56 sclk_spdif = clk_get(NULL, "sclk_spdif");
57 if (IS_ERR(sclk_spdif)) {
58 printk(KERN_WARNING "%s: Cannot find sclk_spdif.\n",
59 __func__);
60 ret = -EINVAL;
61 goto out3;
62 }
63
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);
68
69 clk_put(sclk_spdif);
70out3:
71 clk_put(sclk_audio0);
72out2:
73 clk_put(mout_epll);
74out1:
75 clk_put(fout_epll);
76
77 return ret;
78}
79
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.
83 */
84static int set_audio_clock_rate(unsigned long epll_rate,
85 unsigned long audio_rate)
86{
87 struct clk *fout_epll, *sclk_spdif;
88
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__);
92 return -ENOENT;
93 }
94
95 clk_set_rate(fout_epll, epll_rate);
96 clk_put(fout_epll);
97
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__);
101 return -ENOENT;
102 }
103
104 clk_set_rate(sclk_spdif, audio_rate);
105 clk_put(sclk_spdif);
106
107 return 0;
108}
109
110static int smdk_hw_params(struct snd_pcm_substream *substream,
111 struct snd_pcm_hw_params *params)
112{
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;
116 int ret, ratio;
117
118 switch (params_rate(params)) {
119 case 44100:
120 pll_out = 45158400;
121 break;
122 case 32000:
123 case 48000:
124 case 96000:
125 pll_out = 49152000;
126 break;
127 default:
128 return -EINVAL;
129 }
130
131 /* Setting ratio to 512fs helps to use S/PDIF with HDMI without
132 * modify S/PDIF ASoC machine driver.
133 */
134 ratio = 512;
135 rclk_rate = params_rate(params) * ratio;
136
137 /* Set audio source clock rates */
138 ret = set_audio_clock_rate(pll_out, rclk_rate);
139 if (ret < 0)
140 return ret;
141
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);
145 if (ret < 0)
146 return ret;
147
148 return ret;
149}
150
151static struct snd_soc_ops smdk_spdif_ops = {
152 .hw_params = smdk_hw_params,
153};
154
155static struct snd_soc_dai_link smdk_dai = {
156 .name = "S/PDIF",
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,
163};
164
165static struct snd_soc_card smdk = {
166 .name = "SMDK-S/PDIF",
167 .dai_link = &smdk_dai,
168 .num_links = 1,
169};
170
171static struct platform_device *smdk_snd_spdif_dit_device;
172static struct platform_device *smdk_snd_spdif_device;
173
174static int __init smdk_init(void)
175{
176 int ret;
177
178 smdk_snd_spdif_dit_device = platform_device_alloc("spdif-dit", -1);
179 if (!smdk_snd_spdif_dit_device)
180 return -ENOMEM;
181
182 ret = platform_device_add(smdk_snd_spdif_dit_device);
183 if (ret)
184 goto err1;
185
186 smdk_snd_spdif_device = platform_device_alloc("soc-audio", -1);
187 if (!smdk_snd_spdif_device) {
188 ret = -ENOMEM;
189 goto err2;
190 }
191
192 platform_set_drvdata(smdk_snd_spdif_device, &smdk);
193
194 ret = platform_device_add(smdk_snd_spdif_device);
195 if (ret)
196 goto err3;
197
198 /* Set audio clock hierarchy manually */
199 ret = set_audio_clock_heirachy(smdk_snd_spdif_device);
200 if (ret)
201 goto err4;
202
203 return 0;
204err4:
205 platform_device_del(smdk_snd_spdif_device);
206err3:
207 platform_device_put(smdk_snd_spdif_device);
208err2:
209 platform_device_del(smdk_snd_spdif_dit_device);
210err1:
211 platform_device_put(smdk_snd_spdif_dit_device);
212 return ret;
213}
214
215static void __exit smdk_exit(void)
216{
217 platform_device_unregister(smdk_snd_spdif_device);
218 platform_device_unregister(smdk_snd_spdif_dit_device);
219}
220
221module_init(smdk_init);
222module_exit(smdk_exit);
223
224MODULE_AUTHOR("Seungwhan Youn, <sw.youn@samsung.com>");
225MODULE_DESCRIPTION("ALSA SoC SMDK+S/PDIF");
226MODULE_LICENSE("GPL");