ASoC: twl6040: Use neutral name for power mode text/enum
[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>
fb34d3d5
MLC
24#include <linux/mfd/twl6040.h>
25
5e64d6aa
MLC
26#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/soc.h>
96dc227c 29#include <sound/jack.h>
5e64d6aa
MLC
30
31#include <asm/mach-types.h>
32#include <plat/hardware.h>
33#include <plat/mux.h>
34
35#include "mcpdm.h"
5e64d6aa
MLC
36#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;
f0fba2ad 45 struct snd_soc_dai *codec_dai = rtd->codec_dai;
5e64d6aa
MLC
46 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 }
f0fba2ad 64 return ret;
5e64d6aa
MLC
65}
66
67static struct snd_soc_ops sdp4430_ops = {
68 .hw_params = sdp4430_hw_params,
69};
70
96dc227c
JEC
71/* 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
5e64d6aa
MLC
86static 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),
7254e2bd 121 SND_SOC_DAPM_SPK("Earphone Spk", NULL),
23ac3b61 122 SND_SOC_DAPM_INPUT("Aux/FM Stereo In"),
5e64d6aa
MLC
123};
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"},
7254e2bd
JEC
142
143 /* Earphone speaker */
144 {"Earphone Spk", NULL, "EP"},
23ac3b61
JEC
145
146 /* Aux/FM Stereo In: AFML, AFMR */
147 {"AFML", NULL, "Aux/FM Stereo In"},
148 {"AFMR", NULL, "Aux/FM Stereo In"},
5e64d6aa
MLC
149};
150
f0fba2ad 151static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
5e64d6aa 152{
f0fba2ad 153 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 154 struct snd_soc_dapm_context *dapm = &codec->dapm;
5e64d6aa
MLC
155 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 */
ce6120cc 164 ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets,
5e64d6aa
MLC
165 ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
166 if (ret)
167 return ret;
168
169 /* Set up SDP4430 specific audio path audio_map */
ce6120cc 170 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
5e64d6aa
MLC
171
172 /* SDP4430 connected pins */
ce6120cc
LG
173 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
174 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
23ac3b61
JEC
175 snd_soc_dapm_enable_pin(dapm, "AFML");
176 snd_soc_dapm_enable_pin(dapm, "AFMR");
ce6120cc
LG
177 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
178 snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
5e64d6aa 179
ce6120cc 180 ret = snd_soc_dapm_sync(dapm);
96dc227c
JEC
181 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);
5e64d6aa
MLC
197
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",
f0fba2ad
LG
205 .cpu_dai_name ="omap-mcpdm-dai",
206 .codec_dai_name = "twl6040-hifi",
207 .platform_name = "omap-pcm-audio",
208 .codec_name = "twl6040-codec",
5e64d6aa 209 .init = sdp4430_twl6040_init,
d8b55d2c 210 .ops = &sdp4430_ops,
5e64d6aa
MLC
211};
212
213/* Audio machine driver */
214static struct snd_soc_card snd_soc_sdp4430 = {
215 .name = "SDP4430",
5e64d6aa
MLC
216 .dai_link = &sdp4430_dai,
217 .num_links = 1,
218};
219
5e64d6aa
MLC
220static struct platform_device *sdp4430_snd_device;
221
222static int __init sdp4430_soc_init(void)
223{
224 int ret;
225
ec588ae6 226 if (!machine_is_omap_4430sdp())
5e64d6aa 227 return -ENODEV;
5e64d6aa
MLC
228 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
f0fba2ad 236 platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430);
5e64d6aa
MLC
237
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
This page took 0.079586 seconds and 5 git commands to generate.