ASoC: twl6040: Add jack support for headset and handset
[deliverable/linux.git] / sound / soc / omap / sdp4430.c
CommitLineData
5e64d6aa
MLC
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 <sound/core.h>
25#include <sound/pcm.h>
26#include <sound/soc.h>
5e64d6aa
MLC
27
28#include <asm/mach-types.h>
29#include <plat/hardware.h>
30#include <plat/mux.h>
31
32#include "mcpdm.h"
5e64d6aa
MLC
33#include "omap-pcm.h"
34#include "../codecs/twl6040.h"
35
36static int twl6040_power_mode;
37
38static int sdp4430_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
40{
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad 42 struct snd_soc_dai *codec_dai = rtd->codec_dai;
5e64d6aa
MLC
43 int clk_id, freq;
44 int ret;
45
46 if (twl6040_power_mode) {
47 clk_id = TWL6040_SYSCLK_SEL_HPPLL;
48 freq = 38400000;
49 } else {
50 clk_id = TWL6040_SYSCLK_SEL_LPPLL;
51 freq = 32768;
52 }
53
54 /* set the codec mclk */
55 ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq,
56 SND_SOC_CLOCK_IN);
57 if (ret) {
58 printk(KERN_ERR "can't set codec system clock\n");
59 return ret;
60 }
f0fba2ad 61 return ret;
5e64d6aa
MLC
62}
63
64static struct snd_soc_ops sdp4430_ops = {
65 .hw_params = sdp4430_hw_params,
66};
67
68static int sdp4430_get_power_mode(struct snd_kcontrol *kcontrol,
69 struct snd_ctl_elem_value *ucontrol)
70{
71 ucontrol->value.integer.value[0] = twl6040_power_mode;
72 return 0;
73}
74
75static int sdp4430_set_power_mode(struct snd_kcontrol *kcontrol,
76 struct snd_ctl_elem_value *ucontrol)
77{
78 if (twl6040_power_mode == ucontrol->value.integer.value[0])
79 return 0;
80
81 twl6040_power_mode = ucontrol->value.integer.value[0];
82
83 return 1;
84}
85
86static const char *power_texts[] = {"Low-Power", "High-Performance"};
87
88static const struct soc_enum sdp4430_enum[] = {
89 SOC_ENUM_SINGLE_EXT(2, power_texts),
90};
91
92static const struct snd_kcontrol_new sdp4430_controls[] = {
93 SOC_ENUM_EXT("TWL6040 Power Mode", sdp4430_enum[0],
94 sdp4430_get_power_mode, sdp4430_set_power_mode),
95};
96
97/* SDP4430 machine DAPM */
98static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
99 SND_SOC_DAPM_MIC("Ext Mic", NULL),
100 SND_SOC_DAPM_SPK("Ext Spk", NULL),
101 SND_SOC_DAPM_MIC("Headset Mic", NULL),
102 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
7254e2bd 103 SND_SOC_DAPM_SPK("Earphone Spk", NULL),
23ac3b61 104 SND_SOC_DAPM_INPUT("Aux/FM Stereo In"),
5e64d6aa
MLC
105};
106
107static const struct snd_soc_dapm_route audio_map[] = {
108 /* External Mics: MAINMIC, SUBMIC with bias*/
109 {"MAINMIC", NULL, "Main Mic Bias"},
110 {"SUBMIC", NULL, "Main Mic Bias"},
111 {"Main Mic Bias", NULL, "Ext Mic"},
112
113 /* External Speakers: HFL, HFR */
114 {"Ext Spk", NULL, "HFL"},
115 {"Ext Spk", NULL, "HFR"},
116
117 /* Headset Mic: HSMIC with bias */
118 {"HSMIC", NULL, "Headset Mic Bias"},
119 {"Headset Mic Bias", NULL, "Headset Mic"},
120
121 /* Headset Stereophone (Headphone): HSOL, HSOR */
122 {"Headset Stereophone", NULL, "HSOL"},
123 {"Headset Stereophone", NULL, "HSOR"},
7254e2bd
JEC
124
125 /* Earphone speaker */
126 {"Earphone Spk", NULL, "EP"},
23ac3b61
JEC
127
128 /* Aux/FM Stereo In: AFML, AFMR */
129 {"AFML", NULL, "Aux/FM Stereo In"},
130 {"AFMR", NULL, "Aux/FM Stereo In"},
5e64d6aa
MLC
131};
132
f0fba2ad 133static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
5e64d6aa 134{
f0fba2ad 135 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 136 struct snd_soc_dapm_context *dapm = &codec->dapm;
5e64d6aa
MLC
137 int ret;
138
139 /* Add SDP4430 specific controls */
140 ret = snd_soc_add_controls(codec, sdp4430_controls,
141 ARRAY_SIZE(sdp4430_controls));
142 if (ret)
143 return ret;
144
145 /* Add SDP4430 specific widgets */
ce6120cc 146 ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets,
5e64d6aa
MLC
147 ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
148 if (ret)
149 return ret;
150
151 /* Set up SDP4430 specific audio path audio_map */
ce6120cc 152 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
5e64d6aa
MLC
153
154 /* SDP4430 connected pins */
ce6120cc
LG
155 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
156 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
23ac3b61
JEC
157 snd_soc_dapm_enable_pin(dapm, "AFML");
158 snd_soc_dapm_enable_pin(dapm, "AFMR");
ce6120cc
LG
159 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
160 snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
5e64d6aa 161
ce6120cc 162 ret = snd_soc_dapm_sync(dapm);
5e64d6aa
MLC
163
164 return ret;
165}
166
167/* Digital audio interface glue - connects codec <--> CPU */
168static struct snd_soc_dai_link sdp4430_dai = {
169 .name = "TWL6040",
170 .stream_name = "TWL6040",
f0fba2ad
LG
171 .cpu_dai_name ="omap-mcpdm-dai",
172 .codec_dai_name = "twl6040-hifi",
173 .platform_name = "omap-pcm-audio",
174 .codec_name = "twl6040-codec",
5e64d6aa 175 .init = sdp4430_twl6040_init,
d8b55d2c 176 .ops = &sdp4430_ops,
5e64d6aa
MLC
177};
178
179/* Audio machine driver */
180static struct snd_soc_card snd_soc_sdp4430 = {
181 .name = "SDP4430",
5e64d6aa
MLC
182 .dai_link = &sdp4430_dai,
183 .num_links = 1,
184};
185
5e64d6aa
MLC
186static struct platform_device *sdp4430_snd_device;
187
188static int __init sdp4430_soc_init(void)
189{
190 int ret;
191
ec588ae6 192 if (!machine_is_omap_4430sdp())
5e64d6aa 193 return -ENODEV;
5e64d6aa
MLC
194 printk(KERN_INFO "SDP4430 SoC init\n");
195
196 sdp4430_snd_device = platform_device_alloc("soc-audio", -1);
197 if (!sdp4430_snd_device) {
198 printk(KERN_ERR "Platform device allocation failed\n");
199 return -ENOMEM;
200 }
201
f0fba2ad 202 platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430);
5e64d6aa
MLC
203
204 ret = platform_device_add(sdp4430_snd_device);
205 if (ret)
206 goto err;
207
208 /* Codec starts in HP mode */
209 twl6040_power_mode = 1;
210
211 return 0;
212
213err:
214 printk(KERN_ERR "Unable to add platform device\n");
215 platform_device_put(sdp4430_snd_device);
216 return ret;
217}
218module_init(sdp4430_soc_init);
219
220static void __exit sdp4430_soc_exit(void)
221{
222 platform_device_unregister(sdp4430_snd_device);
223}
224module_exit(sdp4430_soc_exit);
225
226MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
227MODULE_DESCRIPTION("ALSA SoC SDP4430");
228MODULE_LICENSE("GPL");
229
This page took 0.05064 seconds and 5 git commands to generate.