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