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 | ||
da155d5b | 13 | #include <linux/module.h> |
d0f5fa17 | 14 | #include <sound/soc.h> |
0378b6ac | 15 | #include <sound/pcm_params.h> |
d0f5fa17 | 16 | |
b0f39c25 JB |
17 | #include <asm/mach-types.h> |
18 | ||
d0f5fa17 | 19 | #include "../codecs/wm8580.h" |
0fff21a8 | 20 | #include "i2s.h" |
d0f5fa17 | 21 | |
9d37e894 MB |
22 | /* |
23 | * Default CFG switch settings to use this driver: | |
24 | * | |
25 | * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On | |
26 | */ | |
27 | ||
d98ce6cf JB |
28 | /* SMDK has a 12MHZ crystal attached to WM8580 */ |
29 | #define SMDK_WM8580_FREQ 12000000 | |
d0f5fa17 | 30 | |
d98ce6cf | 31 | static int smdk_hw_params(struct snd_pcm_substream *substream, |
d0f5fa17 | 32 | struct snd_pcm_hw_params *params) |
33 | { | |
34 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad LG |
35 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
36 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
d0f5fa17 | 37 | unsigned int pll_out; |
38 | int bfs, rfs, ret; | |
39 | ||
40 | switch (params_format(params)) { | |
41 | case SNDRV_PCM_FORMAT_U8: | |
42 | case SNDRV_PCM_FORMAT_S8: | |
43 | bfs = 16; | |
44 | break; | |
45 | case SNDRV_PCM_FORMAT_U16_LE: | |
46 | case SNDRV_PCM_FORMAT_S16_LE: | |
47 | bfs = 32; | |
48 | break; | |
49 | default: | |
50 | return -EINVAL; | |
51 | } | |
52 | ||
53 | /* The Fvco for WM8580 PLLs must fall within [90,100]MHz. | |
54 | * This criterion can't be met if we request PLL output | |
55 | * as {8000x256, 64000x256, 11025x256}Hz. | |
56 | * As a wayout, we rather change rfs to a minimum value that | |
57 | * results in (params_rate(params) * rfs), and itself, acceptable | |
58 | * to both - the CODEC and the CPU. | |
59 | */ | |
60 | switch (params_rate(params)) { | |
61 | case 16000: | |
62 | case 22050: | |
63 | case 32000: | |
64 | case 44100: | |
65 | case 48000: | |
66 | case 88200: | |
67 | case 96000: | |
68 | rfs = 256; | |
69 | break; | |
70 | case 64000: | |
71 | rfs = 384; | |
72 | break; | |
73 | case 8000: | |
74 | case 11025: | |
75 | rfs = 512; | |
76 | break; | |
77 | default: | |
78 | return -EINVAL; | |
79 | } | |
80 | pll_out = params_rate(params) * rfs; | |
81 | ||
82 | /* Set the Codec DAI configuration */ | |
83 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
84 | | SND_SOC_DAIFMT_NB_NF | |
85 | | SND_SOC_DAIFMT_CBM_CFM); | |
86 | if (ret < 0) | |
87 | return ret; | |
88 | ||
89 | /* Set the AP DAI configuration */ | |
90 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | |
91 | | SND_SOC_DAIFMT_NB_NF | |
92 | | SND_SOC_DAIFMT_CBM_CFM); | |
93 | if (ret < 0) | |
94 | return ret; | |
95 | ||
26d95b6e | 96 | /* Set WM8580 to drive MCLK from its PLLA */ |
d0f5fa17 | 97 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK, |
98 | WM8580_CLKSRC_PLLA); | |
99 | if (ret < 0) | |
100 | return ret; | |
101 | ||
c5607d8e | 102 | ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0, |
d98ce6cf | 103 | SMDK_WM8580_FREQ, pll_out); |
d0f5fa17 | 104 | if (ret < 0) |
105 | return ret; | |
106 | ||
c5607d8e MB |
107 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA, |
108 | pll_out, SND_SOC_CLOCK_IN); | |
d0f5fa17 | 109 | if (ret < 0) |
110 | return ret; | |
111 | ||
d0f5fa17 | 112 | return 0; |
113 | } | |
114 | ||
115 | /* | |
d98ce6cf | 116 | * SMDK WM8580 DAI operations. |
d0f5fa17 | 117 | */ |
d98ce6cf JB |
118 | static struct snd_soc_ops smdk_ops = { |
119 | .hw_params = smdk_hw_params, | |
d0f5fa17 | 120 | }; |
121 | ||
d98ce6cf | 122 | /* SMDK Playback widgets */ |
ce363f6d | 123 | static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = { |
698cb111 MB |
124 | SND_SOC_DAPM_HP("Front", NULL), |
125 | SND_SOC_DAPM_HP("Center+Sub", NULL), | |
126 | SND_SOC_DAPM_HP("Rear", NULL), | |
d0f5fa17 | 127 | |
d0f5fa17 | 128 | SND_SOC_DAPM_MIC("MicIn", NULL), |
129 | SND_SOC_DAPM_LINE("LineIn", NULL), | |
130 | }; | |
131 | ||
132 | /* SMDK-PAIFTX connections */ | |
ce363f6d | 133 | static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = { |
d0f5fa17 | 134 | /* MicIn feeds AINL */ |
135 | {"AINL", NULL, "MicIn"}, | |
136 | ||
137 | /* LineIn feeds AINL/R */ | |
138 | {"AINL", NULL, "LineIn"}, | |
139 | {"AINR", NULL, "LineIn"}, | |
d0f5fa17 | 140 | |
d0f5fa17 | 141 | /* Front Left/Right are fed VOUT1L/R */ |
698cb111 MB |
142 | {"Front", NULL, "VOUT1L"}, |
143 | {"Front", NULL, "VOUT1R"}, | |
d0f5fa17 | 144 | |
145 | /* Center/Sub are fed VOUT2L/R */ | |
698cb111 MB |
146 | {"Center+Sub", NULL, "VOUT2L"}, |
147 | {"Center+Sub", NULL, "VOUT2R"}, | |
d0f5fa17 | 148 | |
149 | /* Rear Left/Right are fed VOUT3L/R */ | |
698cb111 MB |
150 | {"Rear", NULL, "VOUT3L"}, |
151 | {"Rear", NULL, "VOUT3R"}, | |
d0f5fa17 | 152 | }; |
153 | ||
d98ce6cf | 154 | static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd) |
d0f5fa17 | 155 | { |
f0fba2ad | 156 | struct snd_soc_codec *codec = rtd->codec; |
ce6120cc | 157 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
f0fba2ad | 158 | |
26d95b6e MB |
159 | /* Enabling the microphone requires the fitting of a 0R |
160 | * resistor to connect the line from the microphone jack. | |
161 | */ | |
ce6120cc | 162 | snd_soc_dapm_disable_pin(dapm, "MicIn"); |
d0f5fa17 | 163 | |
d0f5fa17 | 164 | return 0; |
165 | } | |
166 | ||
b0f39c25 JB |
167 | enum { |
168 | PRI_PLAYBACK = 0, | |
169 | PRI_CAPTURE, | |
170 | SEC_PLAYBACK, | |
171 | }; | |
172 | ||
d98ce6cf | 173 | static struct snd_soc_dai_link smdk_dai[] = { |
b0f39c25 JB |
174 | [PRI_PLAYBACK] = { /* Primary Playback i/f */ |
175 | .name = "WM8580 PAIF RX", | |
176 | .stream_name = "Playback", | |
72685f27 | 177 | .cpu_dai_name = "samsung-i2s.0", |
b0f39c25 JB |
178 | .codec_dai_name = "wm8580-hifi-playback", |
179 | .platform_name = "samsung-audio", | |
5d5d09b2 | 180 | .codec_name = "wm8580.0-001b", |
b0f39c25 JB |
181 | .ops = &smdk_ops, |
182 | }, | |
183 | [PRI_CAPTURE] = { /* Primary Capture i/f */ | |
184 | .name = "WM8580 PAIF TX", | |
185 | .stream_name = "Capture", | |
72685f27 | 186 | .cpu_dai_name = "samsung-i2s.0", |
b0f39c25 JB |
187 | .codec_dai_name = "wm8580-hifi-capture", |
188 | .platform_name = "samsung-audio", | |
5d5d09b2 | 189 | .codec_name = "wm8580.0-001b", |
b0f39c25 JB |
190 | .init = smdk_wm8580_init_paiftx, |
191 | .ops = &smdk_ops, | |
192 | }, | |
193 | [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */ | |
194 | .name = "Sec_FIFO TX", | |
195 | .stream_name = "Playback", | |
196 | .cpu_dai_name = "samsung-i2s.x", | |
197 | .codec_dai_name = "wm8580-hifi-playback", | |
198 | .platform_name = "samsung-audio", | |
5d5d09b2 | 199 | .codec_name = "wm8580.0-001b", |
b0f39c25 JB |
200 | .ops = &smdk_ops, |
201 | }, | |
d0f5fa17 | 202 | }; |
203 | ||
d98ce6cf JB |
204 | static struct snd_soc_card smdk = { |
205 | .name = "SMDK-I2S", | |
095d79dc | 206 | .owner = THIS_MODULE, |
d98ce6cf | 207 | .dai_link = smdk_dai, |
b0f39c25 | 208 | .num_links = 2, |
ce363f6d MB |
209 | |
210 | .dapm_widgets = smdk_wm8580_dapm_widgets, | |
211 | .num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets), | |
212 | .dapm_routes = smdk_wm8580_audio_map, | |
213 | .num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map), | |
d0f5fa17 | 214 | }; |
215 | ||
d98ce6cf | 216 | static struct platform_device *smdk_snd_device; |
d0f5fa17 | 217 | |
d98ce6cf | 218 | static int __init smdk_audio_init(void) |
d0f5fa17 | 219 | { |
220 | int ret; | |
b0f39c25 JB |
221 | char *str; |
222 | ||
4b42120d | 223 | if (machine_is_smdkc100() |
40d24829 | 224 | || machine_is_smdkv210() || machine_is_smdkc110()) { |
b0f39c25 | 225 | smdk.num_links = 3; |
b0f39c25 JB |
226 | /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */ |
227 | str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name; | |
228 | str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF; | |
72685f27 JB |
229 | } else if (machine_is_smdk6410()) { |
230 | str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name; | |
231 | str[strlen(str) - 1] = '2'; | |
232 | str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name; | |
233 | str[strlen(str) - 1] = '2'; | |
b0f39c25 | 234 | } |
d0f5fa17 | 235 | |
d98ce6cf JB |
236 | smdk_snd_device = platform_device_alloc("soc-audio", -1); |
237 | if (!smdk_snd_device) | |
d0f5fa17 | 238 | return -ENOMEM; |
239 | ||
d98ce6cf JB |
240 | platform_set_drvdata(smdk_snd_device, &smdk); |
241 | ret = platform_device_add(smdk_snd_device); | |
d0f5fa17 | 242 | |
243 | if (ret) | |
d98ce6cf | 244 | platform_device_put(smdk_snd_device); |
d0f5fa17 | 245 | |
246 | return ret; | |
247 | } | |
d98ce6cf | 248 | module_init(smdk_audio_init); |
d0f5fa17 | 249 | |
38533698 MB |
250 | static void __exit smdk_audio_exit(void) |
251 | { | |
252 | platform_device_unregister(smdk_snd_device); | |
253 | } | |
254 | module_exit(smdk_audio_exit); | |
255 | ||
d0f5fa17 | 256 | MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com"); |
d98ce6cf | 257 | MODULE_DESCRIPTION("ALSA SoC SMDK WM8580"); |
d0f5fa17 | 258 | MODULE_LICENSE("GPL"); |