ASoC: sst_platform: add support for capture stream on headset dai
[deliverable/linux.git] / sound / soc / mid-x86 / mfld_machine.c
CommitLineData
55c72036
VK
1/*
2 * mfld_machine.c - ASoc Machine driver for Intel Medfield MID platform
3 *
4 * Copyright (C) 2010 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com>
6 * Author: Harsha Priya <priya.harsha@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
27#include <linux/init.h>
28#include <linux/device.h>
29#include <linux/slab.h>
30#include <sound/pcm.h>
31#include <sound/pcm_params.h>
32#include <sound/soc.h>
33#include "../codecs/sn95031.h"
34
35#define MID_MONO 1
36#define MID_STEREO 2
37#define MID_MAX_CAP 5
38
39static unsigned int hs_switch;
40static unsigned int lo_dac;
41
42/* sound card controls */
43static const char *headset_switch_text[] = {"Earpiece", "Headset"};
44
45static const char *lo_text[] = {"Vibra", "Headset", "IHF", "None"};
46
47static const struct soc_enum headset_enum =
48 SOC_ENUM_SINGLE_EXT(2, headset_switch_text);
49
50static const struct soc_enum lo_enum =
51 SOC_ENUM_SINGLE_EXT(4, lo_text);
52
53static int headset_get_switch(struct snd_kcontrol *kcontrol,
54 struct snd_ctl_elem_value *ucontrol)
55{
56 ucontrol->value.integer.value[0] = hs_switch;
57 return 0;
58}
59
60static int headset_set_switch(struct snd_kcontrol *kcontrol,
61 struct snd_ctl_elem_value *ucontrol)
62{
63 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
64
65 if (ucontrol->value.integer.value[0] == hs_switch)
66 return 0;
67
68 if (ucontrol->value.integer.value[0]) {
69 pr_debug("hs_set HS path\n");
70 snd_soc_dapm_enable_pin(&codec->dapm, "HPOUTL");
71 snd_soc_dapm_enable_pin(&codec->dapm, "HPOUTR");
72 snd_soc_dapm_disable_pin(&codec->dapm, "EPOUT");
73 } else {
74 pr_debug("hs_set EP path\n");
75 snd_soc_dapm_disable_pin(&codec->dapm, "HPOUTL");
76 snd_soc_dapm_disable_pin(&codec->dapm, "HPOUTR");
77 snd_soc_dapm_enable_pin(&codec->dapm, "EPOUT");
78 }
79 snd_soc_dapm_sync(&codec->dapm);
80 hs_switch = ucontrol->value.integer.value[0];
81
82 return 0;
83}
84
85static void lo_enable_out_pins(struct snd_soc_codec *codec)
86{
87 snd_soc_dapm_enable_pin(&codec->dapm, "IHFOUTL");
88 snd_soc_dapm_enable_pin(&codec->dapm, "IHFOUTR");
89 snd_soc_dapm_enable_pin(&codec->dapm, "LINEOUTL");
90 snd_soc_dapm_enable_pin(&codec->dapm, "LINEOUTR");
91 snd_soc_dapm_enable_pin(&codec->dapm, "VIB1OUT");
92 snd_soc_dapm_enable_pin(&codec->dapm, "VIB2OUT");
93 if (hs_switch) {
94 snd_soc_dapm_enable_pin(&codec->dapm, "HPOUTL");
95 snd_soc_dapm_enable_pin(&codec->dapm, "HPOUTR");
96 snd_soc_dapm_disable_pin(&codec->dapm, "EPOUT");
97 } else {
98 snd_soc_dapm_disable_pin(&codec->dapm, "HPOUTL");
99 snd_soc_dapm_disable_pin(&codec->dapm, "HPOUTR");
100 snd_soc_dapm_enable_pin(&codec->dapm, "EPOUT");
101 }
102}
103
104static int lo_get_switch(struct snd_kcontrol *kcontrol,
105 struct snd_ctl_elem_value *ucontrol)
106{
107 ucontrol->value.integer.value[0] = lo_dac;
108 return 0;
109}
110
111static int lo_set_switch(struct snd_kcontrol *kcontrol,
112 struct snd_ctl_elem_value *ucontrol)
113{
114 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
115
116 if (ucontrol->value.integer.value[0] == lo_dac)
117 return 0;
118
119 /* we dont want to work with last state of lineout so just enable all
120 * pins and then disable pins not required
121 */
122 lo_enable_out_pins(codec);
123 switch (ucontrol->value.integer.value[0]) {
124 case 0:
125 pr_debug("set vibra path\n");
126 snd_soc_dapm_disable_pin(&codec->dapm, "VIB1OUT");
127 snd_soc_dapm_disable_pin(&codec->dapm, "VIB2OUT");
128 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0);
129 break;
130
131 case 1:
132 pr_debug("set hs path\n");
133 snd_soc_dapm_disable_pin(&codec->dapm, "HPOUTL");
134 snd_soc_dapm_disable_pin(&codec->dapm, "HPOUTR");
135 snd_soc_dapm_disable_pin(&codec->dapm, "EPOUT");
136 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0x22);
137 break;
138
139 case 2:
140 pr_debug("set spkr path\n");
141 snd_soc_dapm_disable_pin(&codec->dapm, "IHFOUTL");
142 snd_soc_dapm_disable_pin(&codec->dapm, "IHFOUTR");
143 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0x44);
144 break;
145
146 case 3:
147 pr_debug("set null path\n");
148 snd_soc_dapm_disable_pin(&codec->dapm, "LINEOUTL");
149 snd_soc_dapm_disable_pin(&codec->dapm, "LINEOUTR");
150 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0x66);
151 break;
152 }
153 snd_soc_dapm_sync(&codec->dapm);
154 lo_dac = ucontrol->value.integer.value[0];
155 return 0;
156}
157
158static const struct snd_kcontrol_new mfld_snd_controls[] = {
159 SOC_ENUM_EXT("Playback Switch", headset_enum,
160 headset_get_switch, headset_set_switch),
161 SOC_ENUM_EXT("Lineout Mux", lo_enum,
162 lo_get_switch, lo_set_switch),
163};
164
165static int mfld_init(struct snd_soc_pcm_runtime *runtime)
166{
167 struct snd_soc_codec *codec = runtime->codec;
168 struct snd_soc_dapm_context *dapm = &codec->dapm;
169 int ret_val;
170
171 ret_val = snd_soc_add_controls(codec, mfld_snd_controls,
172 ARRAY_SIZE(mfld_snd_controls));
173 if (ret_val) {
174 pr_err("soc_add_controls failed %d", ret_val);
175 return ret_val;
176 }
177 /* default is earpiece pin, userspace sets it explcitly */
178 snd_soc_dapm_disable_pin(dapm, "HPOUTL");
179 snd_soc_dapm_disable_pin(dapm, "HPOUTR");
180 /* default is lineout NC, userspace sets it explcitly */
181 snd_soc_dapm_disable_pin(dapm, "LINEOUTL");
182 snd_soc_dapm_disable_pin(dapm, "LINEOUTR");
183 lo_dac = 3;
184 hs_switch = 0;
185 return snd_soc_dapm_sync(dapm);
186}
187
188struct snd_soc_dai_link mfld_msic_dailink[] = {
189 {
190 .name = "Medfield Headset",
191 .stream_name = "Headset",
192 .cpu_dai_name = "Headset-cpu-dai",
193 .codec_dai_name = "SN95031 Headset",
194 .codec_name = "sn95031",
195 .platform_name = "sst-platform",
196 .init = mfld_init,
197 },
198 {
199 .name = "Medfield Speaker",
200 .stream_name = "Speaker",
201 .cpu_dai_name = "Speaker-cpu-dai",
202 .codec_dai_name = "SN95031 Speaker",
203 .codec_name = "sn95031",
204 .platform_name = "sst-platform",
205 .init = NULL,
206 },
207 {
208 .name = "Medfield Vibra",
209 .stream_name = "Vibra1",
210 .cpu_dai_name = "Vibra1-cpu-dai",
211 .codec_dai_name = "SN95031 Vibra1",
212 .codec_name = "sn95031",
213 .platform_name = "sst-platform",
214 .init = NULL,
215 },
216 {
217 .name = "Medfield Haptics",
218 .stream_name = "Vibra2",
219 .cpu_dai_name = "Vibra2-cpu-dai",
220 .codec_dai_name = "SN95031 Vibra2",
221 .codec_name = "sn95031",
222 .platform_name = "sst-platform",
223 .init = NULL,
224 },
225};
226
227/* SoC card */
228static struct snd_soc_card snd_soc_card_mfld = {
229 .name = "medfield_audio",
230 .dai_link = mfld_msic_dailink,
231 .num_links = ARRAY_SIZE(mfld_msic_dailink),
232};
233
234static int __devinit snd_mfld_mc_probe(struct platform_device *pdev)
235{
236 struct platform_device *socdev;
237 int ret_val = 0;
238
239 pr_debug("snd_mfld_mc_probe called\n");
240
241 socdev = platform_device_alloc("soc-audio", -1);
242 if (!socdev) {
243 pr_err("soc-audio device allocation failed\n");
244 return -ENOMEM;
245 }
246 platform_set_drvdata(socdev, &snd_soc_card_mfld);
247 ret_val = platform_device_add(socdev);
248 if (ret_val) {
249 pr_err("Unable to add soc-audio device, err %d\n", ret_val);
250 platform_device_put(socdev);
251 }
252
253 platform_set_drvdata(pdev, socdev);
254
255 pr_debug("successfully exited probe\n");
256 return ret_val;
257}
258
259static int __devexit snd_mfld_mc_remove(struct platform_device *pdev)
260{
261 struct platform_device *socdev = platform_get_drvdata(pdev);
262 pr_debug("snd_mfld_mc_remove called\n");
263
264 platform_device_unregister(socdev);
265 platform_set_drvdata(pdev, NULL);
266 return 0;
267}
268
269static struct platform_driver snd_mfld_mc_driver = {
270 .driver = {
271 .owner = THIS_MODULE,
272 .name = "msic_audio",
273 },
274 .probe = snd_mfld_mc_probe,
275 .remove = __devexit_p(snd_mfld_mc_remove),
276};
277
278static int __init snd_mfld_driver_init(void)
279{
280 pr_debug("snd_mfld_driver_init called\n");
281 return platform_driver_register(&snd_mfld_mc_driver);
282}
283module_init(snd_mfld_driver_init);
284
285static void __exit snd_mfld_driver_exit(void)
286{
287 pr_debug("snd_mfld_driver_exit called\n");
288 platform_driver_unregister(&snd_mfld_mc_driver);
289}
290module_exit(snd_mfld_driver_exit);
291
292MODULE_DESCRIPTION("ASoC Intel(R) MID Machine driver");
293MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
294MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
295MODULE_LICENSE("GPL v2");
296MODULE_ALIAS("platform:msic-audio");
This page took 0.036665 seconds and 5 git commands to generate.