blob: b3374fe6580f932fe505abe49ec0efc8db7d8e46 [file] [log] [blame]
Joonwoo Park0976d012011-12-22 11:48:18 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08002 *
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/delay.h>
15#include <linux/gpio.h>
16#include <linux/mfd/pm8xxx/pm8921.h>
17#include <linux/platform_device.h>
18#include <linux/gpio.h>
19#include <linux/mfd/pm8xxx/pm8921.h>
Joonwoo Park0976d012011-12-22 11:48:18 -080020#include <linux/slab.h>
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -080021#include <sound/core.h>
22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24#include <sound/soc-dsp.h>
25#include <sound/pcm.h>
26#include <sound/jack.h>
27#include <asm/mach-types.h>
28#include <mach/socinfo.h>
29#include "msm-pcm-routing.h"
30#include "../codecs/wcd9310.h"
31
32/* 8064 machine driver */
33
34#define PM8921_GPIO_BASE NR_GPIO_IRQS
35#define PM8921_GPIO_PM_TO_SYS(pm_gpio) (pm_gpio - 1 + PM8921_GPIO_BASE)
36
37#define MSM8064_SPK_ON 1
38#define MSM8064_SPK_OFF 0
39
40#define MSM_SLIM_0_RX_MAX_CHANNELS 2
41#define MSM_SLIM_0_TX_MAX_CHANNELS 4
42
43#define BTSCO_RATE_8KHZ 8000
44#define BTSCO_RATE_16KHZ 16000
45
46#define BOTTOM_SPK_AMP_POS 0x1
47#define BOTTOM_SPK_AMP_NEG 0x2
48#define TOP_SPK_AMP_POS 0x4
49#define TOP_SPK_AMP_NEG 0x8
50
51#define GPIO_AUX_PCM_DOUT 43
52#define GPIO_AUX_PCM_DIN 44
53#define GPIO_AUX_PCM_SYNC 45
54#define GPIO_AUX_PCM_CLK 46
55
Joonwoo Park0976d012011-12-22 11:48:18 -080056#define TABLA_EXT_CLK_RATE 12288000
57
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -080058#define TABLA_MBHC_DEF_BUTTONS 8
Joonwoo Park0976d012011-12-22 11:48:18 -080059#define TABLA_MBHC_DEF_RLOADS 5
60
Neema Shetty3c9d2862012-03-11 01:25:32 -080061/* Shared channel numbers for Slimbus ports that connect APQ to MDM. */
62enum {
63 SLIM_1_RX_1 = 145, /* BT-SCO and USB TX */
64 SLIM_1_TX_1 = 146, /* BT-SCO and USB RX */
65 SLIM_2_RX_1 = 147, /* HDMI RX */
Helen Zeng8f925502012-03-05 16:50:17 -080066 SLIM_4_TX_1 = 148, /* In-call recording RX */
67 SLIM_4_TX_2 = 149, /* In-call recording RX */
68 SLIM_4_RX_1 = 150, /* In-call music delivery TX */
69};
70
71enum {
72 INCALL_REC_MONO,
73 INCALL_REC_STEREO,
Neema Shetty3c9d2862012-03-11 01:25:32 -080074};
75
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -080076static u32 top_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(18);
77static u32 bottom_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(19);
78static int msm_spk_control;
79static int msm_ext_bottom_spk_pamp;
80static int msm_ext_top_spk_pamp;
81static int msm_slim_0_rx_ch = 1;
82static int msm_slim_0_tx_ch = 1;
83
84static int msm_btsco_rate = BTSCO_RATE_8KHZ;
85static int msm_btsco_ch = 1;
86
Helen Zeng8f925502012-03-05 16:50:17 -080087static int rec_mode = INCALL_REC_MONO;
88
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -080089static struct clk *codec_clk;
90static int clk_users;
91
92static int msm_headset_gpios_configured;
93
94static struct snd_soc_jack hs_jack;
95static struct snd_soc_jack button_jack;
96
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070097static int msm_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
98 bool dapm);
99
100static struct tabla_mbhc_config mbhc_cfg = {
101 .headset_jack = &hs_jack,
102 .button_jack = &button_jack,
103 .read_fw_bin = false,
104 .calibration = NULL,
105 .micbias = TABLA_MICBIAS2,
106 .mclk_cb_fn = msm_enable_codec_ext_clk,
107 .mclk_rate = TABLA_EXT_CLK_RATE,
108 .gpio = 0, /* MBHC GPIO is not configured */
109 .gpio_irq = 0,
110 .gpio_level_insert = 1,
111};
Joonwoo Park0976d012011-12-22 11:48:18 -0800112
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800113static void msm_enable_ext_spk_amp_gpio(u32 spk_amp_gpio)
114{
115 int ret = 0;
116
117 struct pm_gpio param = {
118 .direction = PM_GPIO_DIR_OUT,
119 .output_buffer = PM_GPIO_OUT_BUF_CMOS,
120 .output_value = 1,
121 .pull = PM_GPIO_PULL_NO,
122 .vin_sel = PM_GPIO_VIN_S4,
123 .out_strength = PM_GPIO_STRENGTH_MED,
124 .
125 function = PM_GPIO_FUNC_NORMAL,
126 };
127
128 if (spk_amp_gpio == bottom_spk_pamp_gpio) {
129
130 ret = gpio_request(bottom_spk_pamp_gpio, "BOTTOM_SPK_AMP");
131 if (ret) {
132 pr_err("%s: Error requesting BOTTOM SPK AMP GPIO %u\n",
133 __func__, bottom_spk_pamp_gpio);
134 return;
135 }
136 ret = pm8xxx_gpio_config(bottom_spk_pamp_gpio, &param);
137 if (ret)
138 pr_err("%s: Failed to configure Bottom Spk Ampl"
139 " gpio %u\n", __func__, bottom_spk_pamp_gpio);
140 else {
141 pr_debug("%s: enable Bottom spkr amp gpio\n", __func__);
142 gpio_direction_output(bottom_spk_pamp_gpio, 1);
143 }
144
145 } else if (spk_amp_gpio == top_spk_pamp_gpio) {
146
147 ret = gpio_request(top_spk_pamp_gpio, "TOP_SPK_AMP");
148 if (ret) {
149 pr_err("%s: Error requesting GPIO %d\n", __func__,
150 top_spk_pamp_gpio);
151 return;
152 }
153 ret = pm8xxx_gpio_config(top_spk_pamp_gpio, &param);
154 if (ret)
155 pr_err("%s: Failed to configure Top Spk Ampl"
156 " gpio %u\n", __func__, top_spk_pamp_gpio);
157 else {
158 pr_debug("%s: enable Top spkr amp gpio\n", __func__);
159 gpio_direction_output(top_spk_pamp_gpio, 1);
160 }
161 } else {
162 pr_err("%s: ERROR : Invalid External Speaker Ampl GPIO."
163 " gpio = %u\n", __func__, spk_amp_gpio);
164 return;
165 }
166}
167
168static void msm_ext_spk_power_amp_on(u32 spk)
169{
170 if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) {
171
172 if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) &&
173 (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) {
174
175 pr_debug("%s() External Bottom Speaker Ampl already "
176 "turned on. spk = 0x%08x\n", __func__, spk);
177 return;
178 }
179
180 msm_ext_bottom_spk_pamp |= spk;
181
182 if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) &&
183 (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) {
184
185 msm_enable_ext_spk_amp_gpio(bottom_spk_pamp_gpio);
186 pr_debug("%s: slepping 4 ms after turning on external "
187 " Bottom Speaker Ampl\n", __func__);
188 usleep_range(4000, 4000);
189 }
190
191 } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG)) {
192
193 if ((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) &&
194 (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) {
195
196 pr_debug("%s() External Top Speaker Ampl already"
197 "turned on. spk = 0x%08x\n", __func__, spk);
198 return;
199 }
200
201 msm_ext_top_spk_pamp |= spk;
202
203 if ((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) &&
204 (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) {
205
206 msm_enable_ext_spk_amp_gpio(top_spk_pamp_gpio);
207 pr_debug("%s: sleeping 4 ms after turning on "
208 " external Top Speaker Ampl\n", __func__);
209 usleep_range(4000, 4000);
210 }
211 } else {
212
213 pr_err("%s: ERROR : Invalid External Speaker Ampl. spk = 0x%08x\n",
214 __func__, spk);
215 return;
216 }
217}
218
219static void msm_ext_spk_power_amp_off(u32 spk)
220{
221 if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) {
222
223 if (!msm_ext_bottom_spk_pamp)
224 return;
225
226 gpio_direction_output(bottom_spk_pamp_gpio, 0);
227 gpio_free(bottom_spk_pamp_gpio);
228 msm_ext_bottom_spk_pamp = 0;
229
230 pr_debug("%s: sleeping 4 ms after turning off external Bottom"
231 " Speaker Ampl\n", __func__);
232
233 usleep_range(4000, 4000);
234
235 } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG)) {
236
237 if (!msm_ext_top_spk_pamp)
238 return;
239
240 gpio_direction_output(top_spk_pamp_gpio, 0);
241 gpio_free(top_spk_pamp_gpio);
242 msm_ext_top_spk_pamp = 0;
243
244 pr_debug("%s: sleeping 4 ms after turning off external Top"
245 " Spkaker Ampl\n", __func__);
246
247 usleep_range(4000, 4000);
248 } else {
249
250 pr_err("%s: ERROR : Invalid Ext Spk Ampl. spk = 0x%08x\n",
251 __func__, spk);
252 return;
253 }
254}
255
256static void msm_ext_control(struct snd_soc_codec *codec)
257{
258 struct snd_soc_dapm_context *dapm = &codec->dapm;
259
260 pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control);
261 if (msm_spk_control == MSM8064_SPK_ON) {
262 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos");
263 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg");
264 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos");
265 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg");
266 } else {
267 snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Pos");
268 snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Neg");
269 snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Pos");
270 snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Neg");
271 }
272
273 snd_soc_dapm_sync(dapm);
274}
275
276static int msm_get_spk(struct snd_kcontrol *kcontrol,
277 struct snd_ctl_elem_value *ucontrol)
278{
279 pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control);
280 ucontrol->value.integer.value[0] = msm_spk_control;
281 return 0;
282}
283static int msm_set_spk(struct snd_kcontrol *kcontrol,
284 struct snd_ctl_elem_value *ucontrol)
285{
286 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
287
288 pr_debug("%s()\n", __func__);
289 if (msm_spk_control == ucontrol->value.integer.value[0])
290 return 0;
291
292 msm_spk_control = ucontrol->value.integer.value[0];
293 msm_ext_control(codec);
294 return 1;
295}
296static int msm_spkramp_event(struct snd_soc_dapm_widget *w,
297 struct snd_kcontrol *k, int event)
298{
299 pr_debug("%s() %x\n", __func__, SND_SOC_DAPM_EVENT_ON(event));
300
301 if (SND_SOC_DAPM_EVENT_ON(event)) {
302 if (!strncmp(w->name, "Ext Spk Bottom Pos", 18))
303 msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_POS);
304 else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18))
305 msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_NEG);
306 else if (!strncmp(w->name, "Ext Spk Top Pos", 15))
307 msm_ext_spk_power_amp_on(TOP_SPK_AMP_POS);
308 else if (!strncmp(w->name, "Ext Spk Top Neg", 15))
309 msm_ext_spk_power_amp_on(TOP_SPK_AMP_NEG);
310 else {
311 pr_err("%s() Invalid Speaker Widget = %s\n",
312 __func__, w->name);
313 return -EINVAL;
314 }
315
316 } else {
317 if (!strncmp(w->name, "Ext Spk Bottom Pos", 18))
318 msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_POS);
319 else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18))
320 msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_NEG);
321 else if (!strncmp(w->name, "Ext Spk Top Pos", 15))
322 msm_ext_spk_power_amp_off(TOP_SPK_AMP_POS);
323 else if (!strncmp(w->name, "Ext Spk Top Neg", 15))
324 msm_ext_spk_power_amp_off(TOP_SPK_AMP_NEG);
325 else {
326 pr_err("%s() Invalid Speaker Widget = %s\n",
327 __func__, w->name);
328 return -EINVAL;
329 }
330 }
331 return 0;
332}
333
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700334static int msm_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
335 bool dapm)
Joonwoo Park0976d012011-12-22 11:48:18 -0800336{
337 pr_debug("%s: enable = %d\n", __func__, enable);
338 if (enable) {
339 clk_users++;
340 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
341 if (clk_users != 1)
342 return 0;
343
Joonwoo Park0976d012011-12-22 11:48:18 -0800344 if (codec_clk) {
345 clk_set_rate(codec_clk, TABLA_EXT_CLK_RATE);
Asish Bhattacharya4776d962012-04-25 12:08:09 +0530346 clk_prepare_enable(codec_clk);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700347 tabla_mclk_enable(codec, 1, dapm);
Joonwoo Park0976d012011-12-22 11:48:18 -0800348 } else {
349 pr_err("%s: Error setting Tabla MCLK\n", __func__);
350 clk_users--;
351 return -EINVAL;
352 }
353 } else {
354 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
355 if (clk_users == 0)
356 return 0;
357 clk_users--;
358 if (!clk_users) {
359 pr_debug("%s: disabling MCLK. clk_users = %d\n",
360 __func__, clk_users);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700361 tabla_mclk_enable(codec, 0, dapm);
Asish Bhattacharya4776d962012-04-25 12:08:09 +0530362 clk_disable_unprepare(codec_clk);
Joonwoo Park0976d012011-12-22 11:48:18 -0800363 }
364 }
365 return 0;
366}
367
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800368static int msm_mclk_event(struct snd_soc_dapm_widget *w,
369 struct snd_kcontrol *kcontrol, int event)
370{
371 pr_debug("%s: event = %d\n", __func__, event);
372
373 switch (event) {
374 case SND_SOC_DAPM_PRE_PMU:
375
376 clk_users++;
377 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
378
379 if (clk_users != 1)
380 return 0;
381
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800382 if (codec_clk) {
383 clk_set_rate(codec_clk, 12288000);
Asish Bhattacharya4776d962012-04-25 12:08:09 +0530384 clk_prepare_enable(codec_clk);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700385 tabla_mclk_enable(w->codec, 1, true);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800386
387 } else {
388 pr_err("%s: Error setting Tabla MCLK\n", __func__);
389 clk_users--;
390 return -EINVAL;
391 }
392 break;
393 case SND_SOC_DAPM_POST_PMD:
394
395 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
396
397 if (clk_users == 0)
398 return 0;
399
400 clk_users--;
401
402 if (!clk_users) {
403 pr_debug("%s: disabling MCLK. clk_users = %d\n",
404 __func__, clk_users);
405
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700406 tabla_mclk_enable(w->codec, 0, true);
Asish Bhattacharya4776d962012-04-25 12:08:09 +0530407 clk_disable_unprepare(codec_clk);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800408 }
409 break;
410 }
411 return 0;
412}
413
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700414static const struct snd_soc_dapm_widget apq8064_dapm_widgets[] = {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800415
416 SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0,
417 msm_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
418
419 SND_SOC_DAPM_SPK("Ext Spk Bottom Pos", msm_spkramp_event),
420 SND_SOC_DAPM_SPK("Ext Spk Bottom Neg", msm_spkramp_event),
421
422 SND_SOC_DAPM_SPK("Ext Spk Top Pos", msm_spkramp_event),
423 SND_SOC_DAPM_SPK("Ext Spk Top Neg", msm_spkramp_event),
424
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700425 /************ Analog MICs ************/
426 /**
427 * Analog mic7 (Front Top) on Liquid.
428 * Used as Handset mic on CDP.
429 */
430 SND_SOC_DAPM_MIC("Analog mic7", NULL),
431
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800432 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800433 SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
434 SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
435
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700436 /*********** Digital Mics ***************/
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800437 SND_SOC_DAPM_MIC("Digital Mic1", NULL),
438 SND_SOC_DAPM_MIC("Digital Mic2", NULL),
439 SND_SOC_DAPM_MIC("Digital Mic3", NULL),
440 SND_SOC_DAPM_MIC("Digital Mic4", NULL),
441 SND_SOC_DAPM_MIC("Digital Mic5", NULL),
442 SND_SOC_DAPM_MIC("Digital Mic6", NULL),
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800443};
444
Kiran Kandi323d7102012-04-18 19:56:14 -0700445static const struct snd_soc_dapm_route apq8064_common_audio_map[] = {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800446
447 {"RX_BIAS", NULL, "MCLK"},
448 {"LDO_H", NULL, "MCLK"},
449
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700450 {"HEADPHONE", NULL, "LDO_H"},
451
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800452 /* Speaker path */
453 {"Ext Spk Bottom Pos", NULL, "LINEOUT1"},
454 {"Ext Spk Bottom Neg", NULL, "LINEOUT3"},
455
456 {"Ext Spk Top Pos", NULL, "LINEOUT2"},
457 {"Ext Spk Top Neg", NULL, "LINEOUT4"},
458
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700459 /************ Analog MIC Paths ************/
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800460
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700461 /* Headset Mic */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800462 {"AMIC2", NULL, "MIC BIAS2 External"},
463 {"MIC BIAS2 External", NULL, "Headset Mic"},
464
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700465 /* Headset ANC microphones */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800466 {"AMIC3", NULL, "MIC BIAS3 Internal1"},
467 {"MIC BIAS3 Internal1", NULL, "ANCRight Headset Mic"},
468
469 {"AMIC4", NULL, "MIC BIAS1 Internal2"},
470 {"MIC BIAS1 Internal2", NULL, "ANCLeft Headset Mic"},
Kiran Kandi323d7102012-04-18 19:56:14 -0700471};
472
473static const struct snd_soc_dapm_route apq8064_mtp_audio_map[] = {
474
475 /************ Digital MIC Paths ************/
476
477 /*
478 * Digital Mic1 (Front bottom Left) on MTP.
479 * Conncted to DMIC1 Input on Tabla codec.
480 */
481 {"DMIC1", NULL, "MIC BIAS1 External"},
482 {"MIC BIAS1 External", NULL, "Digital Mic1"},
483
484 /**
485 * Digital Mic2 (Front bottom right) on MTP.
486 * Conncted to DMIC2 Input on Tabla codec.
487 */
488 {"DMIC2", NULL, "MIC BIAS1 External"},
489 {"MIC BIAS1 External", NULL, "Digital Mic2"},
490
491 /**
492 * Digital Mic3 (Back bottom) on MTP.
493 * Conncted to DMIC3 Input on Tabla codec.
494 */
495 {"DMIC3", NULL, "MIC BIAS3 External"},
496 {"MIC BIAS3 External", NULL, "Digital Mic3"},
497
498 /**
499 * Digital Mic4 (Back top) on MTP.
500 * Conncted to DMIC4 Input on Tabla codec.
501 */
502 {"DMIC4", NULL, "MIC BIAS3 External"},
503 {"MIC BIAS3 External", NULL, "Digital Mic4"},
504
505 /**
506 * Digital Mic5 (Top front Mic) on MTP.
507 * Conncted to DMIC6 Input on Tabla codec.
508 */
509 {"DMIC6", NULL, "MIC BIAS4 External"},
510 {"MIC BIAS4 External", NULL, "Digital Mic5"},
511
512};
513
514static const struct snd_soc_dapm_route apq8064_liquid_cdp_audio_map[] = {
515
516 /************ Analog MIC Paths ************/
517 /**
518 * Analog mic7 (Front Top Mic) on Liquid.
519 * Used as Handset mic on CDP.
520 * Not there on MTP.
521 */
522 {"AMIC1", NULL, "MIC BIAS1 External"},
523 {"MIC BIAS1 External", NULL, "Analog mic7"},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800524
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800525
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700526 /************ Digital MIC Paths ************/
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800527 /**
528 * The digital Mic routes are setup considering
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700529 * Liquid as default device.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800530 */
531
532 /**
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700533 * Digital Mic1 (Front bottom left corner) on Liquid.
534 * Digital Mic2 (Front bottom right) on MTP.
535 * Digital Mic GM1 on CDP mainboard.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800536 * Conncted to DMIC2 Input on Tabla codec.
537 */
538 {"DMIC2", NULL, "MIC BIAS1 External"},
539 {"MIC BIAS1 External", NULL, "Digital Mic1"},
540
541 /**
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700542 * Digital Mic2 (Front left side) on Liquid.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800543 * Digital Mic GM2 on CDP mainboard.
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700544 * Not there on MTP.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800545 * Conncted to DMIC3 Input on Tabla codec.
546 */
547 {"DMIC3", NULL, "MIC BIAS3 External"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700548 {"MIC BIAS3 External", NULL, "Digital Mic2"},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800549
550 /**
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700551 * Digital Mic3. Front bottom left of middle on Liquid.
552 * Digital Mic5 (Top front Mic) on MTP.
553 * Digital Mic GM5 on CDP mainboard.
554 * Conncted to DMIC6 Input on Tabla codec.
555 */
556 {"DMIC6", NULL, "MIC BIAS4 External"},
557 {"MIC BIAS4 External", NULL, "Digital Mic3"},
558
559 /**
560 * Digital Mic4. Back bottom on Liquid.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800561 * Digital Mic GM3 on CDP mainboard.
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700562 * Top Front Mic on MTP.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800563 * Conncted to DMIC5 Input on Tabla codec.
564 */
565 {"DMIC5", NULL, "MIC BIAS4 External"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700566 {"MIC BIAS4 External", NULL, "Digital Mic4"},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800567
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700568 /**
569 * Digital Mic5. Front bottom right of middle on Liquid.
570 * Digital Mic GM6 on CDP mainboard.
571 * Not there on MTP.
572 * Conncted to DMIC4 Input on Tabla codec.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800573 */
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700574 {"DMIC4", NULL, "MIC BIAS3 External"},
575 {"MIC BIAS3 External", NULL, "Digital Mic5"},
576
577 /* Digital Mic6 (Front bottom right corner) on Liquid.
578 * Digital Mic1 (Front bottom Left) on MTP.
579 * Digital Mic GM4 on CDP.
580 * Conncted to DMIC1 Input on Tabla codec.
581 */
582 {"DMIC1", NULL, "MIC BIAS1 External"},
583 {"MIC BIAS1 External", NULL, "Digital Mic6"},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800584};
585
586static const char *spk_function[] = {"Off", "On"};
587static const char *slim0_rx_ch_text[] = {"One", "Two"};
588static const char *slim0_tx_ch_text[] = {"One", "Two", "Three", "Four"};
589
590static const struct soc_enum msm_enum[] = {
591 SOC_ENUM_SINGLE_EXT(2, spk_function),
592 SOC_ENUM_SINGLE_EXT(2, slim0_rx_ch_text),
593 SOC_ENUM_SINGLE_EXT(4, slim0_tx_ch_text),
594};
595
596static const char *btsco_rate_text[] = {"8000", "16000"};
597static const struct soc_enum msm_btsco_enum[] = {
598 SOC_ENUM_SINGLE_EXT(2, btsco_rate_text),
599};
600
601static int msm_slim_0_rx_ch_get(struct snd_kcontrol *kcontrol,
602 struct snd_ctl_elem_value *ucontrol)
603{
604 pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__,
605 msm_slim_0_rx_ch);
606 ucontrol->value.integer.value[0] = msm_slim_0_rx_ch - 1;
607 return 0;
608}
609
610static int msm_slim_0_rx_ch_put(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_value *ucontrol)
612{
613 msm_slim_0_rx_ch = ucontrol->value.integer.value[0] + 1;
614
615 pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__,
616 msm_slim_0_rx_ch);
617 return 1;
618}
619
620static int msm_slim_0_tx_ch_get(struct snd_kcontrol *kcontrol,
621 struct snd_ctl_elem_value *ucontrol)
622{
623 pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__,
624 msm_slim_0_tx_ch);
625 ucontrol->value.integer.value[0] = msm_slim_0_tx_ch - 1;
626 return 0;
627}
628
629static int msm_slim_0_tx_ch_put(struct snd_kcontrol *kcontrol,
630 struct snd_ctl_elem_value *ucontrol)
631{
632 msm_slim_0_tx_ch = ucontrol->value.integer.value[0] + 1;
633
634 pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__,
635 msm_slim_0_tx_ch);
636 return 1;
637}
638
639static int msm_btsco_rate_get(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_value *ucontrol)
641{
642 pr_debug("%s: msm_btsco_rate = %d", __func__,
643 msm_btsco_rate);
644 ucontrol->value.integer.value[0] = msm_btsco_rate;
645 return 0;
646}
647
648static int msm_btsco_rate_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 switch (ucontrol->value.integer.value[0]) {
652 case 0:
653 msm_btsco_rate = BTSCO_RATE_8KHZ;
654 break;
655 case 1:
656 msm_btsco_rate = BTSCO_RATE_16KHZ;
657 break;
658 default:
659 msm_btsco_rate = BTSCO_RATE_8KHZ;
660 break;
661 }
662 pr_debug("%s: msm_btsco_rate = %d\n", __func__,
663 msm_btsco_rate);
664 return 0;
665}
666
Helen Zeng8f925502012-03-05 16:50:17 -0800667static int msm_incall_rec_mode_get(struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
669{
670 ucontrol->value.integer.value[0] = rec_mode;
671 return 0;
672}
673
674static int msm_incall_rec_mode_put(struct snd_kcontrol *kcontrol,
675 struct snd_ctl_elem_value *ucontrol)
676{
677
678 rec_mode = ucontrol->value.integer.value[0];
679 pr_debug("%s: rec_mode:%d\n", __func__, rec_mode);
680
681 return 0;
682}
683
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800684static const struct snd_kcontrol_new tabla_msm_controls[] = {
685 SOC_ENUM_EXT("Speaker Function", msm_enum[0], msm_get_spk,
686 msm_set_spk),
687 SOC_ENUM_EXT("SLIM_0_RX Channels", msm_enum[1],
688 msm_slim_0_rx_ch_get, msm_slim_0_rx_ch_put),
689 SOC_ENUM_EXT("SLIM_0_TX Channels", msm_enum[2],
690 msm_slim_0_tx_ch_get, msm_slim_0_tx_ch_put),
691};
692
693static const struct snd_kcontrol_new int_btsco_rate_mixer_controls[] = {
694 SOC_ENUM_EXT("Internal BTSCO SampleRate", msm_btsco_enum[0],
695 msm_btsco_rate_get, msm_btsco_rate_put),
696};
697
Helen Zeng8f925502012-03-05 16:50:17 -0800698static const struct snd_kcontrol_new incall_rec_mode_mixer_controls[] = {
699 SOC_SINGLE_EXT("Incall Rec Mode", SND_SOC_NOPM, 0, 1, 0,
700 msm_incall_rec_mode_get, msm_incall_rec_mode_put),
701};
702
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800703static int msm_btsco_init(struct snd_soc_pcm_runtime *rtd)
704{
705 int err = 0;
706 struct snd_soc_platform *platform = rtd->platform;
707
708 err = snd_soc_add_platform_controls(platform,
709 int_btsco_rate_mixer_controls,
710 ARRAY_SIZE(int_btsco_rate_mixer_controls));
711 if (err < 0)
712 return err;
713 return 0;
714}
715
Helen Zeng8f925502012-03-05 16:50:17 -0800716static int msm_incall_rec_init(struct snd_soc_pcm_runtime *rtd)
717{
718 int err = 0;
719 struct snd_soc_platform *platform = rtd->platform;
720
721 err = snd_soc_add_platform_controls(platform,
722 incall_rec_mode_mixer_controls,
723 ARRAY_SIZE(incall_rec_mode_mixer_controls));
724 if (err < 0)
725 return err;
726 return 0;
727}
728
Joonwoo Park0976d012011-12-22 11:48:18 -0800729static void *def_tabla_mbhc_cal(void)
730{
731 void *tabla_cal;
732 struct tabla_mbhc_btn_detect_cfg *btn_cfg;
733 u16 *btn_low, *btn_high;
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800734 u8 *n_ready, *n_cic, *gain;
Joonwoo Park0976d012011-12-22 11:48:18 -0800735
736 tabla_cal = kzalloc(TABLA_MBHC_CAL_SIZE(TABLA_MBHC_DEF_BUTTONS,
737 TABLA_MBHC_DEF_RLOADS),
738 GFP_KERNEL);
739 if (!tabla_cal) {
740 pr_err("%s: out of memory\n", __func__);
741 return NULL;
742 }
743
744#define S(X, Y) ((TABLA_MBHC_CAL_GENERAL_PTR(tabla_cal)->X) = (Y))
745 S(t_ldoh, 100);
746 S(t_bg_fast_settle, 100);
747 S(t_shutdown_plug_rem, 255);
748 S(mbhc_nsa, 4);
749 S(mbhc_navg, 4);
750#undef S
751#define S(X, Y) ((TABLA_MBHC_CAL_PLUG_DET_PTR(tabla_cal)->X) = (Y))
752 S(mic_current, TABLA_PID_MIC_5_UA);
753 S(hph_current, TABLA_PID_MIC_5_UA);
754 S(t_mic_pid, 100);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800755 S(t_ins_complete, 250);
Joonwoo Park0976d012011-12-22 11:48:18 -0800756 S(t_ins_retry, 200);
757#undef S
758#define S(X, Y) ((TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla_cal)->X) = (Y))
759 S(v_no_mic, 30);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800760 S(v_hs_max, 1550);
Joonwoo Park0976d012011-12-22 11:48:18 -0800761#undef S
762#define S(X, Y) ((TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal)->X) = (Y))
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800763 S(c[0], 62);
764 S(c[1], 124);
765 S(nc, 1);
766 S(n_meas, 3);
Joonwoo Park0976d012011-12-22 11:48:18 -0800767 S(mbhc_nsc, 11);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800768 S(n_btn_meas, 1);
769 S(n_btn_con, 2);
Joonwoo Park0976d012011-12-22 11:48:18 -0800770 S(num_btn, TABLA_MBHC_DEF_BUTTONS);
771 S(v_btn_press_delta_sta, 100);
772 S(v_btn_press_delta_cic, 50);
773#undef S
774 btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal);
775 btn_low = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_LOW);
776 btn_high = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_HIGH);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800777 btn_low[0] = -50;
778 btn_high[0] = 10;
779 btn_low[1] = 11;
780 btn_high[1] = 38;
781 btn_low[2] = 39;
782 btn_high[2] = 64;
783 btn_low[3] = 65;
784 btn_high[3] = 91;
785 btn_low[4] = 92;
786 btn_high[4] = 115;
787 btn_low[5] = 116;
788 btn_high[5] = 141;
789 btn_low[6] = 142;
790 btn_high[6] = 163;
791 btn_low[7] = 164;
792 btn_high[7] = 250;
793 n_ready = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_READY);
794 n_ready[0] = 48;
795 n_ready[1] = 38;
Joonwoo Park0976d012011-12-22 11:48:18 -0800796 n_cic = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_CIC);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800797 n_cic[0] = 60;
798 n_cic[1] = 47;
Joonwoo Park0976d012011-12-22 11:48:18 -0800799 gain = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_GAIN);
800 gain[0] = 11;
801 gain[1] = 9;
802
803 return tabla_cal;
804}
805
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800806static int msm_hw_params(struct snd_pcm_substream *substream,
807 struct snd_pcm_hw_params *params)
808{
809 struct snd_soc_pcm_runtime *rtd = substream->private_data;
810 struct snd_soc_dai *codec_dai = rtd->codec_dai;
811 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
812 int ret = 0;
813 unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
814 unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700815 unsigned int user_set_tx_ch = 0;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800816
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700817
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800818 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700819
820 pr_debug("%s: rx_0_ch=%d\n", __func__, msm_slim_0_rx_ch);
821
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800822 ret = snd_soc_dai_get_channel_map(codec_dai,
823 &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
824 if (ret < 0) {
825 pr_err("%s: failed to get codec chan map\n", __func__);
826 goto end;
827 }
828
829 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
830 msm_slim_0_rx_ch, rx_ch);
831 if (ret < 0) {
832 pr_err("%s: failed to set cpu chan map\n", __func__);
833 goto end;
834 }
835 ret = snd_soc_dai_set_channel_map(codec_dai, 0, 0,
836 msm_slim_0_rx_ch, rx_ch);
837 if (ret < 0) {
838 pr_err("%s: failed to set codec channel map\n",
839 __func__);
840 goto end;
841 }
842 } else {
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700843
844 if (codec_dai->id == 2)
845 user_set_tx_ch = msm_slim_0_tx_ch;
846 else if (codec_dai->id == 4)
847 user_set_tx_ch = params_channels(params);
848
849 pr_debug("%s: %s_tx_dai_id_%d_ch=%d\n", __func__,
850 codec_dai->name, codec_dai->id, user_set_tx_ch);
851
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800852 ret = snd_soc_dai_get_channel_map(codec_dai,
853 &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
854 if (ret < 0) {
855 pr_err("%s: failed to get codec chan map\n", __func__);
856 goto end;
857 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700858
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800859 ret = snd_soc_dai_set_channel_map(cpu_dai,
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700860 user_set_tx_ch, tx_ch, 0 , 0);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800861 if (ret < 0) {
862 pr_err("%s: failed to set cpu chan map\n", __func__);
863 goto end;
864 }
865 ret = snd_soc_dai_set_channel_map(codec_dai,
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700866 user_set_tx_ch, tx_ch, 0, 0);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800867 if (ret < 0) {
868 pr_err("%s: failed to set codec channel map\n",
869 __func__);
870 goto end;
871 }
872
873
874 }
875end:
876 return ret;
877}
878
Helen Zengf3b17fb2012-02-28 15:07:38 -0800879static int msm_stubrx_init(struct snd_soc_pcm_runtime *rtd)
880{
881 rtd->pmdown_time = 0;
882
883 return 0;
884}
885
Neema Shetty3c9d2862012-03-11 01:25:32 -0800886static int msm_slimbus_1_hw_params(struct snd_pcm_substream *substream,
887 struct snd_pcm_hw_params *params)
888{
889 struct snd_soc_pcm_runtime *rtd = substream->private_data;
890 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
891 int ret = 0;
892 unsigned int rx_ch = SLIM_1_RX_1, tx_ch = SLIM_1_TX_1;
893
894 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
895 pr_debug("%s: APQ BT/USB TX -> SLIMBUS_1_RX -> MDM TX shared ch %d\n",
896 __func__, rx_ch);
897
898 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0, 1, &rx_ch);
899 if (ret < 0) {
900 pr_err("%s: Erorr %d setting SLIM_1 RX channel map\n",
901 __func__, ret);
902
903 goto end;
904 }
905 } else {
906 pr_debug("%s: MDM RX -> SLIMBUS_1_TX -> APQ BT/USB Rx shared ch %d\n",
907 __func__, tx_ch);
908
909 ret = snd_soc_dai_set_channel_map(cpu_dai, 1, &tx_ch, 0, 0);
910 if (ret < 0) {
911 pr_err("%s: Erorr %d setting SLIM_1 TX channel map\n",
912 __func__, ret);
913
914 goto end;
915 }
916 }
917
918end:
919 return ret;
920}
921
Helen Zeng8f925502012-03-05 16:50:17 -0800922static int msm_slimbus_4_hw_params(struct snd_pcm_substream *substream,
923 struct snd_pcm_hw_params *params)
924{
925 struct snd_soc_pcm_runtime *rtd = substream->private_data;
926 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
927 int ret = 0;
928 unsigned int rx_ch = SLIM_4_RX_1, tx_ch[2];
929
930 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
931 pr_debug("%s: APQ Incall Playback SLIMBUS_4_RX -> MDM TX shared ch %d\n",
932 __func__, rx_ch);
933
934 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0, 1, &rx_ch);
935 if (ret < 0) {
936 pr_err("%s: Erorr %d setting SLIM_4 RX channel map\n",
937 __func__, ret);
938
939 }
940 } else {
941 if (rec_mode == INCALL_REC_STEREO) {
942 tx_ch[0] = SLIM_4_TX_1;
943 tx_ch[1] = SLIM_4_TX_2;
944 ret = snd_soc_dai_set_channel_map(cpu_dai, 2,
945 tx_ch, 0, 0);
946 } else {
947 tx_ch[0] = SLIM_4_TX_1;
948 ret = snd_soc_dai_set_channel_map(cpu_dai, 1,
949 tx_ch, 0, 0);
950 }
951 pr_debug("%s: Incall Record shared tx_ch[0]:%d, tx_ch[1]:%d\n",
952 __func__, tx_ch[0], tx_ch[1]);
953
954 if (ret < 0) {
955 pr_err("%s: Erorr %d setting SLIM_4 TX channel map\n",
956 __func__, ret);
957
958 }
959 }
960
961 return ret;
962}
963
964
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800965static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
966{
967 int err;
968 struct snd_soc_codec *codec = rtd->codec;
969 struct snd_soc_dapm_context *dapm = &codec->dapm;
Kuirong Wanga9c3acc2012-02-09 17:00:45 -0800970 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800971
Kuirong Wanga9c3acc2012-02-09 17:00:45 -0800972 pr_debug("%s(), dev_name%s\n", __func__, dev_name(cpu_dai->dev));
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800973
974 /*if (machine_is_msm_liquid()) {
975 top_spk_pamp_gpio = (PM8921_GPIO_PM_TO_SYS(19));
976 bottom_spk_pamp_gpio = (PM8921_GPIO_PM_TO_SYS(18));
977 }*/
978
979 rtd->pmdown_time = 0;
980
981 err = snd_soc_add_controls(codec, tabla_msm_controls,
982 ARRAY_SIZE(tabla_msm_controls));
983 if (err < 0)
984 return err;
985
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700986 snd_soc_dapm_new_controls(dapm, apq8064_dapm_widgets,
987 ARRAY_SIZE(apq8064_dapm_widgets));
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800988
Kiran Kandi323d7102012-04-18 19:56:14 -0700989 snd_soc_dapm_add_routes(dapm, apq8064_common_audio_map,
990 ARRAY_SIZE(apq8064_common_audio_map));
991
992 if (machine_is_apq8064_mtp()) {
993 snd_soc_dapm_add_routes(dapm, apq8064_mtp_audio_map,
994 ARRAY_SIZE(apq8064_mtp_audio_map));
995 } else {
996 snd_soc_dapm_add_routes(dapm, apq8064_liquid_cdp_audio_map,
997 ARRAY_SIZE(apq8064_liquid_cdp_audio_map));
998 }
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800999
1000 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos");
1001 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg");
1002 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos");
1003 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg");
1004
1005 snd_soc_dapm_sync(dapm);
1006
1007 err = snd_soc_jack_new(codec, "Headset Jack",
1008 (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR),
1009 &hs_jack);
1010 if (err) {
1011 pr_err("failed to create new jack\n");
1012 return err;
1013 }
1014
1015 err = snd_soc_jack_new(codec, "Button Jack",
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -08001016 TABLA_JACK_BUTTON_MASK, &button_jack);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001017 if (err) {
1018 pr_err("failed to create new jack\n");
1019 return err;
1020 }
1021
Kuirong Wanga9c3acc2012-02-09 17:00:45 -08001022 codec_clk = clk_get(cpu_dai->dev, "osr_clk");
1023
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001024 err = tabla_hs_detect(codec, &mbhc_cfg);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001025
Joonwoo Park03324832012-03-19 19:36:16 -07001026 return err;
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001027}
1028
1029static struct snd_soc_dsp_link lpa_fe_media = {
1030 .playback = true,
1031 .trigger = {
1032 SND_SOC_DSP_TRIGGER_POST,
1033 SND_SOC_DSP_TRIGGER_POST
1034 },
1035};
1036
1037static struct snd_soc_dsp_link fe_media = {
1038 .playback = true,
1039 .capture = true,
1040 .trigger = {
1041 SND_SOC_DSP_TRIGGER_POST,
1042 SND_SOC_DSP_TRIGGER_POST
1043 },
1044};
1045
1046static struct snd_soc_dsp_link slimbus0_hl_media = {
1047 .playback = true,
1048 .capture = true,
1049 .trigger = {
1050 SND_SOC_DSP_TRIGGER_POST,
1051 SND_SOC_DSP_TRIGGER_POST
1052 },
1053};
1054
1055static struct snd_soc_dsp_link int_fm_hl_media = {
1056 .playback = true,
1057 .capture = true,
1058 .trigger = {
1059 SND_SOC_DSP_TRIGGER_POST,
1060 SND_SOC_DSP_TRIGGER_POST
1061 },
1062};
1063
1064static int msm_slim_0_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1065 struct snd_pcm_hw_params *params)
1066{
1067 struct snd_interval *rate = hw_param_interval(params,
1068 SNDRV_PCM_HW_PARAM_RATE);
1069
1070 struct snd_interval *channels = hw_param_interval(params,
1071 SNDRV_PCM_HW_PARAM_CHANNELS);
1072
1073 pr_debug("%s()\n", __func__);
1074 rate->min = rate->max = 48000;
1075 channels->min = channels->max = msm_slim_0_rx_ch;
1076
1077 return 0;
1078}
1079
1080static int msm_slim_0_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1081 struct snd_pcm_hw_params *params)
1082{
1083 struct snd_interval *rate = hw_param_interval(params,
1084 SNDRV_PCM_HW_PARAM_RATE);
1085
1086 struct snd_interval *channels = hw_param_interval(params,
1087 SNDRV_PCM_HW_PARAM_CHANNELS);
1088
1089 pr_debug("%s()\n", __func__);
1090 rate->min = rate->max = 48000;
1091 channels->min = channels->max = msm_slim_0_tx_ch;
1092
1093 return 0;
1094}
1095
1096static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1097 struct snd_pcm_hw_params *params)
1098{
1099 struct snd_interval *rate = hw_param_interval(params,
1100 SNDRV_PCM_HW_PARAM_RATE);
1101
1102 pr_debug("%s()\n", __func__);
1103 rate->min = rate->max = 48000;
1104
1105 return 0;
1106}
1107
Swaminathan Sathappanfd9dbad2012-02-15 16:56:44 -08001108static int msm_hdmi_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1109 struct snd_pcm_hw_params *params)
1110{
1111 struct snd_interval *rate = hw_param_interval(params,
1112 SNDRV_PCM_HW_PARAM_RATE);
1113
1114 struct snd_interval *channels = hw_param_interval(params,
1115 SNDRV_PCM_HW_PARAM_CHANNELS);
1116
1117 pr_debug("%s channels->min %u channels->max %u ()\n", __func__,
1118 channels->min, channels->max);
1119
1120 rate->min = rate->max = 48000;
1121
1122 return 0;
1123}
1124
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001125static int msm_btsco_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1126 struct snd_pcm_hw_params *params)
1127{
1128 struct snd_interval *rate = hw_param_interval(params,
1129 SNDRV_PCM_HW_PARAM_RATE);
1130
1131 struct snd_interval *channels = hw_param_interval(params,
1132 SNDRV_PCM_HW_PARAM_CHANNELS);
1133
1134 rate->min = rate->max = msm_btsco_rate;
1135 channels->min = channels->max = msm_btsco_ch;
1136
1137 return 0;
1138}
1139static int msm_auxpcm_be_params_fixup(struct snd_soc_pcm_runtime *rtd,
1140 struct snd_pcm_hw_params *params)
1141{
1142 struct snd_interval *rate = hw_param_interval(params,
1143 SNDRV_PCM_HW_PARAM_RATE);
1144
1145 struct snd_interval *channels = hw_param_interval(params,
1146 SNDRV_PCM_HW_PARAM_CHANNELS);
1147
1148 /* PCM only supports mono output with 8khz sample rate */
1149 rate->min = rate->max = 8000;
1150 channels->min = channels->max = 1;
1151
1152 return 0;
1153}
Neema Shetty3c9d2862012-03-11 01:25:32 -08001154
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001155static int msm_aux_pcm_get_gpios(void)
1156{
1157 int ret = 0;
1158
1159 pr_debug("%s\n", __func__);
1160
1161 ret = gpio_request(GPIO_AUX_PCM_DOUT, "AUX PCM DOUT");
1162 if (ret < 0) {
1163 pr_err("%s: Failed to request gpio(%d): AUX PCM DOUT",
1164 __func__, GPIO_AUX_PCM_DOUT);
1165 goto fail_dout;
1166 }
1167
1168 ret = gpio_request(GPIO_AUX_PCM_DIN, "AUX PCM DIN");
1169 if (ret < 0) {
1170 pr_err("%s: Failed to request gpio(%d): AUX PCM DIN",
1171 __func__, GPIO_AUX_PCM_DIN);
1172 goto fail_din;
1173 }
1174
1175 ret = gpio_request(GPIO_AUX_PCM_SYNC, "AUX PCM SYNC");
1176 if (ret < 0) {
1177 pr_err("%s: Failed to request gpio(%d): AUX PCM SYNC",
1178 __func__, GPIO_AUX_PCM_SYNC);
1179 goto fail_sync;
1180 }
1181 ret = gpio_request(GPIO_AUX_PCM_CLK, "AUX PCM CLK");
1182 if (ret < 0) {
1183 pr_err("%s: Failed to request gpio(%d): AUX PCM CLK",
1184 __func__, GPIO_AUX_PCM_CLK);
1185 goto fail_clk;
1186 }
1187
1188 return 0;
1189
1190fail_clk:
1191 gpio_free(GPIO_AUX_PCM_SYNC);
1192fail_sync:
1193 gpio_free(GPIO_AUX_PCM_DIN);
1194fail_din:
1195 gpio_free(GPIO_AUX_PCM_DOUT);
1196fail_dout:
1197
1198 return ret;
1199}
1200
1201static int msm_aux_pcm_free_gpios(void)
1202{
1203 gpio_free(GPIO_AUX_PCM_DIN);
1204 gpio_free(GPIO_AUX_PCM_DOUT);
1205 gpio_free(GPIO_AUX_PCM_SYNC);
1206 gpio_free(GPIO_AUX_PCM_CLK);
1207
1208 return 0;
1209}
1210static int msm_startup(struct snd_pcm_substream *substream)
1211{
1212 pr_debug("%s(): substream = %s stream = %d\n", __func__,
1213 substream->name, substream->stream);
1214 return 0;
1215}
1216
1217static int msm_auxpcm_startup(struct snd_pcm_substream *substream)
1218{
1219 int ret = 0;
1220
1221 pr_debug("%s(): substream = %s\n", __func__, substream->name);
1222 ret = msm_aux_pcm_get_gpios();
1223 if (ret < 0) {
1224 pr_err("%s: Aux PCM GPIO request failed\n", __func__);
1225 return -EINVAL;
1226 }
1227 return 0;
1228}
1229
1230static void msm_auxpcm_shutdown(struct snd_pcm_substream *substream)
1231{
1232
1233 pr_debug("%s(): substream = %s\n", __func__, substream->name);
1234 msm_aux_pcm_free_gpios();
1235}
1236
1237static void msm_shutdown(struct snd_pcm_substream *substream)
1238{
1239 pr_debug("%s(): substream = %s stream = %d\n", __func__,
1240 substream->name, substream->stream);
1241}
1242
1243static struct snd_soc_ops msm_be_ops = {
1244 .startup = msm_startup,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08001245 .hw_params = msm_hw_params,
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001246 .shutdown = msm_shutdown,
1247};
1248
1249static struct snd_soc_ops msm_auxpcm_be_ops = {
1250 .startup = msm_auxpcm_startup,
1251 .shutdown = msm_auxpcm_shutdown,
1252};
1253
Neema Shetty3c9d2862012-03-11 01:25:32 -08001254static struct snd_soc_ops msm_slimbus_1_be_ops = {
1255 .startup = msm_startup,
1256 .hw_params = msm_slimbus_1_hw_params,
1257 .shutdown = msm_shutdown,
1258};
1259
Helen Zeng8f925502012-03-05 16:50:17 -08001260static struct snd_soc_ops msm_slimbus_4_be_ops = {
1261 .startup = msm_startup,
1262 .hw_params = msm_slimbus_4_hw_params,
1263 .shutdown = msm_shutdown,
1264};
1265
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001266/* Digital audio interface glue - connects codec <---> CPU */
1267static struct snd_soc_dai_link msm_dai[] = {
1268 /* FrontEnd DAI Links */
1269 {
1270 .name = "MSM8960 Media1",
1271 .stream_name = "MultiMedia1",
1272 .cpu_dai_name = "MultiMedia1",
1273 .platform_name = "msm-pcm-dsp",
1274 .dynamic = 1,
1275 .dsp_link = &fe_media,
1276 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA1
1277 },
1278 {
1279 .name = "MSM8960 Media2",
1280 .stream_name = "MultiMedia2",
1281 .cpu_dai_name = "MultiMedia2",
1282 .platform_name = "msm-pcm-dsp",
1283 .dynamic = 1,
1284 .dsp_link = &fe_media,
1285 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA2,
1286 },
1287 {
1288 .name = "Circuit-Switch Voice",
1289 .stream_name = "CS-Voice",
1290 .cpu_dai_name = "CS-VOICE",
1291 .platform_name = "msm-pcm-voice",
1292 .dynamic = 1,
1293 .dsp_link = &fe_media,
1294 .be_id = MSM_FRONTEND_DAI_CS_VOICE,
1295 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1296 .ignore_suspend = 1,
1297 },
1298 {
1299 .name = "MSM VoIP",
1300 .stream_name = "VoIP",
1301 .cpu_dai_name = "VoIP",
1302 .platform_name = "msm-voip-dsp",
1303 .dynamic = 1,
1304 .dsp_link = &fe_media,
1305 .be_id = MSM_FRONTEND_DAI_VOIP,
1306 },
1307 {
1308 .name = "MSM8960 LPA",
1309 .stream_name = "LPA",
1310 .cpu_dai_name = "MultiMedia3",
1311 .platform_name = "msm-pcm-lpa",
1312 .dynamic = 1,
1313 .dsp_link = &lpa_fe_media,
1314 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA3,
1315 },
1316 /* Hostless PMC purpose */
1317 {
1318 .name = "SLIMBUS_0 Hostless",
1319 .stream_name = "SLIMBUS_0 Hostless",
1320 .cpu_dai_name = "SLIMBUS0_HOSTLESS",
1321 .platform_name = "msm-pcm-hostless",
1322 .dynamic = 1,
1323 .dsp_link = &slimbus0_hl_media,
1324 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1325 .ignore_suspend = 1,
1326 /* .be_id = do not care */
1327 },
1328 {
1329 .name = "INT_FM Hostless",
1330 .stream_name = "INT_FM Hostless",
1331 .cpu_dai_name = "INT_FM_HOSTLESS",
1332 .platform_name = "msm-pcm-hostless",
1333 .dynamic = 1,
1334 .dsp_link = &int_fm_hl_media,
1335 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1336 .ignore_suspend = 1,
1337 /* .be_id = do not care */
1338 },
1339 {
1340 .name = "MSM AFE-PCM RX",
1341 .stream_name = "AFE-PROXY RX",
1342 .cpu_dai_name = "msm-dai-q6.241",
1343 .codec_name = "msm-stub-codec.1",
1344 .codec_dai_name = "msm-stub-rx",
1345 .platform_name = "msm-pcm-afe",
1346 .ignore_suspend = 1,
1347 },
1348 {
1349 .name = "MSM AFE-PCM TX",
1350 .stream_name = "AFE-PROXY TX",
1351 .cpu_dai_name = "msm-dai-q6.240",
1352 .codec_name = "msm-stub-codec.1",
1353 .codec_dai_name = "msm-stub-tx",
1354 .platform_name = "msm-pcm-afe",
1355 .ignore_suspend = 1,
1356 },
Neema Shettyb9451242012-02-16 15:37:59 -08001357 {
1358 .name = "Voice Stub",
1359 .stream_name = "Voice Stub",
1360 .cpu_dai_name = "VOICE_STUB",
1361 .platform_name = "msm-pcm-hostless",
1362 .dynamic = 1,
1363 .dsp_link = &fe_media,
1364 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1365 .ignore_suspend = 1,
Neema Shetty3c9d2862012-03-11 01:25:32 -08001366 .be_id = MSM_FRONTEND_DAI_VOICE_STUB,
Neema Shettyb9451242012-02-16 15:37:59 -08001367 },
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001368 /* Backend DAI Links */
1369 {
1370 .name = LPASS_BE_SLIMBUS_0_RX,
1371 .stream_name = "Slimbus Playback",
1372 .cpu_dai_name = "msm-dai-q6.16384",
1373 .platform_name = "msm-pcm-routing",
1374 .codec_name = "tabla_codec",
1375 .codec_dai_name = "tabla_rx1",
1376 .no_pcm = 1,
1377 .be_id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
1378 .init = &msm_audrx_init,
1379 .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
1380 .ops = &msm_be_ops,
1381 },
1382 {
1383 .name = LPASS_BE_SLIMBUS_0_TX,
1384 .stream_name = "Slimbus Capture",
1385 .cpu_dai_name = "msm-dai-q6.16385",
1386 .platform_name = "msm-pcm-routing",
1387 .codec_name = "tabla_codec",
1388 .codec_dai_name = "tabla_tx1",
1389 .no_pcm = 1,
1390 .be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
1391 .be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
1392 .ops = &msm_be_ops,
1393 },
1394 /* Backend BT/FM DAI Links */
1395 {
1396 .name = LPASS_BE_INT_BT_SCO_RX,
1397 .stream_name = "Internal BT-SCO Playback",
1398 .cpu_dai_name = "msm-dai-q6.12288",
1399 .platform_name = "msm-pcm-routing",
1400 .codec_name = "msm-stub-codec.1",
1401 .codec_dai_name = "msm-stub-rx",
1402 .init = &msm_btsco_init,
1403 .no_pcm = 1,
1404 .be_id = MSM_BACKEND_DAI_INT_BT_SCO_RX,
1405 .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
1406 },
1407 {
1408 .name = LPASS_BE_INT_BT_SCO_TX,
1409 .stream_name = "Internal BT-SCO Capture",
1410 .cpu_dai_name = "msm-dai-q6.12289",
1411 .platform_name = "msm-pcm-routing",
1412 .codec_name = "msm-stub-codec.1",
1413 .codec_dai_name = "msm-stub-tx",
1414 .no_pcm = 1,
1415 .be_id = MSM_BACKEND_DAI_INT_BT_SCO_TX,
1416 .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
1417 },
1418 {
1419 .name = LPASS_BE_INT_FM_RX,
1420 .stream_name = "Internal FM Playback",
1421 .cpu_dai_name = "msm-dai-q6.12292",
1422 .platform_name = "msm-pcm-routing",
1423 .codec_name = "msm-stub-codec.1",
1424 .codec_dai_name = "msm-stub-rx",
1425 .no_pcm = 1,
1426 .be_id = MSM_BACKEND_DAI_INT_FM_RX,
1427 .be_hw_params_fixup = msm_be_hw_params_fixup,
1428 },
1429 {
1430 .name = LPASS_BE_INT_FM_TX,
1431 .stream_name = "Internal FM Capture",
1432 .cpu_dai_name = "msm-dai-q6.12293",
1433 .platform_name = "msm-pcm-routing",
1434 .codec_name = "msm-stub-codec.1",
1435 .codec_dai_name = "msm-stub-tx",
1436 .no_pcm = 1,
1437 .be_id = MSM_BACKEND_DAI_INT_FM_TX,
1438 .be_hw_params_fixup = msm_be_hw_params_fixup,
1439 },
1440 /* HDMI BACK END DAI Link */
1441 {
1442 .name = LPASS_BE_HDMI,
1443 .stream_name = "HDMI Playback",
Swaminathan Sathappanfd9dbad2012-02-15 16:56:44 -08001444 .cpu_dai_name = "msm-dai-q6-hdmi.8",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001445 .platform_name = "msm-pcm-routing",
1446 .codec_name = "msm-stub-codec.1",
1447 .codec_dai_name = "msm-stub-rx",
1448 .no_pcm = 1,
1449 .no_codec = 1,
1450 .be_id = MSM_BACKEND_DAI_HDMI_RX,
Swaminathan Sathappanfd9dbad2012-02-15 16:56:44 -08001451 .be_hw_params_fixup = msm_hdmi_be_hw_params_fixup,
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001452 },
1453 /* Backend AFE DAI Links */
1454 {
1455 .name = LPASS_BE_AFE_PCM_RX,
1456 .stream_name = "AFE Playback",
1457 .cpu_dai_name = "msm-dai-q6.224",
1458 .platform_name = "msm-pcm-routing",
1459 .codec_name = "msm-stub-codec.1",
1460 .codec_dai_name = "msm-stub-rx",
1461 .no_codec = 1,
1462 .no_pcm = 1,
1463 .be_id = MSM_BACKEND_DAI_AFE_PCM_RX,
1464 },
1465 {
1466 .name = LPASS_BE_AFE_PCM_TX,
1467 .stream_name = "AFE Capture",
1468 .cpu_dai_name = "msm-dai-q6.225",
1469 .platform_name = "msm-pcm-routing",
1470 .codec_name = "msm-stub-codec.1",
1471 .codec_dai_name = "msm-stub-tx",
1472 .no_codec = 1,
1473 .no_pcm = 1,
1474 .be_id = MSM_BACKEND_DAI_AFE_PCM_TX,
1475 },
1476 /* AUX PCM Backend DAI Links */
1477 {
1478 .name = LPASS_BE_AUXPCM_RX,
1479 .stream_name = "AUX PCM Playback",
1480 .cpu_dai_name = "msm-dai-q6.2",
1481 .platform_name = "msm-pcm-routing",
1482 .codec_name = "msm-stub-codec.1",
1483 .codec_dai_name = "msm-stub-rx",
1484 .no_pcm = 1,
1485 .be_id = MSM_BACKEND_DAI_AUXPCM_RX,
1486 .be_hw_params_fixup = msm_auxpcm_be_params_fixup,
1487 .ops = &msm_auxpcm_be_ops,
1488 },
1489 {
1490 .name = LPASS_BE_AUXPCM_TX,
1491 .stream_name = "AUX PCM Capture",
1492 .cpu_dai_name = "msm-dai-q6.3",
1493 .platform_name = "msm-pcm-routing",
1494 .codec_name = "msm-stub-codec.1",
1495 .codec_dai_name = "msm-stub-tx",
1496 .no_pcm = 1,
1497 .be_id = MSM_BACKEND_DAI_AUXPCM_TX,
1498 .be_hw_params_fixup = msm_auxpcm_be_params_fixup,
1499 },
Neema Shettyb9451242012-02-16 15:37:59 -08001500 {
1501 .name = LPASS_BE_STUB_RX,
1502 .stream_name = "Stub Playback",
1503 .cpu_dai_name = "msm-dai-stub",
1504 .platform_name = "msm-pcm-routing",
1505 .codec_name = "tabla_codec",
1506 .codec_dai_name = "tabla_rx2",
1507 .no_pcm = 1,
1508 /* .be_id = do not care */
1509 .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
Helen Zengf3b17fb2012-02-28 15:07:38 -08001510 .init = &msm_stubrx_init,
Neema Shettyb9451242012-02-16 15:37:59 -08001511 .ops = &msm_be_ops,
1512 },
1513 {
1514 .name = LPASS_BE_STUB_TX,
1515 .stream_name = "Stub Capture",
1516 .cpu_dai_name = "msm-dai-stub",
1517 .platform_name = "msm-pcm-routing",
1518 .codec_name = "tabla_codec",
1519 .codec_dai_name = "tabla_tx1",
1520 .no_pcm = 1,
1521 /* .be_id = do not care */
1522 .be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
1523 .ops = &msm_be_ops,
1524 },
Neema Shetty3c9d2862012-03-11 01:25:32 -08001525 {
1526 .name = LPASS_BE_SLIMBUS_1_RX,
1527 .stream_name = "Slimbus1 Playback",
1528 .cpu_dai_name = "msm-dai-q6.16386",
1529 .platform_name = "msm-pcm-routing",
1530 .codec_name = "msm-stub-codec.1",
1531 .codec_dai_name = "msm-stub-rx",
1532 .no_pcm = 1,
1533 .be_id = MSM_BACKEND_DAI_SLIMBUS_1_RX,
1534 .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
1535 .ops = &msm_slimbus_1_be_ops,
1536
1537 },
1538 {
1539 .name = LPASS_BE_SLIMBUS_1_TX,
1540 .stream_name = "Slimbus1 Capture",
1541 .cpu_dai_name = "msm-dai-q6.16387",
1542 .platform_name = "msm-pcm-routing",
1543 .codec_name = "msm-stub-codec.1",
1544 .codec_dai_name = "msm-stub-tx",
1545 .no_pcm = 1,
1546 .be_id = MSM_BACKEND_DAI_SLIMBUS_1_TX,
1547 .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
1548 .ops = &msm_slimbus_1_be_ops,
1549 },
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001550 {
1551 .name = "SLIMBUS_2 Hostless",
1552 .stream_name = "SLIMBUS_2 Hostless",
1553 .cpu_dai_name = "msm-dai-q6.16389",
1554 .platform_name = "msm-pcm-hostless",
1555 .codec_name = "tabla_codec",
1556 .codec_dai_name = "tabla_tx2",
1557 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1558 .ops = &msm_be_ops,
1559 },
1560
Helen Zeng8f925502012-03-05 16:50:17 -08001561 /* Incall Music Back End DAI Link */
1562 {
1563 .name = LPASS_BE_SLIMBUS_4_RX,
1564 .stream_name = "Slimbus4 Playback",
1565 .cpu_dai_name = "msm-dai-q6.16392",
1566 .platform_name = "msm-pcm-routing",
1567 .codec_name = "msm-stub-codec.1",
1568 .codec_dai_name = "msm-stub-rx",
1569 .no_pcm = 1,
1570 .no_codec = 1,
1571 .be_id = MSM_BACKEND_DAI_SLIMBUS_4_RX,
1572 .be_hw_params_fixup = msm_be_hw_params_fixup,
1573 .ops = &msm_slimbus_4_be_ops,
1574 },
1575 /* Incall Record Back End DAI Link */
1576 {
1577 .name = LPASS_BE_SLIMBUS_4_TX,
1578 .stream_name = "Slimbus4 Capture",
1579 .cpu_dai_name = "msm-dai-q6.16393",
1580 .platform_name = "msm-pcm-routing",
1581 .codec_name = "msm-stub-codec.1",
1582 .codec_dai_name = "msm-stub-tx",
1583 .no_pcm = 1,
1584 .no_codec = 1,
1585 .be_id = MSM_BACKEND_DAI_SLIMBUS_4_TX,
1586 .be_hw_params_fixup = msm_be_hw_params_fixup,
1587 .init = &msm_incall_rec_init,
1588 .ops = &msm_slimbus_4_be_ops,
1589 },
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001590};
1591
1592struct snd_soc_card snd_soc_card_msm = {
Swaminathan Sathappanc165a3a2012-02-29 12:44:31 -08001593 .name = "apq8064-tabla-snd-card",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001594 .dai_link = msm_dai,
1595 .num_links = ARRAY_SIZE(msm_dai),
1596};
1597
1598static struct platform_device *msm_snd_device;
1599
1600static int msm_configure_headset_mic_gpios(void)
1601{
1602 int ret;
1603 struct pm_gpio param = {
1604 .direction = PM_GPIO_DIR_OUT,
1605 .output_buffer = PM_GPIO_OUT_BUF_CMOS,
1606 .output_value = 1,
1607 .pull = PM_GPIO_PULL_NO,
1608 .vin_sel = PM_GPIO_VIN_S4,
1609 .out_strength = PM_GPIO_STRENGTH_MED,
1610 .function = PM_GPIO_FUNC_NORMAL,
1611 };
1612
1613 ret = gpio_request(PM8921_GPIO_PM_TO_SYS(23), "AV_SWITCH");
1614 if (ret) {
1615 pr_err("%s: Failed to request gpio %d\n", __func__,
1616 PM8921_GPIO_PM_TO_SYS(23));
1617 return ret;
1618 }
1619
1620 ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(23), &param);
1621 if (ret)
1622 pr_err("%s: Failed to configure gpio %d\n", __func__,
1623 PM8921_GPIO_PM_TO_SYS(23));
1624 else
1625 gpio_direction_output(PM8921_GPIO_PM_TO_SYS(23), 0);
1626
1627 ret = gpio_request(PM8921_GPIO_PM_TO_SYS(35), "US_EURO_SWITCH");
1628 if (ret) {
1629 pr_err("%s: Failed to request gpio %d\n", __func__,
1630 PM8921_GPIO_PM_TO_SYS(35));
1631 gpio_free(PM8921_GPIO_PM_TO_SYS(23));
1632 return ret;
1633 }
1634 ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(35), &param);
1635 if (ret)
1636 pr_err("%s: Failed to configure gpio %d\n", __func__,
1637 PM8921_GPIO_PM_TO_SYS(35));
1638 else
1639 gpio_direction_output(PM8921_GPIO_PM_TO_SYS(35), 0);
1640
1641 return 0;
1642}
1643static void msm_free_headset_mic_gpios(void)
1644{
1645 if (msm_headset_gpios_configured) {
1646 gpio_free(PM8921_GPIO_PM_TO_SYS(23));
1647 gpio_free(PM8921_GPIO_PM_TO_SYS(35));
1648 }
1649}
1650
1651static int __init msm_audio_init(void)
1652{
1653 int ret;
1654
Santosh Mardi911b27fd2012-04-04 03:09:01 +05301655 if (!cpu_is_apq8064() || (socinfo_get_id() == 130)) {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001656 pr_err("%s: Not the right machine type\n", __func__);
1657 return -ENODEV;
1658 }
1659
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001660 mbhc_cfg.calibration = def_tabla_mbhc_cal();
1661 if (!mbhc_cfg.calibration) {
Joonwoo Park0976d012011-12-22 11:48:18 -08001662 pr_err("Calibration data allocation failed\n");
1663 return -ENOMEM;
1664 }
1665
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001666 msm_snd_device = platform_device_alloc("soc-audio", 0);
1667 if (!msm_snd_device) {
1668 pr_err("Platform device allocation failed\n");
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001669 kfree(mbhc_cfg.calibration);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001670 return -ENOMEM;
1671 }
1672
1673 platform_set_drvdata(msm_snd_device, &snd_soc_card_msm);
1674 ret = platform_device_add(msm_snd_device);
1675 if (ret) {
1676 platform_device_put(msm_snd_device);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001677 kfree(mbhc_cfg.calibration);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001678 return ret;
1679 }
1680
1681 if (msm_configure_headset_mic_gpios()) {
1682 pr_err("%s Fail to configure headset mic gpios\n", __func__);
1683 msm_headset_gpios_configured = 0;
1684 } else
1685 msm_headset_gpios_configured = 1;
1686
1687 return ret;
1688
1689}
1690module_init(msm_audio_init);
1691
1692static void __exit msm_audio_exit(void)
1693{
Santosh Mardi911b27fd2012-04-04 03:09:01 +05301694 if (!cpu_is_apq8064() || (socinfo_get_id() == 130)) {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001695 pr_err("%s: Not the right machine type\n", __func__);
1696 return ;
1697 }
1698 msm_free_headset_mic_gpios();
1699 platform_device_unregister(msm_snd_device);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001700 kfree(mbhc_cfg.calibration);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001701}
1702module_exit(msm_audio_exit);
1703
1704MODULE_DESCRIPTION("ALSA SoC msm");
1705MODULE_LICENSE("GPL v2");