Commit | Line | Data |
---|---|---|
5e64d6aa | 1 | /* |
13f81d65 PU |
2 | * omap-abe-twl6040.c -- SoC audio for TI OMAP based boards with ABE and |
3 | * twl6040 codec | |
5e64d6aa | 4 | * |
8747a6b7 | 5 | * Author: Misael Lopez Cruz <misael.lopez@ti.com> |
5e64d6aa MLC |
6 | * |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Public License | |
9 | * version 2 as published by the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
19 | * 02110-1301 USA | |
20 | * | |
21 | */ | |
22 | ||
23 | #include <linux/clk.h> | |
24 | #include <linux/platform_device.h> | |
fb34d3d5 | 25 | #include <linux/mfd/twl6040.h> |
da155d5b | 26 | #include <linux/module.h> |
fb34d3d5 | 27 | |
5e64d6aa MLC |
28 | #include <sound/core.h> |
29 | #include <sound/pcm.h> | |
30 | #include <sound/soc.h> | |
96dc227c | 31 | #include <sound/jack.h> |
5e64d6aa MLC |
32 | |
33 | #include <asm/mach-types.h> | |
34 | #include <plat/hardware.h> | |
35 | #include <plat/mux.h> | |
36 | ||
6524c8e3 | 37 | #include "omap-dmic.h" |
f5f9d7bf | 38 | #include "omap-mcpdm.h" |
5e64d6aa MLC |
39 | #include "omap-pcm.h" |
40 | #include "../codecs/twl6040.h" | |
41 | ||
13f81d65 | 42 | static int omap_abe_hw_params(struct snd_pcm_substream *substream, |
5e64d6aa MLC |
43 | struct snd_pcm_hw_params *params) |
44 | { | |
45 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad | 46 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
5e64d6aa MLC |
47 | int clk_id, freq; |
48 | int ret; | |
49 | ||
af958c72 PU |
50 | clk_id = twl6040_get_clk_id(rtd->codec); |
51 | if (clk_id == TWL6040_SYSCLK_SEL_HPPLL) | |
5e64d6aa | 52 | freq = 38400000; |
af958c72 | 53 | else if (clk_id == TWL6040_SYSCLK_SEL_LPPLL) |
5e64d6aa | 54 | freq = 32768; |
af958c72 PU |
55 | else |
56 | return -EINVAL; | |
5e64d6aa MLC |
57 | |
58 | /* set the codec mclk */ | |
59 | ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq, | |
60 | SND_SOC_CLOCK_IN); | |
61 | if (ret) { | |
62 | printk(KERN_ERR "can't set codec system clock\n"); | |
63 | return ret; | |
64 | } | |
f0fba2ad | 65 | return ret; |
5e64d6aa MLC |
66 | } |
67 | ||
13f81d65 PU |
68 | static struct snd_soc_ops omap_abe_ops = { |
69 | .hw_params = omap_abe_hw_params, | |
5e64d6aa MLC |
70 | }; |
71 | ||
13f81d65 | 72 | static int omap_abe_dmic_hw_params(struct snd_pcm_substream *substream, |
6524c8e3 PU |
73 | struct snd_pcm_hw_params *params) |
74 | { | |
75 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
76 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
77 | int ret = 0; | |
78 | ||
79 | ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_DMIC_SYSCLK_PAD_CLKS, | |
80 | 19200000, SND_SOC_CLOCK_IN); | |
81 | if (ret < 0) { | |
82 | printk(KERN_ERR "can't set DMIC cpu system clock\n"); | |
83 | return ret; | |
84 | } | |
85 | ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_DMIC_ABE_DMIC_CLK, 2400000, | |
86 | SND_SOC_CLOCK_OUT); | |
87 | if (ret < 0) { | |
88 | printk(KERN_ERR "can't set DMIC output clock\n"); | |
89 | return ret; | |
90 | } | |
91 | return 0; | |
92 | } | |
93 | ||
13f81d65 PU |
94 | static struct snd_soc_ops omap_abe_dmic_ops = { |
95 | .hw_params = omap_abe_dmic_hw_params, | |
6524c8e3 PU |
96 | }; |
97 | ||
96dc227c JEC |
98 | /* Headset jack */ |
99 | static struct snd_soc_jack hs_jack; | |
100 | ||
101 | /*Headset jack detection DAPM pins */ | |
102 | static struct snd_soc_jack_pin hs_jack_pins[] = { | |
103 | { | |
104 | .pin = "Headset Mic", | |
105 | .mask = SND_JACK_MICROPHONE, | |
106 | }, | |
107 | { | |
108 | .pin = "Headset Stereophone", | |
109 | .mask = SND_JACK_HEADPHONE, | |
110 | }, | |
111 | }; | |
112 | ||
5e64d6aa | 113 | /* SDP4430 machine DAPM */ |
13f81d65 | 114 | static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = { |
5e64d6aa MLC |
115 | SND_SOC_DAPM_MIC("Ext Mic", NULL), |
116 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | |
117 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | |
118 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), | |
7254e2bd | 119 | SND_SOC_DAPM_SPK("Earphone Spk", NULL), |
5382ffbb | 120 | SND_SOC_DAPM_INPUT("FM Stereo In"), |
5e64d6aa MLC |
121 | }; |
122 | ||
123 | static const struct snd_soc_dapm_route audio_map[] = { | |
124 | /* External Mics: MAINMIC, SUBMIC with bias*/ | |
125 | {"MAINMIC", NULL, "Main Mic Bias"}, | |
126 | {"SUBMIC", NULL, "Main Mic Bias"}, | |
127 | {"Main Mic Bias", NULL, "Ext Mic"}, | |
128 | ||
129 | /* External Speakers: HFL, HFR */ | |
130 | {"Ext Spk", NULL, "HFL"}, | |
131 | {"Ext Spk", NULL, "HFR"}, | |
132 | ||
133 | /* Headset Mic: HSMIC with bias */ | |
134 | {"HSMIC", NULL, "Headset Mic Bias"}, | |
135 | {"Headset Mic Bias", NULL, "Headset Mic"}, | |
136 | ||
137 | /* Headset Stereophone (Headphone): HSOL, HSOR */ | |
138 | {"Headset Stereophone", NULL, "HSOL"}, | |
139 | {"Headset Stereophone", NULL, "HSOR"}, | |
7254e2bd JEC |
140 | |
141 | /* Earphone speaker */ | |
142 | {"Earphone Spk", NULL, "EP"}, | |
23ac3b61 JEC |
143 | |
144 | /* Aux/FM Stereo In: AFML, AFMR */ | |
5382ffbb UP |
145 | {"AFML", NULL, "FM Stereo In"}, |
146 | {"AFMR", NULL, "FM Stereo In"}, | |
5e64d6aa MLC |
147 | }; |
148 | ||
13f81d65 | 149 | static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd) |
5e64d6aa | 150 | { |
f0fba2ad | 151 | struct snd_soc_codec *codec = rtd->codec; |
7bf3d92c | 152 | int ret, hs_trim; |
5e64d6aa | 153 | |
7bf3d92c PU |
154 | /* |
155 | * Configure McPDM offset cancellation based on the HSOTRIM value from | |
156 | * twl6040. | |
157 | */ | |
158 | hs_trim = twl6040_get_trim_value(codec, TWL6040_TRIM_HSOTRIM); | |
159 | omap_mcpdm_configure_dn_offsets(rtd, TWL6040_HSF_TRIM_LEFT(hs_trim), | |
160 | TWL6040_HSF_TRIM_RIGHT(hs_trim)); | |
161 | ||
96dc227c JEC |
162 | /* Headset jack detection */ |
163 | ret = snd_soc_jack_new(codec, "Headset Jack", | |
164 | SND_JACK_HEADSET, &hs_jack); | |
165 | if (ret) | |
166 | return ret; | |
167 | ||
168 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), | |
169 | hs_jack_pins); | |
170 | ||
171 | if (machine_is_omap_4430sdp()) | |
172 | twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET); | |
173 | else | |
174 | snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET); | |
5e64d6aa MLC |
175 | |
176 | return ret; | |
177 | } | |
178 | ||
13f81d65 | 179 | static const struct snd_soc_dapm_widget dmic_dapm_widgets[] = { |
6524c8e3 PU |
180 | SND_SOC_DAPM_MIC("Digital Mic", NULL), |
181 | }; | |
182 | ||
183 | static const struct snd_soc_dapm_route dmic_audio_map[] = { | |
184 | {"DMic", NULL, "Digital Mic1 Bias"}, | |
185 | {"Digital Mic1 Bias", NULL, "Digital Mic"}, | |
186 | }; | |
187 | ||
13f81d65 | 188 | static int omap_abe_dmic_init(struct snd_soc_pcm_runtime *rtd) |
6524c8e3 PU |
189 | { |
190 | struct snd_soc_codec *codec = rtd->codec; | |
191 | struct snd_soc_dapm_context *dapm = &codec->dapm; | |
192 | int ret; | |
193 | ||
13f81d65 PU |
194 | ret = snd_soc_dapm_new_controls(dapm, dmic_dapm_widgets, |
195 | ARRAY_SIZE(dmic_dapm_widgets)); | |
6524c8e3 PU |
196 | if (ret) |
197 | return ret; | |
198 | ||
199 | return snd_soc_dapm_add_routes(dapm, dmic_audio_map, | |
200 | ARRAY_SIZE(dmic_audio_map)); | |
201 | } | |
202 | ||
5e64d6aa | 203 | /* Digital audio interface glue - connects codec <--> CPU */ |
6524c8e3 PU |
204 | static struct snd_soc_dai_link sdp4430_dai[] = { |
205 | { | |
206 | .name = "TWL6040", | |
207 | .stream_name = "TWL6040", | |
208 | .cpu_dai_name = "omap-mcpdm", | |
209 | .codec_dai_name = "twl6040-legacy", | |
210 | .platform_name = "omap-pcm-audio", | |
211 | .codec_name = "twl6040-codec", | |
13f81d65 PU |
212 | .init = omap_abe_twl6040_init, |
213 | .ops = &omap_abe_ops, | |
6524c8e3 PU |
214 | }, |
215 | { | |
216 | .name = "DMIC", | |
217 | .stream_name = "DMIC Capture", | |
218 | .cpu_dai_name = "omap-dmic", | |
219 | .codec_dai_name = "dmic-hifi", | |
220 | .platform_name = "omap-pcm-audio", | |
221 | .codec_name = "dmic-codec", | |
13f81d65 PU |
222 | .init = omap_abe_dmic_init, |
223 | .ops = &omap_abe_dmic_ops, | |
6524c8e3 | 224 | }, |
5e64d6aa MLC |
225 | }; |
226 | ||
227 | /* Audio machine driver */ | |
13f81d65 | 228 | static struct snd_soc_card omap_abe_card = { |
5e64d6aa | 229 | .name = "SDP4430", |
b425b884 | 230 | .owner = THIS_MODULE, |
6524c8e3 PU |
231 | .dai_link = sdp4430_dai, |
232 | .num_links = ARRAY_SIZE(sdp4430_dai), | |
fc8e5b4c | 233 | |
13f81d65 PU |
234 | .dapm_widgets = twl6040_dapm_widgets, |
235 | .num_dapm_widgets = ARRAY_SIZE(twl6040_dapm_widgets), | |
fc8e5b4c PU |
236 | .dapm_routes = audio_map, |
237 | .num_dapm_routes = ARRAY_SIZE(audio_map), | |
5e64d6aa MLC |
238 | }; |
239 | ||
13f81d65 | 240 | static struct platform_device *omap_abe_snd_device; |
5e64d6aa | 241 | |
13f81d65 | 242 | static int __init omap_abe_soc_init(void) |
5e64d6aa MLC |
243 | { |
244 | int ret; | |
245 | ||
ec588ae6 | 246 | if (!machine_is_omap_4430sdp()) |
5e64d6aa | 247 | return -ENODEV; |
5e64d6aa MLC |
248 | printk(KERN_INFO "SDP4430 SoC init\n"); |
249 | ||
13f81d65 PU |
250 | omap_abe_snd_device = platform_device_alloc("soc-audio", -1); |
251 | if (!omap_abe_snd_device) { | |
5e64d6aa MLC |
252 | printk(KERN_ERR "Platform device allocation failed\n"); |
253 | return -ENOMEM; | |
254 | } | |
255 | ||
13f81d65 | 256 | platform_set_drvdata(omap_abe_snd_device, &omap_abe_card); |
5e64d6aa | 257 | |
13f81d65 | 258 | ret = platform_device_add(omap_abe_snd_device); |
5e64d6aa MLC |
259 | if (ret) |
260 | goto err; | |
261 | ||
5e64d6aa MLC |
262 | return 0; |
263 | ||
264 | err: | |
265 | printk(KERN_ERR "Unable to add platform device\n"); | |
13f81d65 | 266 | platform_device_put(omap_abe_snd_device); |
5e64d6aa MLC |
267 | return ret; |
268 | } | |
13f81d65 | 269 | module_init(omap_abe_soc_init); |
5e64d6aa | 270 | |
13f81d65 | 271 | static void __exit omap_abe_soc_exit(void) |
5e64d6aa | 272 | { |
13f81d65 | 273 | platform_device_unregister(omap_abe_snd_device); |
5e64d6aa | 274 | } |
13f81d65 | 275 | module_exit(omap_abe_soc_exit); |
5e64d6aa | 276 | |
8747a6b7 | 277 | MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>"); |
13f81d65 | 278 | MODULE_DESCRIPTION("ALSA SoC for OMAP boards with ABE and twl6040 codec"); |
5e64d6aa MLC |
279 | MODULE_LICENSE("GPL"); |
280 |