1
2
3
4
5
6
7
8
9
10
11#include <linux/module.h>
12#include <sound/soc.h>
13#include <sound/pcm_params.h>
14#include <sound/pcm.h>
15
16#include <asm/mach-types.h>
17
18#include "../codecs/wm8580.h"
19#include "dma.h"
20#include "pcm.h"
21
22
23
24
25
26
27
28
29
30
31
32#define SMDK_WM8580_EXT_OSC 12000000
33#define SMDK_WM8580_EXT_MCLK 4096000
34#define SMDK_WM8580_EXT_VOICE 2048000
35
36static unsigned long mclk_freq;
37static unsigned long xtal_freq;
38
39
40
41
42
43
44
45
46static int smdk_wm8580_pcm_hw_params(struct snd_pcm_substream *substream,
47 struct snd_pcm_hw_params *params)
48{
49 struct snd_soc_pcm_runtime *rtd = substream->private_data;
50 struct snd_soc_dai *codec_dai = rtd->codec_dai;
51 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
52 int rfs, ret;
53
54 switch (params_rate(params)) {
55 case 8000:
56 break;
57 default:
58 printk(KERN_ERR "%s:%d Sampling Rate %u not supported!\n",
59 __func__, __LINE__, params_rate(params));
60 return -EINVAL;
61 }
62
63 rfs = mclk_freq / params_rate(params) / 2;
64
65
66 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B
67 | SND_SOC_DAIFMT_IB_NF
68 | SND_SOC_DAIFMT_CBS_CFS);
69 if (ret < 0)
70 return ret;
71
72
73 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_B
74 | SND_SOC_DAIFMT_IB_NF
75 | SND_SOC_DAIFMT_CBS_CFS);
76 if (ret < 0)
77 return ret;
78
79 if (mclk_freq == xtal_freq) {
80 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_MCLK,
81 mclk_freq, SND_SOC_CLOCK_IN);
82 if (ret < 0)
83 return ret;
84
85 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
86 WM8580_CLKSRC_MCLK);
87 if (ret < 0)
88 return ret;
89 } else {
90 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
91 mclk_freq, SND_SOC_CLOCK_IN);
92 if (ret < 0)
93 return ret;
94
95 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
96 WM8580_CLKSRC_PLLA);
97 if (ret < 0)
98 return ret;
99
100 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
101 xtal_freq, mclk_freq);
102 if (ret < 0)
103 return ret;
104 }
105
106
107 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C_PCM_CLKSRC_MUX,
108 mclk_freq, SND_SOC_CLOCK_IN);
109 if (ret < 0)
110 return ret;
111
112
113 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_PCM_SCLK_PER_FS, rfs);
114 if (ret < 0)
115 return ret;
116
117 return 0;
118}
119
120static struct snd_soc_ops smdk_wm8580_pcm_ops = {
121 .hw_params = smdk_wm8580_pcm_hw_params,
122};
123
124static struct snd_soc_dai_link smdk_dai[] = {
125 {
126 .name = "WM8580 PAIF PCM RX",
127 .stream_name = "Playback",
128 .cpu_dai_name = "samsung-pcm.0",
129 .codec_dai_name = "wm8580-hifi-playback",
130 .platform_name = "samsung-audio",
131 .codec_name = "wm8580.0-001b",
132 .ops = &smdk_wm8580_pcm_ops,
133 }, {
134 .name = "WM8580 PAIF PCM TX",
135 .stream_name = "Capture",
136 .cpu_dai_name = "samsung-pcm.0",
137 .codec_dai_name = "wm8580-hifi-capture",
138 .platform_name = "samsung-pcm.0",
139 .codec_name = "wm8580.0-001b",
140 .ops = &smdk_wm8580_pcm_ops,
141 },
142};
143
144static struct snd_soc_card smdk_pcm = {
145 .name = "SMDK-PCM",
146 .owner = THIS_MODULE,
147 .dai_link = smdk_dai,
148 .num_links = 2,
149};
150
151
152
153
154
155
156static int snd_smdk_probe(struct platform_device *pdev)
157{
158 int ret = 0;
159
160 xtal_freq = SMDK_WM8580_EXT_OSC;
161 mclk_freq = SMDK_WM8580_EXT_MCLK;
162
163 if (machine_is_smdkc110() || machine_is_smdkv210())
164 xtal_freq = mclk_freq = SMDK_WM8580_EXT_VOICE;
165
166 smdk_pcm.dev = &pdev->dev;
167 ret = snd_soc_register_card(&smdk_pcm);
168 if (ret) {
169 dev_err(&pdev->dev, "snd_soc_register_card failed %d\n", ret);
170 return ret;
171 }
172
173 return 0;
174}
175
176static int snd_smdk_remove(struct platform_device *pdev)
177{
178 snd_soc_unregister_card(&smdk_pcm);
179 return 0;
180}
181
182static struct platform_driver snd_smdk_driver = {
183 .driver = {
184 .owner = THIS_MODULE,
185 .name = "samsung-smdk-pcm",
186 },
187 .probe = snd_smdk_probe,
188 .remove = snd_smdk_remove,
189};
190
191module_platform_driver(snd_smdk_driver);
192
193MODULE_AUTHOR("Sangbeom Kim, <sbkim73@samsung.com>");
194MODULE_DESCRIPTION("ALSA SoC SMDK WM8580 for PCM");
195MODULE_LICENSE("GPL");
196