blob: 7925851a5de14a3600b91453d78e22f49f095118 [file] [log] [blame]
Vinod Koul55c72032011-01-04 20:16:50 +05301/*
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;
Harsha Priyad3165532011-01-28 22:28:32 +0530185 /* we dont use linein in this so set to NC */
186 snd_soc_dapm_disable_pin(dapm, "LINEINL");
187 snd_soc_dapm_disable_pin(dapm, "LINEINR");
Vinod Koul55c72032011-01-04 20:16:50 +0530188 return snd_soc_dapm_sync(dapm);
189}
190
191struct snd_soc_dai_link mfld_msic_dailink[] = {
192 {
193 .name = "Medfield Headset",
194 .stream_name = "Headset",
195 .cpu_dai_name = "Headset-cpu-dai",
196 .codec_dai_name = "SN95031 Headset",
197 .codec_name = "sn95031",
198 .platform_name = "sst-platform",
199 .init = mfld_init,
200 },
201 {
202 .name = "Medfield Speaker",
203 .stream_name = "Speaker",
204 .cpu_dai_name = "Speaker-cpu-dai",
205 .codec_dai_name = "SN95031 Speaker",
206 .codec_name = "sn95031",
207 .platform_name = "sst-platform",
208 .init = NULL,
209 },
210 {
211 .name = "Medfield Vibra",
212 .stream_name = "Vibra1",
213 .cpu_dai_name = "Vibra1-cpu-dai",
214 .codec_dai_name = "SN95031 Vibra1",
215 .codec_name = "sn95031",
216 .platform_name = "sst-platform",
217 .init = NULL,
218 },
219 {
220 .name = "Medfield Haptics",
221 .stream_name = "Vibra2",
222 .cpu_dai_name = "Vibra2-cpu-dai",
223 .codec_dai_name = "SN95031 Vibra2",
224 .codec_name = "sn95031",
225 .platform_name = "sst-platform",
226 .init = NULL,
227 },
228};
229
230/* SoC card */
231static struct snd_soc_card snd_soc_card_mfld = {
232 .name = "medfield_audio",
233 .dai_link = mfld_msic_dailink,
234 .num_links = ARRAY_SIZE(mfld_msic_dailink),
235};
236
237static int __devinit snd_mfld_mc_probe(struct platform_device *pdev)
238{
239 struct platform_device *socdev;
240 int ret_val = 0;
241
242 pr_debug("snd_mfld_mc_probe called\n");
243
244 socdev = platform_device_alloc("soc-audio", -1);
245 if (!socdev) {
246 pr_err("soc-audio device allocation failed\n");
247 return -ENOMEM;
248 }
249 platform_set_drvdata(socdev, &snd_soc_card_mfld);
250 ret_val = platform_device_add(socdev);
251 if (ret_val) {
252 pr_err("Unable to add soc-audio device, err %d\n", ret_val);
253 platform_device_put(socdev);
254 }
255
256 platform_set_drvdata(pdev, socdev);
257
258 pr_debug("successfully exited probe\n");
259 return ret_val;
260}
261
262static int __devexit snd_mfld_mc_remove(struct platform_device *pdev)
263{
264 struct platform_device *socdev = platform_get_drvdata(pdev);
265 pr_debug("snd_mfld_mc_remove called\n");
266
267 platform_device_unregister(socdev);
268 platform_set_drvdata(pdev, NULL);
269 return 0;
270}
271
272static struct platform_driver snd_mfld_mc_driver = {
273 .driver = {
274 .owner = THIS_MODULE,
275 .name = "msic_audio",
276 },
277 .probe = snd_mfld_mc_probe,
278 .remove = __devexit_p(snd_mfld_mc_remove),
279};
280
281static int __init snd_mfld_driver_init(void)
282{
283 pr_debug("snd_mfld_driver_init called\n");
284 return platform_driver_register(&snd_mfld_mc_driver);
285}
286module_init(snd_mfld_driver_init);
287
288static void __exit snd_mfld_driver_exit(void)
289{
290 pr_debug("snd_mfld_driver_exit called\n");
291 platform_driver_unregister(&snd_mfld_mc_driver);
292}
293module_exit(snd_mfld_driver_exit);
294
295MODULE_DESCRIPTION("ASoC Intel(R) MID Machine driver");
296MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
297MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
298MODULE_LICENSE("GPL v2");
299MODULE_ALIAS("platform:msic-audio");