blob: 5d67c25bca5e070bd7786f61f62fbf49e573625b [file] [log] [blame]
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -05001/*
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>
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -050024#include <linux/mfd/twl6040.h>
25
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050026#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/soc.h>
Jorge Eduardo Candelaria96dc2272010-12-10 20:45:19 -060029#include <sound/jack.h>
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050030
31#include <asm/mach-types.h>
32#include <plat/hardware.h>
33#include <plat/mux.h>
34
35#include "mcpdm.h"
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050036#include "omap-pcm.h"
37#include "../codecs/twl6040.h"
38
39static int twl6040_power_mode;
40
41static int sdp4430_hw_params(struct snd_pcm_substream *substream,
42 struct snd_pcm_hw_params *params)
43{
44 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000045 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050046 int clk_id, freq;
47 int ret;
48
49 if (twl6040_power_mode) {
50 clk_id = TWL6040_SYSCLK_SEL_HPPLL;
51 freq = 38400000;
52 } else {
53 clk_id = TWL6040_SYSCLK_SEL_LPPLL;
54 freq = 32768;
55 }
56
57 /* set the codec mclk */
58 ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq,
59 SND_SOC_CLOCK_IN);
60 if (ret) {
61 printk(KERN_ERR "can't set codec system clock\n");
62 return ret;
63 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000064 return ret;
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050065}
66
67static struct snd_soc_ops sdp4430_ops = {
68 .hw_params = sdp4430_hw_params,
69};
70
Jorge Eduardo Candelaria96dc2272010-12-10 20:45:19 -060071/* Headset jack */
72static struct snd_soc_jack hs_jack;
73
74/*Headset jack detection DAPM pins */
75static struct snd_soc_jack_pin hs_jack_pins[] = {
76 {
77 .pin = "Headset Mic",
78 .mask = SND_JACK_MICROPHONE,
79 },
80 {
81 .pin = "Headset Stereophone",
82 .mask = SND_JACK_HEADPHONE,
83 },
84};
85
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050086static int sdp4430_get_power_mode(struct snd_kcontrol *kcontrol,
87 struct snd_ctl_elem_value *ucontrol)
88{
89 ucontrol->value.integer.value[0] = twl6040_power_mode;
90 return 0;
91}
92
93static int sdp4430_set_power_mode(struct snd_kcontrol *kcontrol,
94 struct snd_ctl_elem_value *ucontrol)
95{
96 if (twl6040_power_mode == ucontrol->value.integer.value[0])
97 return 0;
98
99 twl6040_power_mode = ucontrol->value.integer.value[0];
100
101 return 1;
102}
103
104static const char *power_texts[] = {"Low-Power", "High-Performance"};
105
106static const struct soc_enum sdp4430_enum[] = {
107 SOC_ENUM_SINGLE_EXT(2, power_texts),
108};
109
110static const struct snd_kcontrol_new sdp4430_controls[] = {
111 SOC_ENUM_EXT("TWL6040 Power Mode", sdp4430_enum[0],
112 sdp4430_get_power_mode, sdp4430_set_power_mode),
113};
114
115/* SDP4430 machine DAPM */
116static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
117 SND_SOC_DAPM_MIC("Ext Mic", NULL),
118 SND_SOC_DAPM_SPK("Ext Spk", NULL),
119 SND_SOC_DAPM_MIC("Headset Mic", NULL),
120 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
Jorge Eduardo Candelaria7254e2b2010-05-18 12:44:17 -0500121 SND_SOC_DAPM_SPK("Earphone Spk", NULL),
Jorge Eduardo Candelaria23ac3b62010-12-08 10:55:05 -0600122 SND_SOC_DAPM_INPUT("Aux/FM Stereo In"),
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500123};
124
125static const struct snd_soc_dapm_route audio_map[] = {
126 /* External Mics: MAINMIC, SUBMIC with bias*/
127 {"MAINMIC", NULL, "Main Mic Bias"},
128 {"SUBMIC", NULL, "Main Mic Bias"},
129 {"Main Mic Bias", NULL, "Ext Mic"},
130
131 /* External Speakers: HFL, HFR */
132 {"Ext Spk", NULL, "HFL"},
133 {"Ext Spk", NULL, "HFR"},
134
135 /* Headset Mic: HSMIC with bias */
136 {"HSMIC", NULL, "Headset Mic Bias"},
137 {"Headset Mic Bias", NULL, "Headset Mic"},
138
139 /* Headset Stereophone (Headphone): HSOL, HSOR */
140 {"Headset Stereophone", NULL, "HSOL"},
141 {"Headset Stereophone", NULL, "HSOR"},
Jorge Eduardo Candelaria7254e2b2010-05-18 12:44:17 -0500142
143 /* Earphone speaker */
144 {"Earphone Spk", NULL, "EP"},
Jorge Eduardo Candelaria23ac3b62010-12-08 10:55:05 -0600145
146 /* Aux/FM Stereo In: AFML, AFMR */
147 {"AFML", NULL, "Aux/FM Stereo In"},
148 {"AFMR", NULL, "Aux/FM Stereo In"},
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500149};
150
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000151static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500152{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000153 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200154 struct snd_soc_dapm_context *dapm = &codec->dapm;
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500155 int ret;
156
157 /* Add SDP4430 specific controls */
158 ret = snd_soc_add_controls(codec, sdp4430_controls,
159 ARRAY_SIZE(sdp4430_controls));
160 if (ret)
161 return ret;
162
163 /* Add SDP4430 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200164 ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets,
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500165 ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
166 if (ret)
167 return ret;
168
169 /* Set up SDP4430 specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200170 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500171
172 /* SDP4430 connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200173 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
174 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
Jorge Eduardo Candelaria23ac3b62010-12-08 10:55:05 -0600175 snd_soc_dapm_enable_pin(dapm, "AFML");
176 snd_soc_dapm_enable_pin(dapm, "AFMR");
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200177 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
178 snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500179
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200180 ret = snd_soc_dapm_sync(dapm);
Jorge Eduardo Candelaria96dc2272010-12-10 20:45:19 -0600181 if (ret)
182 return ret;
183
184 /* Headset jack detection */
185 ret = snd_soc_jack_new(codec, "Headset Jack",
186 SND_JACK_HEADSET, &hs_jack);
187 if (ret)
188 return ret;
189
190 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
191 hs_jack_pins);
192
193 if (machine_is_omap_4430sdp())
194 twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET);
195 else
196 snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET);
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500197
198 return ret;
199}
200
201/* Digital audio interface glue - connects codec <--> CPU */
202static struct snd_soc_dai_link sdp4430_dai = {
203 .name = "TWL6040",
204 .stream_name = "TWL6040",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000205 .cpu_dai_name ="omap-mcpdm-dai",
206 .codec_dai_name = "twl6040-hifi",
207 .platform_name = "omap-pcm-audio",
208 .codec_name = "twl6040-codec",
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500209 .init = sdp4430_twl6040_init,
Liam Girdwoodd8b55d22010-05-19 14:14:51 +0100210 .ops = &sdp4430_ops,
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500211};
212
213/* Audio machine driver */
214static struct snd_soc_card snd_soc_sdp4430 = {
215 .name = "SDP4430",
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500216 .dai_link = &sdp4430_dai,
217 .num_links = 1,
218};
219
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500220static struct platform_device *sdp4430_snd_device;
221
222static int __init sdp4430_soc_init(void)
223{
224 int ret;
225
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300226 if (!machine_is_omap_4430sdp())
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500227 return -ENODEV;
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500228 printk(KERN_INFO "SDP4430 SoC init\n");
229
230 sdp4430_snd_device = platform_device_alloc("soc-audio", -1);
231 if (!sdp4430_snd_device) {
232 printk(KERN_ERR "Platform device allocation failed\n");
233 return -ENOMEM;
234 }
235
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000236 platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430);
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500237
238 ret = platform_device_add(sdp4430_snd_device);
239 if (ret)
240 goto err;
241
242 /* Codec starts in HP mode */
243 twl6040_power_mode = 1;
244
245 return 0;
246
247err:
248 printk(KERN_ERR "Unable to add platform device\n");
249 platform_device_put(sdp4430_snd_device);
250 return ret;
251}
252module_init(sdp4430_soc_init);
253
254static void __exit sdp4430_soc_exit(void)
255{
256 platform_device_unregister(sdp4430_snd_device);
257}
258module_exit(sdp4430_soc_exit);
259
260MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
261MODULE_DESCRIPTION("ALSA SoC SDP4430");
262MODULE_LICENSE("GPL");
263