blob: bffd2ae1ae462746d6d4994f3eb6b138089458c5 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/clk.h>
14#include <linux/gpio.h>
15#include <linux/mfd/pm8xxx/pm8921.h>
16#include <linux/platform_device.h>
17#include <linux/gpio.h>
18#include <linux/mfd/pm8xxx/pm8921.h>
19#include <sound/core.h>
20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22#include <sound/soc-dsp.h>
23#include <sound/pcm.h>
24#include <sound/jack.h>
Bradley Rubin229c6a52011-07-12 16:18:48 -070025#include <asm/mach-types.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026#include "msm-pcm-routing.h"
27#include <../codecs/wcd9310.h>
28
29/* 8960 machine driver */
30
31#define PM8921_GPIO_BASE NR_GPIO_IRQS
32#define PM8921_GPIO_PM_TO_SYS(pm_gpio) (pm_gpio - 1 + PM8921_GPIO_BASE)
33
34#define MSM_CDC_PAMPL (PM8921_GPIO_PM_TO_SYS(18))
35#define MSM_CDC_PAMPR (PM8921_GPIO_PM_TO_SYS(19))
36#define MSM8960_SPK_ON 1
37#define MSM8960_SPK_OFF 0
38
39#define msm8960_SLIM_0_RX_MAX_CHANNELS 2
40#define msm8960_SLIM_0_TX_MAX_CHANNELS 4
41
42
43static int msm8960_spk_control;
44static int msm8960_pamp_on;
45static int msm8960_slim_0_rx_ch = 1;
46static int msm8960_slim_0_tx_ch = 1;
47
48struct tabla_mbhc_calibration tabla_cal = {
49 .bias = TABLA_MICBIAS2,
50 .tldoh = 100,
51 .bg_fast_settle = 100,
52 .mic_current = TABLA_PID_MIC_5_UA,
53 .mic_pid = 100,
54 .hph_current = TABLA_PID_MIC_5_UA,
55 .setup_plug_removal_delay = 1000000,
56 .shutdown_plug_removal = 100000,
57};
58
59static struct clk *codec_clk;
60static int clk_users;
61
62static int msm8960_headset_gpios_configured;
63
64static struct snd_soc_jack hs_jack;
Bradley Rubincb1e2732011-06-23 16:49:20 -070065static struct snd_soc_jack button_jack;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066
67static void codec_poweramp_on(void)
68{
69 int ret = 0;
70
71 struct pm_gpio param = {
72 .direction = PM_GPIO_DIR_OUT,
73 .output_buffer = PM_GPIO_OUT_BUF_CMOS,
74 .output_value = 1,
75 .pull = PM_GPIO_PULL_NO,
76 .vin_sel = PM_GPIO_VIN_S4,
77 .out_strength = PM_GPIO_STRENGTH_MED,
78 .function = PM_GPIO_FUNC_NORMAL,
79 };
80
81 if (msm8960_pamp_on)
82 return;
83
84 pr_debug("%s: enable stereo spkr amp\n", __func__);
85 ret = gpio_request(MSM_CDC_PAMPL, "CDC PAMP1");
86 if (ret) {
87 pr_err("%s: Error requesting GPIO %d\n", __func__,
88 MSM_CDC_PAMPL);
89 return;
90 }
91 ret = pm8xxx_gpio_config(MSM_CDC_PAMPL, &param);
92 if (ret)
93 pr_err("%s: Failed to configure gpio %d\n", __func__,
94 MSM_CDC_PAMPL);
95 else
96 gpio_direction_output(MSM_CDC_PAMPL, 1);
97
98 ret = gpio_request(MSM_CDC_PAMPR, "CDC PAMPL");
99 if (ret) {
100 pr_err("%s: Error requesting GPIO %d\n", __func__,
101 MSM_CDC_PAMPR);
102 gpio_free(MSM_CDC_PAMPL);
103 return;
104 }
105 ret = pm8xxx_gpio_config(MSM_CDC_PAMPR, &param);
106 if (ret)
107 pr_err("%s: Failed to configure gpio %d\n", __func__,
108 MSM_CDC_PAMPR);
109 else
110 gpio_direction_output(MSM_CDC_PAMPR, 1);
111
112 msm8960_pamp_on = 1;
113}
114static void codec_poweramp_off(void)
115{
116 if (!msm8960_pamp_on)
117 return;
118
119 pr_debug("%s: disable stereo spkr amp\n", __func__);
120 gpio_direction_output(MSM_CDC_PAMPL, 0);
121 gpio_free(MSM_CDC_PAMPL);
122 gpio_direction_output(MSM_CDC_PAMPR, 0);
123 gpio_free(MSM_CDC_PAMPR);
124 msm8960_pamp_on = 0;
125}
126static void msm8960_ext_control(struct snd_soc_codec *codec)
127{
128 struct snd_soc_dapm_context *dapm = &codec->dapm;
129
130 pr_debug("%s: msm8960_spk_control = %d", __func__, msm8960_spk_control);
131 if (msm8960_spk_control == MSM8960_SPK_ON)
132 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
133 else
134 snd_soc_dapm_disable_pin(dapm, "Ext Spk");
135
136 snd_soc_dapm_sync(dapm);
137}
138
139static int msm8960_get_spk(struct snd_kcontrol *kcontrol,
140 struct snd_ctl_elem_value *ucontrol)
141{
142 pr_debug("%s: msm8960_spk_control = %d", __func__, msm8960_spk_control);
143 ucontrol->value.integer.value[0] = msm8960_spk_control;
144 return 0;
145}
146static int msm8960_set_spk(struct snd_kcontrol *kcontrol,
147 struct snd_ctl_elem_value *ucontrol)
148{
149 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
150
151 pr_debug("%s()\n", __func__);
152 if (msm8960_spk_control == ucontrol->value.integer.value[0])
153 return 0;
154
155 msm8960_spk_control = ucontrol->value.integer.value[0];
156 msm8960_ext_control(codec);
157 return 1;
158}
159static int msm8960_spkramp_event(struct snd_soc_dapm_widget *w,
160 struct snd_kcontrol *k, int event)
161{
162 pr_debug("%s() %x\n", __func__, SND_SOC_DAPM_EVENT_ON(event));
163 if (SND_SOC_DAPM_EVENT_ON(event))
164 codec_poweramp_on();
165 else
166 codec_poweramp_off();
167 return 0;
168}
169
170static const struct snd_soc_dapm_widget msm8960_dapm_widgets[] = {
171 SND_SOC_DAPM_SPK("Ext Spk", msm8960_spkramp_event),
172 SND_SOC_DAPM_MIC("Handset Mic", NULL),
173 SND_SOC_DAPM_MIC("Headset Mic", NULL),
174 SND_SOC_DAPM_MIC("Digital Mic1", NULL),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700175 SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
176 SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
Kiran Kandia21d6bc2011-07-17 21:19:59 -0700177
178 /* Digital Mic1. Front Bottom left Digital Mic on Fluid and MTP. */
179 SND_SOC_DAPM_MIC("Digital Mic1", NULL),
180
181 /* Digital Mic2. Front Bottom right Digital Mic on Fluid and MTP. */
182 SND_SOC_DAPM_MIC("Digital Mic2", NULL),
183
184 /* Digital Mic4. Back Top Digital Mic on Fluid. */
185 SND_SOC_DAPM_MIC("Digital Mic4", NULL),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186};
187
Bradley Rubin229c6a52011-07-12 16:18:48 -0700188static const struct snd_soc_dapm_route common_audio_map[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189 /* Speaker path */
190 {"Ext Spk", NULL, "LINEOUT"},
191
192 /* Microphone path */
Bradley Rubin229c6a52011-07-12 16:18:48 -0700193 {"AMIC1", NULL, "MIC BIAS1 Internal1"},
194 {"MIC BIAS1 Internal1", NULL, "Handset Mic"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700195
196 {"AMIC2", NULL, "MIC BIAS2 External"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197 {"MIC BIAS2 External", NULL, "Headset Mic"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700198
Kiran Kandia21d6bc2011-07-17 21:19:59 -0700199 /**
200 * Digital Mic1. Front Bottom left Digital Mic on Fluid and MTP.
201 * Conncted to DMIC2 Input on Tabla codec.
202 */
203 {"DMIC2", NULL, "MIC BIAS1 External"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700204 {"MIC BIAS1 External", NULL, "Digital Mic1"},
Kiran Kandia21d6bc2011-07-17 21:19:59 -0700205
206 /**
207 * Digital Mic2. Front Bottom right Digital Mic on Fluid and MTP.
208 * Conncted to DMIC1 Input on Tabla codec.
209 */
210 {"DMIC1", NULL, "MIC BIAS1 External"},
211 {"MIC BIAS1 External", NULL, "Digital Mic2"},
212
213 /**
214 * Digital Mic4. Back top Digital Mic on Fluid.
215 * Conncted to DMIC3 Input on Tabla codec.
216 */
217 {"DMIC3", NULL, "MIC BIAS3 External"},
218 {"MIC BIAS3 External", NULL, "Digital Mic4"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219};
220
Bradley Rubin229c6a52011-07-12 16:18:48 -0700221static const struct snd_soc_dapm_route cdp_audio_map[] = {
222 {"AMIC3", NULL, "MIC BIAS3 External"},
223 {"MIC BIAS3 External", NULL, "ANCRight Headset Mic"},
224
225 {"AMIC4", NULL, "MIC BIAS4 External"},
226 {"MIC BIAS4 External", NULL, "ANCLeft Headset Mic"},
227};
228
229static const struct snd_soc_dapm_route fluid_audio_map[] = {
230 {"AMIC3", NULL, "MIC BIAS3 Internal1"},
231 {"MIC BIAS3 Internal1", NULL, "ANCRight Headset Mic"},
232
233 {"AMIC4", NULL, "MIC BIAS1 Internal2"},
234 {"MIC BIAS1 Internal2", NULL, "ANCLeft Headset Mic"},
235};
236
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700237static const char *spk_function[] = {"Off", "On"};
Patrick Lai9f4b4292011-07-16 22:11:09 -0700238static const char *slim0_rx_ch_text[] = {"One", "Two"};
239static const char *slim0_tx_ch_text[] = {"One", "Two", "Three", "Four"};
240
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700241static const struct soc_enum msm8960_enum[] = {
242 SOC_ENUM_SINGLE_EXT(2, spk_function),
Patrick Lai9f4b4292011-07-16 22:11:09 -0700243 SOC_ENUM_SINGLE_EXT(2, slim0_rx_ch_text),
244 SOC_ENUM_SINGLE_EXT(4, slim0_tx_ch_text),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700245};
246
247static int msm8960_slim_0_rx_ch_get(struct snd_kcontrol *kcontrol,
248 struct snd_ctl_elem_value *ucontrol)
249{
Patrick Lai9f4b4292011-07-16 22:11:09 -0700250 pr_debug("%s: msm8960_slim_0_rx_ch = %d\n", __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700251 msm8960_slim_0_rx_ch);
Patrick Lai9f4b4292011-07-16 22:11:09 -0700252 ucontrol->value.integer.value[0] = msm8960_slim_0_rx_ch - 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700253 return 0;
254}
255
256static int msm8960_slim_0_rx_ch_put(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_value *ucontrol)
258{
Patrick Lai9f4b4292011-07-16 22:11:09 -0700259 msm8960_slim_0_rx_ch = ucontrol->value.integer.value[0] + 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700260
Patrick Lai9f4b4292011-07-16 22:11:09 -0700261 pr_debug("%s: msm8960_slim_0_rx_ch = %d\n", __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700262 msm8960_slim_0_rx_ch);
263 return 1;
264}
265
266static int msm8960_slim_0_tx_ch_get(struct snd_kcontrol *kcontrol,
267 struct snd_ctl_elem_value *ucontrol)
268{
Patrick Lai9f4b4292011-07-16 22:11:09 -0700269 pr_debug("%s: msm8960_slim_0_tx_ch = %d\n", __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700270 msm8960_slim_0_tx_ch);
Patrick Lai9f4b4292011-07-16 22:11:09 -0700271 ucontrol->value.integer.value[0] = msm8960_slim_0_tx_ch - 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700272 return 0;
273}
274
275static int msm8960_slim_0_tx_ch_put(struct snd_kcontrol *kcontrol,
276 struct snd_ctl_elem_value *ucontrol)
277{
Patrick Lai9f4b4292011-07-16 22:11:09 -0700278 msm8960_slim_0_tx_ch = ucontrol->value.integer.value[0] + 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700279
280 pr_debug("%s: msm8960_slim_0_tx_ch = %d\n", __func__,
281 msm8960_slim_0_tx_ch);
282 return 1;
283}
284
285
286static const struct snd_kcontrol_new tabla_msm8960_controls[] = {
287 SOC_ENUM_EXT("Speaker Function", msm8960_enum[0], msm8960_get_spk,
288 msm8960_set_spk),
Patrick Lai9f4b4292011-07-16 22:11:09 -0700289 SOC_ENUM_EXT("SLIM_0_RX Channels", msm8960_enum[1],
290 msm8960_slim_0_rx_ch_get, msm8960_slim_0_rx_ch_put),
291 SOC_ENUM_EXT("SLIM_0_TX Channels", msm8960_enum[2],
292 msm8960_slim_0_tx_ch_get, msm8960_slim_0_tx_ch_put),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293};
294
295static int msm8960_audrx_init(struct snd_soc_pcm_runtime *rtd)
296{
297 int err;
298 struct snd_soc_codec *codec = rtd->codec;
299 struct snd_soc_dapm_context *dapm = &codec->dapm;
300
301 pr_debug("%s()\n", __func__);
302
303 err = snd_soc_add_controls(codec, tabla_msm8960_controls,
304 ARRAY_SIZE(tabla_msm8960_controls));
305 if (err < 0)
306 return err;
307
308 snd_soc_dapm_new_controls(dapm, msm8960_dapm_widgets,
309 ARRAY_SIZE(msm8960_dapm_widgets));
310
Bradley Rubin229c6a52011-07-12 16:18:48 -0700311 snd_soc_dapm_add_routes(dapm, common_audio_map,
312 ARRAY_SIZE(common_audio_map));
313
314 if (machine_is_msm8960_cdp())
315 snd_soc_dapm_add_routes(dapm, cdp_audio_map,
316 ARRAY_SIZE(cdp_audio_map));
317 else if (machine_is_msm8960_mtp())
318 snd_soc_dapm_add_routes(dapm, cdp_audio_map,
319 ARRAY_SIZE(cdp_audio_map));
320 else if (machine_is_msm8960_fluid())
321 snd_soc_dapm_add_routes(dapm, fluid_audio_map,
322 ARRAY_SIZE(fluid_audio_map));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700323
324 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
325
326 snd_soc_dapm_sync(dapm);
327
328 err = snd_soc_jack_new(codec, "Headset Jack",
329 SND_JACK_HEADSET, &hs_jack);
330 if (err) {
331 pr_err("failed to create new jack\n");
332 return err;
333 }
Bradley Rubincb1e2732011-06-23 16:49:20 -0700334
335 err = snd_soc_jack_new(codec, "Button Jack",
336 SND_JACK_BTN_0, &button_jack);
337 if (err) {
338 pr_err("failed to create new jack\n");
339 return err;
340 }
341
342 tabla_hs_detect(codec, &hs_jack, &button_jack, &tabla_cal);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700343
344 return 0;
345}
346
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700347static struct snd_soc_dsp_link lpa_fe_media = {
Patrick Lai5b3fdfc2011-09-01 11:04:56 -0700348 .playback = true,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700349 .trigger = {
350 SND_SOC_DSP_TRIGGER_POST,
351 SND_SOC_DSP_TRIGGER_POST
352 },
353};
354
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700355static struct snd_soc_dsp_link fe_media = {
Patrick Lai5b3fdfc2011-09-01 11:04:56 -0700356 .playback = true,
357 .capture = true,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700358 .trigger = {
359 SND_SOC_DSP_TRIGGER_POST,
360 SND_SOC_DSP_TRIGGER_POST
361 },
362};
363
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700364static struct snd_soc_dsp_link slimbus0_hl_media = {
Patrick Lai5b3fdfc2011-09-01 11:04:56 -0700365 .playback = true,
366 .capture = true,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700367 .trigger = {
368 SND_SOC_DSP_TRIGGER_POST,
369 SND_SOC_DSP_TRIGGER_POST
370 },
371};
372
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700373static struct snd_soc_dsp_link int_fm_hl_media = {
Patrick Lai5b3fdfc2011-09-01 11:04:56 -0700374 .playback = true,
375 .capture = true,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700376 .trigger = {
377 SND_SOC_DSP_TRIGGER_POST,
378 SND_SOC_DSP_TRIGGER_POST
379 },
380};
381
382static int msm8960_slim_0_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
383 struct snd_pcm_hw_params *params)
384{
385 struct snd_interval *rate = hw_param_interval(params,
386 SNDRV_PCM_HW_PARAM_RATE);
387
388 struct snd_interval *channels = hw_param_interval(params,
389 SNDRV_PCM_HW_PARAM_CHANNELS);
390
391 pr_debug("%s()\n", __func__);
392 rate->min = rate->max = 48000;
393 channels->min = channels->max = msm8960_slim_0_rx_ch;
394
395 return 0;
396}
397
398static int msm8960_slim_0_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
399 struct snd_pcm_hw_params *params)
400{
401 struct snd_interval *rate = hw_param_interval(params,
402 SNDRV_PCM_HW_PARAM_RATE);
403
404 struct snd_interval *channels = hw_param_interval(params,
405 SNDRV_PCM_HW_PARAM_CHANNELS);
406
407 pr_debug("%s()\n", __func__);
408 rate->min = rate->max = 48000;
409 channels->min = channels->max = msm8960_slim_0_tx_ch;
410
411 return 0;
412}
413
414static int msm8960_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
415 struct snd_pcm_hw_params *params)
416{
417 struct snd_interval *rate = hw_param_interval(params,
418 SNDRV_PCM_HW_PARAM_RATE);
419
420 pr_debug("%s()\n", __func__);
421 rate->min = rate->max = 48000;
422
423 return 0;
424}
425
426static int msm8960_startup(struct snd_pcm_substream *substream)
427{
428 if (clk_users++)
429 return 0;
430
431 codec_clk = clk_get(NULL, "i2s_spkr_osr_clk");
432 if (codec_clk) {
433 clk_set_rate(codec_clk, 12288000);
434 clk_enable(codec_clk);
435 } else {
436 pr_err("%s: Error setting Tabla MCLK\n", __func__);
437 clk_users--;
438 return -EINVAL;
439 }
440 return 0;
441}
442
443static void msm8960_shutdown(struct snd_pcm_substream *substream)
444{
445 clk_users--;
446 if (!clk_users) {
447 clk_disable(codec_clk);
448 clk_put(codec_clk);
449 }
450}
451
452static struct snd_soc_ops msm8960_be_ops = {
453 .startup = msm8960_startup,
454 .shutdown = msm8960_shutdown,
455};
456
457/* Digital audio interface glue - connects codec <---> CPU */
458static struct snd_soc_dai_link msm8960_dai[] = {
459 /* FrontEnd DAI Links */
460 {
461 .name = "MSM8960 Media1",
462 .stream_name = "MultiMedia1",
463 .cpu_dai_name = "MultiMedia1",
464 .platform_name = "msm-pcm-dsp",
465 .dynamic = 1,
466 .dsp_link = &fe_media,
467 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA1
468 },
469 {
470 .name = "MSM8960 Media2",
471 .stream_name = "MultiMedia2",
472 .cpu_dai_name = "MultiMedia2",
473 .platform_name = "msm-pcm-dsp",
474 .dynamic = 1,
475 .dsp_link = &fe_media,
476 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA2,
477 },
478 {
479 .name = "Circuit-Switch Voice",
480 .stream_name = "CS-Voice",
481 .cpu_dai_name = "CS-VOICE",
482 .platform_name = "msm-pcm-voice",
483 .dynamic = 1,
484 .dsp_link = &fe_media,
485 .be_id = MSM_FRONTEND_DAI_CS_VOICE,
486 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
487 },
488 {
489 .name = "MSM VoIP",
490 .stream_name = "VoIP",
491 .cpu_dai_name = "VoIP",
492 .platform_name = "msm-voip-dsp",
493 .dynamic = 1,
494 .dsp_link = &fe_media,
495 .be_id = MSM_FRONTEND_DAI_VOIP,
496 },
497 {
498 .name = "MSM8960 LPA",
499 .stream_name = "LPA",
500 .cpu_dai_name = "MultiMedia3",
501 .platform_name = "msm-pcm-lpa",
502 .dynamic = 1,
503 .dsp_link = &lpa_fe_media,
504 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA3,
505 },
506 /* Hostless PMC purpose */
507 {
508 .name = "SLIMBUS_0 Hostless",
509 .stream_name = "SLIMBUS_0 Hostless",
510 .cpu_dai_name = "SLIMBUS0_HOSTLESS",
511 .platform_name = "msm-pcm-hostless",
512 .dynamic = 1,
513 .dsp_link = &slimbus0_hl_media,
514 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
515 /* .be_id = do not care */
516 },
517 {
518 .name = "INT_FM Hostless",
519 .stream_name = "INT_FM Hostless",
520 .cpu_dai_name = "INT_FM_HOSTLESS",
521 .platform_name = "msm-pcm-hostless",
522 .dynamic = 1,
523 .dsp_link = &int_fm_hl_media,
524 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
525 /* .be_id = do not care */
526 },
527 /* Backend DAI Links */
528 {
529 .name = LPASS_BE_SLIMBUS_0_RX,
530 .stream_name = "Slimbus Playback",
531 .cpu_dai_name = "msm-dai-q6.16384",
532 .platform_name = "msm-pcm-routing",
533 .codec_name = "tabla_codec",
534 .codec_dai_name = "tabla_rx1",
535 .no_pcm = 1,
536 .be_id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
537 .init = &msm8960_audrx_init,
538 .be_hw_params_fixup = msm8960_slim_0_rx_be_hw_params_fixup,
539 .ops = &msm8960_be_ops,
540 },
541 {
542 .name = LPASS_BE_SLIMBUS_0_TX,
543 .stream_name = "Slimbus Capture",
544 .cpu_dai_name = "msm-dai-q6.16385",
545 .platform_name = "msm-pcm-routing",
546 .codec_name = "tabla_codec",
547 .codec_dai_name = "tabla_tx1",
548 .no_pcm = 1,
549 .be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
550 .be_hw_params_fixup = msm8960_slim_0_tx_be_hw_params_fixup,
551 .ops = &msm8960_be_ops,
552 },
553 /* Backend BT/FM DAI Links */
554 {
555 .name = LPASS_BE_INT_BT_SCO_RX,
556 .stream_name = "Internal BT-SCO Playback",
557 .cpu_dai_name = "msm-dai-q6.12288",
558 .platform_name = "msm-pcm-routing",
559 .codec_name = "msm-stub-codec.1",
560 .codec_dai_name = "msm-stub-rx",
561 .no_pcm = 1,
562 .be_id = MSM_BACKEND_DAI_INT_BT_SCO_RX,
563 },
564 {
565 .name = LPASS_BE_INT_BT_SCO_TX,
566 .stream_name = "Internal BT-SCO Capture",
567 .cpu_dai_name = "msm-dai-q6.12289",
568 .platform_name = "msm-pcm-routing",
569 .codec_name = "msm-stub-codec.1",
570 .codec_dai_name = "msm-stub-tx",
571 .no_pcm = 1,
572 .be_id = MSM_BACKEND_DAI_INT_BT_SCO_TX,
573 },
574 {
575 .name = LPASS_BE_INT_FM_RX,
576 .stream_name = "Internal FM Playback",
577 .cpu_dai_name = "msm-dai-q6.12292",
578 .platform_name = "msm-pcm-routing",
579 .codec_name = "msm-stub-codec.1",
580 .codec_dai_name = "msm-stub-rx",
581 .no_pcm = 1,
582 .be_id = MSM_BACKEND_DAI_INT_FM_RX,
583 .be_hw_params_fixup = msm8960_be_hw_params_fixup,
584 },
585 {
586 .name = LPASS_BE_INT_FM_TX,
587 .stream_name = "Internal FM Capture",
588 .cpu_dai_name = "msm-dai-q6.12293",
589 .platform_name = "msm-pcm-routing",
590 .codec_name = "msm-stub-codec.1",
591 .codec_dai_name = "msm-stub-tx",
592 .no_pcm = 1,
593 .be_id = MSM_BACKEND_DAI_INT_FM_TX,
594 .be_hw_params_fixup = msm8960_be_hw_params_fixup,
595 },
596 /* HDMI BACK END DAI Link */
597 {
598 .name = LPASS_BE_HDMI,
599 .stream_name = "HDMI Playback",
600 .cpu_dai_name = "msm-dai-q6.8",
601 .platform_name = "msm-pcm-routing",
602 .codec_name = "msm-stub-codec.1",
603 .codec_dai_name = "msm-stub-rx",
604 .no_pcm = 1,
605 .no_codec = 1,
606 .be_id = MSM_BACKEND_DAI_HDMI_RX,
607 .be_hw_params_fixup = msm8960_be_hw_params_fixup,
608 },
609};
610
611struct snd_soc_card snd_soc_card_msm8960 = {
612 .name = "msm8960-snd-card",
613 .dai_link = msm8960_dai,
614 .num_links = ARRAY_SIZE(msm8960_dai),
615};
616
617static struct platform_device *msm8960_snd_device;
618
619static int msm8960_configure_headset_mic_gpios(void)
620{
621 int ret;
622 struct pm_gpio param = {
623 .direction = PM_GPIO_DIR_OUT,
624 .output_buffer = PM_GPIO_OUT_BUF_CMOS,
625 .output_value = 1,
626 .pull = PM_GPIO_PULL_NO,
627 .vin_sel = PM_GPIO_VIN_S4,
628 .out_strength = PM_GPIO_STRENGTH_MED,
629 .function = PM_GPIO_FUNC_NORMAL,
630 };
631
632 ret = gpio_request(PM8921_GPIO_PM_TO_SYS(23), "AV_SWITCH");
633 if (ret) {
634 pr_err("%s: Failed to request gpio %d\n", __func__,
635 PM8921_GPIO_PM_TO_SYS(23));
636 return ret;
637 }
638
639 ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(23), &param);
640 if (ret)
641 pr_err("%s: Failed to configure gpio %d\n", __func__,
642 PM8921_GPIO_PM_TO_SYS(23));
643 else
644 gpio_direction_output(PM8921_GPIO_PM_TO_SYS(23), 0);
645
646 ret = gpio_request(PM8921_GPIO_PM_TO_SYS(35), "US_EURO_SWITCH");
647 if (ret) {
648 pr_err("%s: Failed to request gpio %d\n", __func__,
649 PM8921_GPIO_PM_TO_SYS(35));
650 gpio_free(PM8921_GPIO_PM_TO_SYS(23));
651 return ret;
652 }
653 ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(35), &param);
654 if (ret)
655 pr_err("%s: Failed to configure gpio %d\n", __func__,
656 PM8921_GPIO_PM_TO_SYS(35));
657 else
658 gpio_direction_output(PM8921_GPIO_PM_TO_SYS(35), 1);
659
660 return 0;
661}
662static void msm8960_free_headset_mic_gpios(void)
663{
664 if (msm8960_headset_gpios_configured) {
665 gpio_free(PM8921_GPIO_PM_TO_SYS(23));
666 gpio_free(PM8921_GPIO_PM_TO_SYS(35));
667 }
668}
669
670static int __init msm8960_audio_init(void)
671{
672 int ret;
673
674 msm8960_snd_device = platform_device_alloc("soc-audio", 0);
675 if (!msm8960_snd_device) {
676 pr_err("Platform device allocation failed\n");
677 return -ENOMEM;
678 }
679
680 platform_set_drvdata(msm8960_snd_device, &snd_soc_card_msm8960);
681 ret = platform_device_add(msm8960_snd_device);
682 if (ret) {
683 platform_device_put(msm8960_snd_device);
684 return ret;
685 }
686
687 if (msm8960_configure_headset_mic_gpios()) {
688 pr_err("%s Fail to configure headset mic gpios\n", __func__);
689 msm8960_headset_gpios_configured = 0;
690 } else
691 msm8960_headset_gpios_configured = 1;
692
693 return ret;
694
695}
696module_init(msm8960_audio_init);
697
698static void __exit msm8960_audio_exit(void)
699{
700 msm8960_free_headset_mic_gpios();
701 platform_device_unregister(msm8960_snd_device);
702}
703module_exit(msm8960_audio_exit);
704
705MODULE_DESCRIPTION("ALSA SoC MSM8960");
706MODULE_LICENSE("GPL v2");