Commit | Line | Data |
---|---|---|
d0f5fa17 | 1 | /* |
d98ce6cf | 2 | * smdk_wm8580.c |
d0f5fa17 | 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> | |
d0f5fa17 | 19 | |
b0f39c25 JB |
20 | #include <asm/mach-types.h> |
21 | ||
d0f5fa17 | 22 | #include "../codecs/wm8580.h" |
4b640cf3 | 23 | #include "dma.h" |
0fff21a8 | 24 | #include "i2s.h" |
d0f5fa17 | 25 | |
9d37e894 MB |
26 | /* |
27 | * Default CFG switch settings to use this driver: | |
28 | * | |
29 | * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On | |
30 | */ | |
31 | ||
d98ce6cf JB |
32 | /* SMDK has a 12MHZ crystal attached to WM8580 */ |
33 | #define SMDK_WM8580_FREQ 12000000 | |
d0f5fa17 | 34 | |
d98ce6cf | 35 | static int smdk_hw_params(struct snd_pcm_substream *substream, |
d0f5fa17 | 36 | struct snd_pcm_hw_params *params) |
37 | { | |
38 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad LG |
39 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
40 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
d0f5fa17 | 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 | ||
26d95b6e | 100 | /* Set WM8580 to drive MCLK from its PLLA */ |
d0f5fa17 | 101 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK, |
102 | WM8580_CLKSRC_PLLA); | |
103 | if (ret < 0) | |
104 | return ret; | |
105 | ||
c5607d8e | 106 | ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0, |
d98ce6cf | 107 | SMDK_WM8580_FREQ, pll_out); |
d0f5fa17 | 108 | if (ret < 0) |
109 | return ret; | |
110 | ||
c5607d8e MB |
111 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA, |
112 | pll_out, SND_SOC_CLOCK_IN); | |
d0f5fa17 | 113 | if (ret < 0) |
114 | return ret; | |
115 | ||
d0f5fa17 | 116 | return 0; |
117 | } | |
118 | ||
119 | /* | |
d98ce6cf | 120 | * SMDK WM8580 DAI operations. |
d0f5fa17 | 121 | */ |
d98ce6cf JB |
122 | static struct snd_soc_ops smdk_ops = { |
123 | .hw_params = smdk_hw_params, | |
d0f5fa17 | 124 | }; |
125 | ||
d98ce6cf | 126 | /* SMDK Playback widgets */ |
d0f5fa17 | 127 | static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = { |
698cb111 MB |
128 | SND_SOC_DAPM_HP("Front", NULL), |
129 | SND_SOC_DAPM_HP("Center+Sub", NULL), | |
130 | SND_SOC_DAPM_HP("Rear", NULL), | |
d0f5fa17 | 131 | }; |
132 | ||
d98ce6cf | 133 | /* SMDK Capture widgets */ |
d0f5fa17 | 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 */ | |
698cb111 MB |
152 | {"Front", NULL, "VOUT1L"}, |
153 | {"Front", NULL, "VOUT1R"}, | |
d0f5fa17 | 154 | |
155 | /* Center/Sub are fed VOUT2L/R */ | |
698cb111 MB |
156 | {"Center+Sub", NULL, "VOUT2L"}, |
157 | {"Center+Sub", NULL, "VOUT2R"}, | |
d0f5fa17 | 158 | |
159 | /* Rear Left/Right are fed VOUT3L/R */ | |
698cb111 MB |
160 | {"Rear", NULL, "VOUT3L"}, |
161 | {"Rear", NULL, "VOUT3R"}, | |
d0f5fa17 | 162 | }; |
163 | ||
d98ce6cf | 164 | static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd) |
d0f5fa17 | 165 | { |
f0fba2ad | 166 | struct snd_soc_codec *codec = rtd->codec; |
ce6120cc | 167 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
f0fba2ad | 168 | |
d98ce6cf | 169 | /* Add smdk specific Capture widgets */ |
ce6120cc | 170 | snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_cpt, |
d0f5fa17 | 171 | ARRAY_SIZE(wm8580_dapm_widgets_cpt)); |
172 | ||
173 | /* Set up PAIFTX audio path */ | |
ce6120cc | 174 | snd_soc_dapm_add_routes(dapm, audio_map_tx, ARRAY_SIZE(audio_map_tx)); |
d0f5fa17 | 175 | |
26d95b6e MB |
176 | /* Enabling the microphone requires the fitting of a 0R |
177 | * resistor to connect the line from the microphone jack. | |
178 | */ | |
ce6120cc | 179 | snd_soc_dapm_disable_pin(dapm, "MicIn"); |
d0f5fa17 | 180 | |
181 | /* signal a DAPM event */ | |
ce6120cc | 182 | snd_soc_dapm_sync(dapm); |
d0f5fa17 | 183 | |
184 | return 0; | |
185 | } | |
186 | ||
d98ce6cf | 187 | static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd) |
d0f5fa17 | 188 | { |
f0fba2ad | 189 | struct snd_soc_codec *codec = rtd->codec; |
ce6120cc | 190 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
f0fba2ad | 191 | |
d98ce6cf | 192 | /* Add smdk specific Playback widgets */ |
ce6120cc | 193 | snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_pbk, |
d0f5fa17 | 194 | ARRAY_SIZE(wm8580_dapm_widgets_pbk)); |
195 | ||
196 | /* Set up PAIFRX audio path */ | |
ce6120cc | 197 | snd_soc_dapm_add_routes(dapm, audio_map_rx, ARRAY_SIZE(audio_map_rx)); |
d0f5fa17 | 198 | |
d0f5fa17 | 199 | /* signal a DAPM event */ |
ce6120cc | 200 | snd_soc_dapm_sync(dapm); |
d0f5fa17 | 201 | |
202 | return 0; | |
203 | } | |
204 | ||
b0f39c25 JB |
205 | enum { |
206 | PRI_PLAYBACK = 0, | |
207 | PRI_CAPTURE, | |
208 | SEC_PLAYBACK, | |
209 | }; | |
210 | ||
d98ce6cf | 211 | static struct snd_soc_dai_link smdk_dai[] = { |
b0f39c25 JB |
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 | }, | |
d0f5fa17 | 242 | }; |
243 | ||
d98ce6cf JB |
244 | static struct snd_soc_card smdk = { |
245 | .name = "SMDK-I2S", | |
246 | .dai_link = smdk_dai, | |
b0f39c25 | 247 | .num_links = 2, |
d0f5fa17 | 248 | }; |
249 | ||
d98ce6cf | 250 | static struct platform_device *smdk_snd_device; |
d0f5fa17 | 251 | |
d98ce6cf | 252 | static int __init smdk_audio_init(void) |
d0f5fa17 | 253 | { |
254 | int ret; | |
b0f39c25 JB |
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 | } | |
d0f5fa17 | 268 | |
d98ce6cf JB |
269 | smdk_snd_device = platform_device_alloc("soc-audio", -1); |
270 | if (!smdk_snd_device) | |
d0f5fa17 | 271 | return -ENOMEM; |
272 | ||
d98ce6cf JB |
273 | platform_set_drvdata(smdk_snd_device, &smdk); |
274 | ret = platform_device_add(smdk_snd_device); | |
d0f5fa17 | 275 | |
276 | if (ret) | |
d98ce6cf | 277 | platform_device_put(smdk_snd_device); |
d0f5fa17 | 278 | |
279 | return ret; | |
280 | } | |
d98ce6cf | 281 | module_init(smdk_audio_init); |
d0f5fa17 | 282 | |
283 | MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com"); | |
d98ce6cf | 284 | MODULE_DESCRIPTION("ALSA SoC SMDK WM8580"); |
d0f5fa17 | 285 | MODULE_LICENSE("GPL"); |