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