1
2
3
4
5
6
7
8
9
10#include "../codecs/wm8994.h"
11#include <sound/pcm_params.h>
12#include <linux/module.h>
13#include <linux/of.h>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38#define SMDK_WM8994_FREQ 16934000
39
40static int smdk_hw_params(struct snd_pcm_substream *substream,
41 struct snd_pcm_hw_params *params)
42{
43 struct snd_soc_pcm_runtime *rtd = substream->private_data;
44 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
45 struct snd_soc_dai *codec_dai = rtd->codec_dai;
46 unsigned int pll_out;
47 int ret;
48
49
50 if (params_format(params) == SNDRV_PCM_FORMAT_S24_LE)
51 pll_out = params_rate(params) * 384;
52 else if (params_rate(params) == 8000 || params_rate(params) == 11025)
53 pll_out = params_rate(params) * 512;
54 else
55 pll_out = params_rate(params) * 256;
56
57 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
58 | SND_SOC_DAIFMT_NB_NF
59 | SND_SOC_DAIFMT_CBM_CFM);
60 if (ret < 0)
61 return ret;
62
63 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
64 | SND_SOC_DAIFMT_NB_NF
65 | SND_SOC_DAIFMT_CBM_CFM);
66 if (ret < 0)
67 return ret;
68
69 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
70 SMDK_WM8994_FREQ, pll_out);
71 if (ret < 0)
72 return ret;
73
74 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
75 pll_out, SND_SOC_CLOCK_IN);
76 if (ret < 0)
77 return ret;
78
79 return 0;
80}
81
82
83
84
85static struct snd_soc_ops smdk_ops = {
86 .hw_params = smdk_hw_params,
87};
88
89static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
90{
91 struct snd_soc_codec *codec = rtd->codec;
92 struct snd_soc_dapm_context *dapm = &codec->dapm;
93
94
95 snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
96 snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
97
98
99 snd_soc_dapm_enable_pin(dapm, "IN1LN");
100 snd_soc_dapm_enable_pin(dapm, "IN1RN");
101
102
103 snd_soc_dapm_enable_pin(dapm, "IN2LN");
104 snd_soc_dapm_enable_pin(dapm, "IN2RN");
105
106
107 snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
108 snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
109 snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
110 snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
111 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
112 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
113 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
114 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
115 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
116 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
117 snd_soc_dapm_nc_pin(dapm, "IN1LP");
118 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
119 snd_soc_dapm_nc_pin(dapm, "IN1RP");
120 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
121
122 return 0;
123}
124
125static struct snd_soc_dai_link smdk_dai[] = {
126 {
127 .name = "WM8994 AIF1",
128 .stream_name = "Pri_Dai",
129 .cpu_dai_name = "samsung-i2s.0",
130 .codec_dai_name = "wm8994-aif1",
131 .platform_name = "samsung-i2s.0",
132 .codec_name = "wm8994-codec",
133 .init = smdk_wm8994_init_paiftx,
134 .ops = &smdk_ops,
135 }, {
136 .name = "Sec_FIFO TX",
137 .stream_name = "Sec_Dai",
138 .cpu_dai_name = "samsung-i2s-sec",
139 .codec_dai_name = "wm8994-aif1",
140 .platform_name = "samsung-i2s-sec",
141 .codec_name = "wm8994-codec",
142 .ops = &smdk_ops,
143 },
144};
145
146static struct snd_soc_card smdk = {
147 .name = "SMDK-I2S",
148 .owner = THIS_MODULE,
149 .dai_link = smdk_dai,
150 .num_links = ARRAY_SIZE(smdk_dai),
151};
152
153
154static int smdk_audio_probe(struct platform_device *pdev)
155{
156 int ret;
157 struct device_node *np = pdev->dev.of_node;
158 struct snd_soc_card *card = &smdk;
159
160 card->dev = &pdev->dev;
161
162 if (np) {
163 smdk_dai[0].cpu_dai_name = NULL;
164 smdk_dai[0].cpu_of_node = of_parse_phandle(np,
165 "samsung,i2s-controller", 0);
166 if (!smdk_dai[0].cpu_of_node) {
167 dev_err(&pdev->dev,
168 "Property 'samsung,i2s-controller' missing or invalid\n");
169 ret = -EINVAL;
170 }
171
172 smdk_dai[0].platform_name = NULL;
173 smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node;
174 }
175
176 ret = snd_soc_register_card(card);
177
178 if (ret)
179 dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
180
181 return ret;
182}
183
184static int smdk_audio_remove(struct platform_device *pdev)
185{
186 struct snd_soc_card *card = platform_get_drvdata(pdev);
187
188 snd_soc_unregister_card(card);
189
190 return 0;
191}
192
193#ifdef CONFIG_OF
194static const struct of_device_id samsung_wm8994_of_match[] = {
195 { .compatible = "samsung,smdk-wm8994", },
196 {},
197};
198MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
199#endif
200
201static struct platform_driver smdk_audio_driver = {
202 .driver = {
203 .name = "smdk-audio",
204 .owner = THIS_MODULE,
205 .of_match_table = of_match_ptr(samsung_wm8994_of_match),
206 },
207 .probe = smdk_audio_probe,
208 .remove = smdk_audio_remove,
209};
210
211module_platform_driver(smdk_audio_driver);
212
213MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
214MODULE_LICENSE("GPL");
215MODULE_ALIAS("platform:smdk-audio");
216