diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /sound/soc/omap/sdp4430.c | |
parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) |
Diffstat (limited to 'sound/soc/omap/sdp4430.c')
-rw-r--r-- | sound/soc/omap/sdp4430.c | 223 |
1 files changed, 223 insertions, 0 deletions
diff --git a/sound/soc/omap/sdp4430.c b/sound/soc/omap/sdp4430.c new file mode 100644 index 00000000000..b80efb02bfc --- /dev/null +++ b/sound/soc/omap/sdp4430.c | |||
@@ -0,0 +1,223 @@ | |||
1 | /* | ||
2 | * sdp4430.c -- SoC audio for TI OMAP4430 SDP | ||
3 | * | ||
4 | * Author: Misael Lopez Cruz <x0052729@ti.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * version 2 as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
18 | * 02110-1301 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <linux/clk.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/mfd/twl6040.h> | ||
25 | |||
26 | #include <sound/core.h> | ||
27 | #include <sound/pcm.h> | ||
28 | #include <sound/soc.h> | ||
29 | #include <sound/jack.h> | ||
30 | |||
31 | #include <asm/mach-types.h> | ||
32 | #include <plat/hardware.h> | ||
33 | #include <plat/mux.h> | ||
34 | |||
35 | #include "mcpdm.h" | ||
36 | #include "omap-pcm.h" | ||
37 | #include "../codecs/twl6040.h" | ||
38 | |||
39 | static int sdp4430_hw_params(struct snd_pcm_substream *substream, | ||
40 | struct snd_pcm_hw_params *params) | ||
41 | { | ||
42 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
43 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
44 | int clk_id, freq; | ||
45 | int ret; | ||
46 | |||
47 | clk_id = twl6040_get_clk_id(rtd->codec); | ||
48 | if (clk_id == TWL6040_SYSCLK_SEL_HPPLL) | ||
49 | freq = 38400000; | ||
50 | else if (clk_id == TWL6040_SYSCLK_SEL_LPPLL) | ||
51 | freq = 32768; | ||
52 | else | ||
53 | return -EINVAL; | ||
54 | |||
55 | /* set the codec mclk */ | ||
56 | ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq, | ||
57 | SND_SOC_CLOCK_IN); | ||
58 | if (ret) { | ||
59 | printk(KERN_ERR "can't set codec system clock\n"); | ||
60 | return ret; | ||
61 | } | ||
62 | return ret; | ||
63 | } | ||
64 | |||
65 | static struct snd_soc_ops sdp4430_ops = { | ||
66 | .hw_params = sdp4430_hw_params, | ||
67 | }; | ||
68 | |||
69 | /* Headset jack */ | ||
70 | static struct snd_soc_jack hs_jack; | ||
71 | |||
72 | /*Headset jack detection DAPM pins */ | ||
73 | static struct snd_soc_jack_pin hs_jack_pins[] = { | ||
74 | { | ||
75 | .pin = "Headset Mic", | ||
76 | .mask = SND_JACK_MICROPHONE, | ||
77 | }, | ||
78 | { | ||
79 | .pin = "Headset Stereophone", | ||
80 | .mask = SND_JACK_HEADPHONE, | ||
81 | }, | ||
82 | }; | ||
83 | |||
84 | /* SDP4430 machine DAPM */ | ||
85 | static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = { | ||
86 | SND_SOC_DAPM_MIC("Ext Mic", NULL), | ||
87 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | ||
88 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | ||
89 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), | ||
90 | SND_SOC_DAPM_SPK("Earphone Spk", NULL), | ||
91 | SND_SOC_DAPM_INPUT("Aux/FM Stereo In"), | ||
92 | }; | ||
93 | |||
94 | static const struct snd_soc_dapm_route audio_map[] = { | ||
95 | /* External Mics: MAINMIC, SUBMIC with bias*/ | ||
96 | {"MAINMIC", NULL, "Main Mic Bias"}, | ||
97 | {"SUBMIC", NULL, "Main Mic Bias"}, | ||
98 | {"Main Mic Bias", NULL, "Ext Mic"}, | ||
99 | |||
100 | /* External Speakers: HFL, HFR */ | ||
101 | {"Ext Spk", NULL, "HFL"}, | ||
102 | {"Ext Spk", NULL, "HFR"}, | ||
103 | |||
104 | /* Headset Mic: HSMIC with bias */ | ||
105 | {"HSMIC", NULL, "Headset Mic Bias"}, | ||
106 | {"Headset Mic Bias", NULL, "Headset Mic"}, | ||
107 | |||
108 | /* Headset Stereophone (Headphone): HSOL, HSOR */ | ||
109 | {"Headset Stereophone", NULL, "HSOL"}, | ||
110 | {"Headset Stereophone", NULL, "HSOR"}, | ||
111 | |||
112 | /* Earphone speaker */ | ||
113 | {"Earphone Spk", NULL, "EP"}, | ||
114 | |||
115 | /* Aux/FM Stereo In: AFML, AFMR */ | ||
116 | {"AFML", NULL, "Aux/FM Stereo In"}, | ||
117 | {"AFMR", NULL, "Aux/FM Stereo In"}, | ||
118 | }; | ||
119 | |||
120 | static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd) | ||
121 | { | ||
122 | struct snd_soc_codec *codec = rtd->codec; | ||
123 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
124 | int ret; | ||
125 | |||
126 | /* Add SDP4430 specific widgets */ | ||
127 | ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets, | ||
128 | ARRAY_SIZE(sdp4430_twl6040_dapm_widgets)); | ||
129 | if (ret) | ||
130 | return ret; | ||
131 | |||
132 | /* Set up SDP4430 specific audio path audio_map */ | ||
133 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); | ||
134 | |||
135 | /* SDP4430 connected pins */ | ||
136 | snd_soc_dapm_enable_pin(dapm, "Ext Mic"); | ||
137 | snd_soc_dapm_enable_pin(dapm, "Ext Spk"); | ||
138 | snd_soc_dapm_enable_pin(dapm, "AFML"); | ||
139 | snd_soc_dapm_enable_pin(dapm, "AFMR"); | ||
140 | snd_soc_dapm_enable_pin(dapm, "Headset Mic"); | ||
141 | snd_soc_dapm_enable_pin(dapm, "Headset Stereophone"); | ||
142 | |||
143 | ret = snd_soc_dapm_sync(dapm); | ||
144 | if (ret) | ||
145 | return ret; | ||
146 | |||
147 | /* Headset jack detection */ | ||
148 | ret = snd_soc_jack_new(codec, "Headset Jack", | ||
149 | SND_JACK_HEADSET, &hs_jack); | ||
150 | if (ret) | ||
151 | return ret; | ||
152 | |||
153 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), | ||
154 | hs_jack_pins); | ||
155 | |||
156 | if (machine_is_omap_4430sdp()) | ||
157 | twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET); | ||
158 | else | ||
159 | snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET); | ||
160 | |||
161 | return ret; | ||
162 | } | ||
163 | |||
164 | /* Digital audio interface glue - connects codec <--> CPU */ | ||
165 | static struct snd_soc_dai_link sdp4430_dai = { | ||
166 | .name = "TWL6040", | ||
167 | .stream_name = "TWL6040", | ||
168 | .cpu_dai_name ="omap-mcpdm-dai", | ||
169 | .codec_dai_name = "twl6040-hifi", | ||
170 | .platform_name = "omap-pcm-audio", | ||
171 | .codec_name = "twl6040-codec", | ||
172 | .init = sdp4430_twl6040_init, | ||
173 | .ops = &sdp4430_ops, | ||
174 | }; | ||
175 | |||
176 | /* Audio machine driver */ | ||
177 | static struct snd_soc_card snd_soc_sdp4430 = { | ||
178 | .name = "SDP4430", | ||
179 | .dai_link = &sdp4430_dai, | ||
180 | .num_links = 1, | ||
181 | }; | ||
182 | |||
183 | static struct platform_device *sdp4430_snd_device; | ||
184 | |||
185 | static int __init sdp4430_soc_init(void) | ||
186 | { | ||
187 | int ret; | ||
188 | |||
189 | if (!machine_is_omap_4430sdp()) | ||
190 | return -ENODEV; | ||
191 | printk(KERN_INFO "SDP4430 SoC init\n"); | ||
192 | |||
193 | sdp4430_snd_device = platform_device_alloc("soc-audio", -1); | ||
194 | if (!sdp4430_snd_device) { | ||
195 | printk(KERN_ERR "Platform device allocation failed\n"); | ||
196 | return -ENOMEM; | ||
197 | } | ||
198 | |||
199 | platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430); | ||
200 | |||
201 | ret = platform_device_add(sdp4430_snd_device); | ||
202 | if (ret) | ||
203 | goto err; | ||
204 | |||
205 | return 0; | ||
206 | |||
207 | err: | ||
208 | printk(KERN_ERR "Unable to add platform device\n"); | ||
209 | platform_device_put(sdp4430_snd_device); | ||
210 | return ret; | ||
211 | } | ||
212 | module_init(sdp4430_soc_init); | ||
213 | |||
214 | static void __exit sdp4430_soc_exit(void) | ||
215 | { | ||
216 | platform_device_unregister(sdp4430_snd_device); | ||
217 | } | ||
218 | module_exit(sdp4430_soc_exit); | ||
219 | |||
220 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); | ||
221 | MODULE_DESCRIPTION("ALSA SoC SDP4430"); | ||
222 | MODULE_LICENSE("GPL"); | ||
223 | |||