diff options
Diffstat (limited to 'sound/soc/samsung/smdk_wm8580.c')
-rw-r--r-- | sound/soc/samsung/smdk_wm8580.c | 285 |
1 files changed, 285 insertions, 0 deletions
diff --git a/sound/soc/samsung/smdk_wm8580.c b/sound/soc/samsung/smdk_wm8580.c new file mode 100644 index 000000000000..0ae3d57d79e6 --- /dev/null +++ b/sound/soc/samsung/smdk_wm8580.c | |||
@@ -0,0 +1,285 @@ | |||
1 | /* | ||
2 | * smdk_wm8580.c | ||
3 | * | ||
4 | * Copyright (c) 2009 Samsung Electronics Co. Ltd | ||
5 | * Author: Jaswinder Singh <jassi.brar@samsung.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the | ||
9 | * Free Software Foundation; either version 2 of the License, or (at your | ||
10 | * option) any later version. | ||
11 | */ | ||
12 | |||
13 | #include <linux/platform_device.h> | ||
14 | #include <linux/clk.h> | ||
15 | #include <sound/core.h> | ||
16 | #include <sound/pcm.h> | ||
17 | #include <sound/pcm_params.h> | ||
18 | #include <sound/soc.h> | ||
19 | |||
20 | #include <asm/mach-types.h> | ||
21 | |||
22 | #include "../codecs/wm8580.h" | ||
23 | #include "dma.h" | ||
24 | #include "i2s.h" | ||
25 | |||
26 | /* | ||
27 | * Default CFG switch settings to use this driver: | ||
28 | * | ||
29 | * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On | ||
30 | */ | ||
31 | |||
32 | /* SMDK has a 12MHZ crystal attached to WM8580 */ | ||
33 | #define SMDK_WM8580_FREQ 12000000 | ||
34 | |||
35 | static int smdk_hw_params(struct snd_pcm_substream *substream, | ||
36 | struct snd_pcm_hw_params *params) | ||
37 | { | ||
38 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
39 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
40 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
41 | unsigned int pll_out; | ||
42 | int bfs, rfs, ret; | ||
43 | |||
44 | switch (params_format(params)) { | ||
45 | case SNDRV_PCM_FORMAT_U8: | ||
46 | case SNDRV_PCM_FORMAT_S8: | ||
47 | bfs = 16; | ||
48 | break; | ||
49 | case SNDRV_PCM_FORMAT_U16_LE: | ||
50 | case SNDRV_PCM_FORMAT_S16_LE: | ||
51 | bfs = 32; | ||
52 | break; | ||
53 | default: | ||
54 | return -EINVAL; | ||
55 | } | ||
56 | |||
57 | /* The Fvco for WM8580 PLLs must fall within [90,100]MHz. | ||
58 | * This criterion can't be met if we request PLL output | ||
59 | * as {8000x256, 64000x256, 11025x256}Hz. | ||
60 | * As a wayout, we rather change rfs to a minimum value that | ||
61 | * results in (params_rate(params) * rfs), and itself, acceptable | ||
62 | * to both - the CODEC and the CPU. | ||
63 | */ | ||
64 | switch (params_rate(params)) { | ||
65 | case 16000: | ||
66 | case 22050: | ||
67 | case 32000: | ||
68 | case 44100: | ||
69 | case 48000: | ||
70 | case 88200: | ||
71 | case 96000: | ||
72 | rfs = 256; | ||
73 | break; | ||
74 | case 64000: | ||
75 | rfs = 384; | ||
76 | break; | ||
77 | case 8000: | ||
78 | case 11025: | ||
79 | rfs = 512; | ||
80 | break; | ||
81 | default: | ||
82 | return -EINVAL; | ||
83 | } | ||
84 | pll_out = params_rate(params) * rfs; | ||
85 | |||
86 | /* Set the Codec DAI configuration */ | ||
87 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | ||
88 | | SND_SOC_DAIFMT_NB_NF | ||
89 | | SND_SOC_DAIFMT_CBM_CFM); | ||
90 | if (ret < 0) | ||
91 | return ret; | ||
92 | |||
93 | /* Set the AP DAI configuration */ | ||
94 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | ||
95 | | SND_SOC_DAIFMT_NB_NF | ||
96 | | SND_SOC_DAIFMT_CBM_CFM); | ||
97 | if (ret < 0) | ||
98 | return ret; | ||
99 | |||
100 | /* Set WM8580 to drive MCLK from its PLLA */ | ||
101 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK, | ||
102 | WM8580_CLKSRC_PLLA); | ||
103 | if (ret < 0) | ||
104 | return ret; | ||
105 | |||
106 | ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0, | ||
107 | SMDK_WM8580_FREQ, pll_out); | ||
108 | if (ret < 0) | ||
109 | return ret; | ||
110 | |||
111 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA, | ||
112 | pll_out, SND_SOC_CLOCK_IN); | ||
113 | if (ret < 0) | ||
114 | return ret; | ||
115 | |||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * SMDK WM8580 DAI operations. | ||
121 | */ | ||
122 | static struct snd_soc_ops smdk_ops = { | ||
123 | .hw_params = smdk_hw_params, | ||
124 | }; | ||
125 | |||
126 | /* SMDK Playback widgets */ | ||
127 | static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = { | ||
128 | SND_SOC_DAPM_HP("Front", NULL), | ||
129 | SND_SOC_DAPM_HP("Center+Sub", NULL), | ||
130 | SND_SOC_DAPM_HP("Rear", NULL), | ||
131 | }; | ||
132 | |||
133 | /* SMDK Capture widgets */ | ||
134 | static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = { | ||
135 | SND_SOC_DAPM_MIC("MicIn", NULL), | ||
136 | SND_SOC_DAPM_LINE("LineIn", NULL), | ||
137 | }; | ||
138 | |||
139 | /* SMDK-PAIFTX connections */ | ||
140 | static const struct snd_soc_dapm_route audio_map_tx[] = { | ||
141 | /* MicIn feeds AINL */ | ||
142 | {"AINL", NULL, "MicIn"}, | ||
143 | |||
144 | /* LineIn feeds AINL/R */ | ||
145 | {"AINL", NULL, "LineIn"}, | ||
146 | {"AINR", NULL, "LineIn"}, | ||
147 | }; | ||
148 | |||
149 | /* SMDK-PAIFRX connections */ | ||
150 | static const struct snd_soc_dapm_route audio_map_rx[] = { | ||
151 | /* Front Left/Right are fed VOUT1L/R */ | ||
152 | {"Front", NULL, "VOUT1L"}, | ||
153 | {"Front", NULL, "VOUT1R"}, | ||
154 | |||
155 | /* Center/Sub are fed VOUT2L/R */ | ||
156 | {"Center+Sub", NULL, "VOUT2L"}, | ||
157 | {"Center+Sub", NULL, "VOUT2R"}, | ||
158 | |||
159 | /* Rear Left/Right are fed VOUT3L/R */ | ||
160 | {"Rear", NULL, "VOUT3L"}, | ||
161 | {"Rear", NULL, "VOUT3R"}, | ||
162 | }; | ||
163 | |||
164 | static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd) | ||
165 | { | ||
166 | struct snd_soc_codec *codec = rtd->codec; | ||
167 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
168 | |||
169 | /* Add smdk specific Capture widgets */ | ||
170 | snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_cpt, | ||
171 | ARRAY_SIZE(wm8580_dapm_widgets_cpt)); | ||
172 | |||
173 | /* Set up PAIFTX audio path */ | ||
174 | snd_soc_dapm_add_routes(dapm, audio_map_tx, ARRAY_SIZE(audio_map_tx)); | ||
175 | |||
176 | /* Enabling the microphone requires the fitting of a 0R | ||
177 | * resistor to connect the line from the microphone jack. | ||
178 | */ | ||
179 | snd_soc_dapm_disable_pin(dapm, "MicIn"); | ||
180 | |||
181 | /* signal a DAPM event */ | ||
182 | snd_soc_dapm_sync(dapm); | ||
183 | |||
184 | return 0; | ||
185 | } | ||
186 | |||
187 | static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd) | ||
188 | { | ||
189 | struct snd_soc_codec *codec = rtd->codec; | ||
190 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
191 | |||
192 | /* Add smdk specific Playback widgets */ | ||
193 | snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_pbk, | ||
194 | ARRAY_SIZE(wm8580_dapm_widgets_pbk)); | ||
195 | |||
196 | /* Set up PAIFRX audio path */ | ||
197 | snd_soc_dapm_add_routes(dapm, audio_map_rx, ARRAY_SIZE(audio_map_rx)); | ||
198 | |||
199 | /* signal a DAPM event */ | ||
200 | snd_soc_dapm_sync(dapm); | ||
201 | |||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | enum { | ||
206 | PRI_PLAYBACK = 0, | ||
207 | PRI_CAPTURE, | ||
208 | SEC_PLAYBACK, | ||
209 | }; | ||
210 | |||
211 | static struct snd_soc_dai_link smdk_dai[] = { | ||
212 | [PRI_PLAYBACK] = { /* Primary Playback i/f */ | ||
213 | .name = "WM8580 PAIF RX", | ||
214 | .stream_name = "Playback", | ||
215 | .cpu_dai_name = "samsung-i2s.2", | ||
216 | .codec_dai_name = "wm8580-hifi-playback", | ||
217 | .platform_name = "samsung-audio", | ||
218 | .codec_name = "wm8580-codec.0-001b", | ||
219 | .init = smdk_wm8580_init_paifrx, | ||
220 | .ops = &smdk_ops, | ||
221 | }, | ||
222 | [PRI_CAPTURE] = { /* Primary Capture i/f */ | ||
223 | .name = "WM8580 PAIF TX", | ||
224 | .stream_name = "Capture", | ||
225 | .cpu_dai_name = "samsung-i2s.2", | ||
226 | .codec_dai_name = "wm8580-hifi-capture", | ||
227 | .platform_name = "samsung-audio", | ||
228 | .codec_name = "wm8580-codec.0-001b", | ||
229 | .init = smdk_wm8580_init_paiftx, | ||
230 | .ops = &smdk_ops, | ||
231 | }, | ||
232 | [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */ | ||
233 | .name = "Sec_FIFO TX", | ||
234 | .stream_name = "Playback", | ||
235 | .cpu_dai_name = "samsung-i2s.x", | ||
236 | .codec_dai_name = "wm8580-hifi-playback", | ||
237 | .platform_name = "samsung-audio", | ||
238 | .codec_name = "wm8580-codec.0-001b", | ||
239 | .init = smdk_wm8580_init_paifrx, | ||
240 | .ops = &smdk_ops, | ||
241 | }, | ||
242 | }; | ||
243 | |||
244 | static struct snd_soc_card smdk = { | ||
245 | .name = "SMDK-I2S", | ||
246 | .dai_link = smdk_dai, | ||
247 | .num_links = 2, | ||
248 | }; | ||
249 | |||
250 | static struct platform_device *smdk_snd_device; | ||
251 | |||
252 | static int __init smdk_audio_init(void) | ||
253 | { | ||
254 | int ret; | ||
255 | char *str; | ||
256 | |||
257 | if (machine_is_smdkc100()) { | ||
258 | smdk.num_links = 3; | ||
259 | /* S5PC100 has I2S0 as v5 */ | ||
260 | str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name; | ||
261 | str[strlen(str) - 1] = '0'; | ||
262 | str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name; | ||
263 | str[strlen(str) - 1] = '0'; | ||
264 | /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */ | ||
265 | str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name; | ||
266 | str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF; | ||
267 | } | ||
268 | |||
269 | smdk_snd_device = platform_device_alloc("soc-audio", -1); | ||
270 | if (!smdk_snd_device) | ||
271 | return -ENOMEM; | ||
272 | |||
273 | platform_set_drvdata(smdk_snd_device, &smdk); | ||
274 | ret = platform_device_add(smdk_snd_device); | ||
275 | |||
276 | if (ret) | ||
277 | platform_device_put(smdk_snd_device); | ||
278 | |||
279 | return ret; | ||
280 | } | ||
281 | module_init(smdk_audio_init); | ||
282 | |||
283 | MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com"); | ||
284 | MODULE_DESCRIPTION("ALSA SoC SMDK WM8580"); | ||
285 | MODULE_LICENSE("GPL"); | ||