]>
Commit | Line | Data |
---|---|---|
d0f5fa17 | 1 | /* |
2 | * smdk64xx_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 | #include <sound/soc-dapm.h> | |
20 | ||
21 | #include "../codecs/wm8580.h" | |
d3ff5a3e | 22 | #include "s3c-dma.h" |
d0f5fa17 | 23 | #include "s3c64xx-i2s.h" |
24 | ||
9d37e894 MB |
25 | /* |
26 | * Default CFG switch settings to use this driver: | |
27 | * | |
28 | * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On | |
29 | */ | |
30 | ||
d0f5fa17 | 31 | /* SMDK64XX has a 12MHZ crystal attached to WM8580 */ |
32 | #define SMDK64XX_WM8580_FREQ 12000000 | |
33 | ||
34 | static int smdk64xx_hw_params(struct snd_pcm_substream *substream, | |
35 | struct snd_pcm_hw_params *params) | |
36 | { | |
37 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad LG |
38 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
39 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
d0f5fa17 | 40 | unsigned int pll_out; |
41 | int bfs, rfs, ret; | |
42 | ||
43 | switch (params_format(params)) { | |
44 | case SNDRV_PCM_FORMAT_U8: | |
45 | case SNDRV_PCM_FORMAT_S8: | |
46 | bfs = 16; | |
47 | break; | |
48 | case SNDRV_PCM_FORMAT_U16_LE: | |
49 | case SNDRV_PCM_FORMAT_S16_LE: | |
50 | bfs = 32; | |
51 | break; | |
52 | default: | |
53 | return -EINVAL; | |
54 | } | |
55 | ||
56 | /* The Fvco for WM8580 PLLs must fall within [90,100]MHz. | |
57 | * This criterion can't be met if we request PLL output | |
58 | * as {8000x256, 64000x256, 11025x256}Hz. | |
59 | * As a wayout, we rather change rfs to a minimum value that | |
60 | * results in (params_rate(params) * rfs), and itself, acceptable | |
61 | * to both - the CODEC and the CPU. | |
62 | */ | |
63 | switch (params_rate(params)) { | |
64 | case 16000: | |
65 | case 22050: | |
66 | case 32000: | |
67 | case 44100: | |
68 | case 48000: | |
69 | case 88200: | |
70 | case 96000: | |
71 | rfs = 256; | |
72 | break; | |
73 | case 64000: | |
74 | rfs = 384; | |
75 | break; | |
76 | case 8000: | |
77 | case 11025: | |
78 | rfs = 512; | |
79 | break; | |
80 | default: | |
81 | return -EINVAL; | |
82 | } | |
83 | pll_out = params_rate(params) * rfs; | |
84 | ||
85 | /* Set the Codec DAI configuration */ | |
86 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
87 | | SND_SOC_DAIFMT_NB_NF | |
88 | | SND_SOC_DAIFMT_CBM_CFM); | |
89 | if (ret < 0) | |
90 | return ret; | |
91 | ||
92 | /* Set the AP DAI configuration */ | |
93 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | |
94 | | SND_SOC_DAIFMT_NB_NF | |
95 | | SND_SOC_DAIFMT_CBM_CFM); | |
96 | if (ret < 0) | |
97 | return ret; | |
98 | ||
99 | ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_CDCLK, | |
100 | 0, SND_SOC_CLOCK_IN); | |
101 | if (ret < 0) | |
102 | return ret; | |
103 | ||
104 | /* We use PCLK for basic ops in SoC-Slave mode */ | |
105 | ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK, | |
106 | 0, SND_SOC_CLOCK_IN); | |
107 | if (ret < 0) | |
108 | return ret; | |
109 | ||
26d95b6e | 110 | /* Set WM8580 to drive MCLK from its PLLA */ |
d0f5fa17 | 111 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK, |
112 | WM8580_CLKSRC_PLLA); | |
113 | if (ret < 0) | |
114 | return ret; | |
115 | ||
c5607d8e MB |
116 | ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0, |
117 | SMDK64XX_WM8580_FREQ, pll_out); | |
d0f5fa17 | 118 | if (ret < 0) |
119 | return ret; | |
120 | ||
c5607d8e MB |
121 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA, |
122 | pll_out, SND_SOC_CLOCK_IN); | |
d0f5fa17 | 123 | if (ret < 0) |
124 | return ret; | |
125 | ||
126 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_BCLK, bfs); | |
127 | if (ret < 0) | |
128 | return ret; | |
129 | ||
130 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, rfs); | |
131 | if (ret < 0) | |
132 | return ret; | |
133 | ||
134 | return 0; | |
135 | } | |
136 | ||
137 | /* | |
138 | * SMDK64XX WM8580 DAI operations. | |
139 | */ | |
140 | static struct snd_soc_ops smdk64xx_ops = { | |
141 | .hw_params = smdk64xx_hw_params, | |
142 | }; | |
143 | ||
144 | /* SMDK64xx Playback widgets */ | |
145 | static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = { | |
698cb111 MB |
146 | SND_SOC_DAPM_HP("Front", NULL), |
147 | SND_SOC_DAPM_HP("Center+Sub", NULL), | |
148 | SND_SOC_DAPM_HP("Rear", NULL), | |
d0f5fa17 | 149 | }; |
150 | ||
151 | /* SMDK64xx Capture widgets */ | |
152 | static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = { | |
153 | SND_SOC_DAPM_MIC("MicIn", NULL), | |
154 | SND_SOC_DAPM_LINE("LineIn", NULL), | |
155 | }; | |
156 | ||
157 | /* SMDK-PAIFTX connections */ | |
158 | static const struct snd_soc_dapm_route audio_map_tx[] = { | |
159 | /* MicIn feeds AINL */ | |
160 | {"AINL", NULL, "MicIn"}, | |
161 | ||
162 | /* LineIn feeds AINL/R */ | |
163 | {"AINL", NULL, "LineIn"}, | |
164 | {"AINR", NULL, "LineIn"}, | |
165 | }; | |
166 | ||
167 | /* SMDK-PAIFRX connections */ | |
168 | static const struct snd_soc_dapm_route audio_map_rx[] = { | |
169 | /* Front Left/Right are fed VOUT1L/R */ | |
698cb111 MB |
170 | {"Front", NULL, "VOUT1L"}, |
171 | {"Front", NULL, "VOUT1R"}, | |
d0f5fa17 | 172 | |
173 | /* Center/Sub are fed VOUT2L/R */ | |
698cb111 MB |
174 | {"Center+Sub", NULL, "VOUT2L"}, |
175 | {"Center+Sub", NULL, "VOUT2R"}, | |
d0f5fa17 | 176 | |
177 | /* Rear Left/Right are fed VOUT3L/R */ | |
698cb111 MB |
178 | {"Rear", NULL, "VOUT3L"}, |
179 | {"Rear", NULL, "VOUT3R"}, | |
d0f5fa17 | 180 | }; |
181 | ||
f0fba2ad | 182 | static int smdk64xx_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd) |
d0f5fa17 | 183 | { |
f0fba2ad LG |
184 | struct snd_soc_codec *codec = rtd->codec; |
185 | ||
d0f5fa17 | 186 | /* Add smdk64xx specific Capture widgets */ |
187 | snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_cpt, | |
188 | ARRAY_SIZE(wm8580_dapm_widgets_cpt)); | |
189 | ||
190 | /* Set up PAIFTX audio path */ | |
191 | snd_soc_dapm_add_routes(codec, audio_map_tx, ARRAY_SIZE(audio_map_tx)); | |
192 | ||
26d95b6e MB |
193 | /* Enabling the microphone requires the fitting of a 0R |
194 | * resistor to connect the line from the microphone jack. | |
195 | */ | |
196 | snd_soc_dapm_disable_pin(codec, "MicIn"); | |
d0f5fa17 | 197 | |
198 | /* signal a DAPM event */ | |
199 | snd_soc_dapm_sync(codec); | |
200 | ||
201 | return 0; | |
202 | } | |
203 | ||
f0fba2ad | 204 | static int smdk64xx_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd) |
d0f5fa17 | 205 | { |
f0fba2ad LG |
206 | struct snd_soc_codec *codec = rtd->codec; |
207 | ||
d0f5fa17 | 208 | /* Add smdk64xx specific Playback widgets */ |
209 | snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_pbk, | |
210 | ARRAY_SIZE(wm8580_dapm_widgets_pbk)); | |
211 | ||
212 | /* Set up PAIFRX audio path */ | |
213 | snd_soc_dapm_add_routes(codec, audio_map_rx, ARRAY_SIZE(audio_map_rx)); | |
214 | ||
d0f5fa17 | 215 | /* signal a DAPM event */ |
216 | snd_soc_dapm_sync(codec); | |
217 | ||
218 | return 0; | |
219 | } | |
220 | ||
221 | static struct snd_soc_dai_link smdk64xx_dai[] = { | |
222 | { /* Primary Playback i/f */ | |
223 | .name = "WM8580 PAIF RX", | |
224 | .stream_name = "Playback", | |
f0fba2ad LG |
225 | .cpu_dai_name = "s3c64xx-iis-v4", |
226 | .codec_dai_name = "wm8580-hifi-playback", | |
227 | .platform_name = "s3c24xx-pcm-audio", | |
228 | .codec_name = "wm8580-codec.0-001b", | |
d0f5fa17 | 229 | .init = smdk64xx_wm8580_init_paifrx, |
230 | .ops = &smdk64xx_ops, | |
231 | }, | |
232 | { /* Primary Capture i/f */ | |
233 | .name = "WM8580 PAIF TX", | |
234 | .stream_name = "Capture", | |
f0fba2ad LG |
235 | .cpu_dai_name = "s3c64xx-iis-v4", |
236 | .codec_dai_name = "wm8580-hifi-capture", | |
237 | .platform_name = "s3c24xx-pcm-audio", | |
238 | .codec_name = "wm8580-codec.0-001b", | |
d0f5fa17 | 239 | .init = smdk64xx_wm8580_init_paiftx, |
240 | .ops = &smdk64xx_ops, | |
241 | }, | |
242 | }; | |
243 | ||
244 | static struct snd_soc_card smdk64xx = { | |
245 | .name = "smdk64xx", | |
d0f5fa17 | 246 | .dai_link = smdk64xx_dai, |
247 | .num_links = ARRAY_SIZE(smdk64xx_dai), | |
248 | }; | |
249 | ||
d0f5fa17 | 250 | static struct platform_device *smdk64xx_snd_device; |
251 | ||
252 | static int __init smdk64xx_audio_init(void) | |
253 | { | |
254 | int ret; | |
255 | ||
256 | smdk64xx_snd_device = platform_device_alloc("soc-audio", -1); | |
257 | if (!smdk64xx_snd_device) | |
258 | return -ENOMEM; | |
259 | ||
f0fba2ad | 260 | platform_set_drvdata(smdk64xx_snd_device, &smdk64xx); |
d0f5fa17 | 261 | ret = platform_device_add(smdk64xx_snd_device); |
262 | ||
263 | if (ret) | |
264 | platform_device_put(smdk64xx_snd_device); | |
265 | ||
266 | return ret; | |
267 | } | |
268 | module_init(smdk64xx_audio_init); | |
269 | ||
270 | MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com"); | |
271 | MODULE_DESCRIPTION("ALSA SoC SMDK64XX WM8580"); | |
272 | MODULE_LICENSE("GPL"); |