diff options
author | Seungwhan Youn <sw.youn@samsung.com> | 2010-10-12 07:58:52 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-10-15 06:41:12 -0400 |
commit | b67089e4c258a3a4ea8e23ceea4a5b7f8c3099d7 (patch) | |
tree | 9a18e9b4a63d6d4e5a3e7ee14f31410617b44ced /sound/soc | |
parent | fc127ccccc5de164d490e8a55a1c2c126293e96f (diff) |
ASoC: SAMSUNG: Add Machine driver for S/PDIF PCM audio
This patch add S/PDIF machine driver to support S/PDIF PCM audio
on SMDKC100, SMDKC110 and SMDKV210 boards.
Signed-off-by: Seungwhan Youn <sw.youn@samsung.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc')
-rw-r--r-- | sound/soc/s3c24xx/Kconfig | 7 | ||||
-rw-r--r-- | sound/soc/s3c24xx/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/s3c24xx/smdk_spdif.c | 223 |
3 files changed, 232 insertions, 0 deletions
diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig index e2cba93446a5..8a6b53ccd203 100644 --- a/sound/soc/s3c24xx/Kconfig +++ b/sound/soc/s3c24xx/Kconfig | |||
@@ -161,3 +161,10 @@ config SND_S5PV210_SOC_GONI_WM8994 | |||
161 | help | 161 | help |
162 | Say Y if you want to add support for SoC audio on goni | 162 | Say Y if you want to add support for SoC audio on goni |
163 | with the WM8994. | 163 | with the WM8994. |
164 | |||
165 | config SND_SOC_SMDK_SPDIF | ||
166 | tristate "SoC S/PDIF Audio support for SMDK" | ||
167 | depends on SND_S3C24XX_SOC && (MACH_SMDKC100 || MACH_SMDKC110 || MACH_SMDKV210) | ||
168 | select SND_S5P_SOC_SPDIF | ||
169 | help | ||
170 | Say Y if you want to add support for SoC S/PDIF audio on the SMDK. | ||
diff --git a/sound/soc/s3c24xx/Makefile b/sound/soc/s3c24xx/Makefile index 0a02735716de..ee8f41d6df99 100644 --- a/sound/soc/s3c24xx/Makefile +++ b/sound/soc/s3c24xx/Makefile | |||
@@ -35,6 +35,7 @@ snd-soc-smdk-wm9713-objs := smdk_wm9713.o | |||
35 | snd-soc-s3c64xx-smartq-wm8987-objs := smartq_wm8987.o | 35 | snd-soc-s3c64xx-smartq-wm8987-objs := smartq_wm8987.o |
36 | snd-soc-aquila-wm8994-objs := aquila_wm8994.o | 36 | snd-soc-aquila-wm8994-objs := aquila_wm8994.o |
37 | snd-soc-goni-wm8994-objs := goni_wm8994.o | 37 | snd-soc-goni-wm8994-objs := goni_wm8994.o |
38 | snd-soc-smdk-spdif-objs := smdk_spdif.o | ||
38 | 39 | ||
39 | obj-$(CONFIG_SND_S3C24XX_SOC_JIVE_WM8750) += snd-soc-jive-wm8750.o | 40 | obj-$(CONFIG_SND_S3C24XX_SOC_JIVE_WM8750) += snd-soc-jive-wm8750.o |
40 | obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o | 41 | obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o |
@@ -51,3 +52,4 @@ obj-$(CONFIG_SND_SOC_SMDK_WM9713) += snd-soc-smdk-wm9713.o | |||
51 | obj-$(CONFIG_SND_S3C64XX_SOC_SMARTQ) += snd-soc-s3c64xx-smartq-wm8987.o | 52 | obj-$(CONFIG_SND_S3C64XX_SOC_SMARTQ) += snd-soc-s3c64xx-smartq-wm8987.o |
52 | obj-$(CONFIG_SND_S5PC110_SOC_AQUILA_WM8994) += snd-soc-aquila-wm8994.o | 53 | obj-$(CONFIG_SND_S5PC110_SOC_AQUILA_WM8994) += snd-soc-aquila-wm8994.o |
53 | obj-$(CONFIG_SND_S5PV210_SOC_GONI_WM8994) += snd-soc-goni-wm8994.o | 54 | obj-$(CONFIG_SND_S5PV210_SOC_GONI_WM8994) += snd-soc-goni-wm8994.o |
55 | obj-$(CONFIG_SND_SOC_SMDK_SPDIF) += snd-soc-smdk-spdif.o | ||
diff --git a/sound/soc/s3c24xx/smdk_spdif.c b/sound/soc/s3c24xx/smdk_spdif.c new file mode 100644 index 000000000000..f31d22ad7c88 --- /dev/null +++ b/sound/soc/s3c24xx/smdk_spdif.c | |||
@@ -0,0 +1,223 @@ | |||
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 "s3c-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 | */ | ||
28 | static int set_audio_clock_heirachy(struct platform_device *pdev) | ||
29 | { | ||
30 | struct clk *fout_epll, *mout_epll, *sclk_audio0, *sclk_spdif; | ||
31 | int ret; | ||
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(fout_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(fout_epll)) { | ||
58 | printk(KERN_WARNING "%s: Cannot find sclk_spdif.\n", | ||
59 | __func__); | ||
60 | ret = -EINVAL; | ||
61 | goto out3; | ||
62 | } | ||
63 | |||
64 | /* Set audio clock heirachy 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); | ||
70 | out3: | ||
71 | clk_put(sclk_audio0); | ||
72 | out2: | ||
73 | clk_put(mout_epll); | ||
74 | out1: | ||
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 heirachy. | ||
83 | */ | ||
84 | static 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 | |||
110 | static 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 | |||
151 | static struct snd_soc_ops smdk_spdif_ops = { | ||
152 | .hw_params = smdk_hw_params, | ||
153 | }; | ||
154 | |||
155 | static struct snd_soc_card smdk; | ||
156 | |||
157 | static struct snd_soc_dai_link smdk_dai = { | ||
158 | .name = "S/PDIF", | ||
159 | .stream_name = "S/PDIF PCM Playback", | ||
160 | .platform_name = "s3c24xx-pcm-audio", | ||
161 | .cpu_dai_name = "samsung-spdif", | ||
162 | .codec_dai_name = "dit-hifi", | ||
163 | .codec_name = "spdif-dit", | ||
164 | .ops = &smdk_spdif_ops, | ||
165 | }; | ||
166 | |||
167 | static struct snd_soc_card smdk = { | ||
168 | .name = "SMDK-S/PDIF", | ||
169 | .dai_link = &smdk_dai, | ||
170 | .num_links = 1, | ||
171 | }; | ||
172 | |||
173 | static struct platform_device *smdk_snd_spdif_dit_device; | ||
174 | static struct platform_device *smdk_snd_spdif_device; | ||
175 | |||
176 | static int __init smdk_init(void) | ||
177 | { | ||
178 | int ret; | ||
179 | |||
180 | smdk_snd_spdif_dit_device = platform_device_alloc("spdif-dit", -1); | ||
181 | if (!smdk_snd_spdif_dit_device) | ||
182 | return -ENOMEM; | ||
183 | |||
184 | ret = platform_device_add(smdk_snd_spdif_dit_device); | ||
185 | if (ret) | ||
186 | goto err2; | ||
187 | |||
188 | smdk_snd_spdif_device = platform_device_alloc("soc-audio", -1); | ||
189 | if (!smdk_snd_spdif_device) { | ||
190 | ret = -ENOMEM; | ||
191 | goto err2; | ||
192 | } | ||
193 | |||
194 | platform_set_drvdata(smdk_snd_spdif_device, &smdk); | ||
195 | |||
196 | ret = platform_device_add(smdk_snd_spdif_device); | ||
197 | if (ret) | ||
198 | goto err1; | ||
199 | |||
200 | /* Set audio clock heirachy manually */ | ||
201 | ret = set_audio_clock_heirachy(smdk_snd_spdif_device); | ||
202 | if (ret) | ||
203 | goto err1; | ||
204 | |||
205 | return 0; | ||
206 | err1: | ||
207 | platform_device_put(smdk_snd_spdif_device); | ||
208 | err2: | ||
209 | platform_device_put(smdk_snd_spdif_dit_device); | ||
210 | return ret; | ||
211 | } | ||
212 | |||
213 | static void __exit smdk_exit(void) | ||
214 | { | ||
215 | platform_device_unregister(smdk_snd_spdif_device); | ||
216 | } | ||
217 | |||
218 | module_init(smdk_init); | ||
219 | module_exit(smdk_exit); | ||
220 | |||
221 | MODULE_AUTHOR("Seungwhan Youn, <sw.youn@samsung.com>"); | ||
222 | MODULE_DESCRIPTION("ALSA SoC SMDK+S/PDIF"); | ||
223 | MODULE_LICENSE("GPL"); | ||