blob: 2da5c6a725aa7ac76caaf8f4aa8193d16cec65bb [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>
Neema Shettya58b9a22012-06-18 19:03:23 -070021#include <linux/pm_runtime.h>
22#include <linux/slimbus/slimbus.h>
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -080023#include <sound/core.h>
24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -080026#include <sound/pcm.h>
27#include <sound/jack.h>
28#include <asm/mach-types.h>
29#include <mach/socinfo.h>
30#include "msm-pcm-routing.h"
31#include "../codecs/wcd9310.h"
32
33/* 8064 machine driver */
34
35#define PM8921_GPIO_BASE NR_GPIO_IRQS
36#define PM8921_GPIO_PM_TO_SYS(pm_gpio) (pm_gpio - 1 + PM8921_GPIO_BASE)
37
38#define MSM8064_SPK_ON 1
39#define MSM8064_SPK_OFF 0
40
41#define MSM_SLIM_0_RX_MAX_CHANNELS 2
42#define MSM_SLIM_0_TX_MAX_CHANNELS 4
43
44#define BTSCO_RATE_8KHZ 8000
45#define BTSCO_RATE_16KHZ 16000
46
47#define BOTTOM_SPK_AMP_POS 0x1
48#define BOTTOM_SPK_AMP_NEG 0x2
49#define TOP_SPK_AMP_POS 0x4
50#define TOP_SPK_AMP_NEG 0x8
Kiran Kandi97fe19d2012-05-20 22:34:04 -070051#define TOP_SPK_AMP 0x10
52
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -080053
54#define GPIO_AUX_PCM_DOUT 43
55#define GPIO_AUX_PCM_DIN 44
56#define GPIO_AUX_PCM_SYNC 45
57#define GPIO_AUX_PCM_CLK 46
58
Joonwoo Park0976d012011-12-22 11:48:18 -080059#define TABLA_EXT_CLK_RATE 12288000
60
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -080061#define TABLA_MBHC_DEF_BUTTONS 8
Joonwoo Park0976d012011-12-22 11:48:18 -080062#define TABLA_MBHC_DEF_RLOADS 5
63
Joonwoo Parkca1516f2012-05-08 13:59:37 -070064#define JACK_DETECT_GPIO 38
65
Neema Shetty3c9d2862012-03-11 01:25:32 -080066/* Shared channel numbers for Slimbus ports that connect APQ to MDM. */
67enum {
68 SLIM_1_RX_1 = 145, /* BT-SCO and USB TX */
69 SLIM_1_TX_1 = 146, /* BT-SCO and USB RX */
Neema Shetty74131ac2012-05-09 13:35:26 -070070 SLIM_3_RX_1 = 151, /* External echo-cancellation ref */
71 SLIM_3_RX_2 = 152, /* External echo-cancellation ref */
Helen Zeng38c3c962012-05-17 14:56:20 -070072 SLIM_3_TX_1 = 153, /* HDMI RX */
73 SLIM_3_TX_2 = 154, /* HDMI RX */
Helen Zeng8f925502012-03-05 16:50:17 -080074 SLIM_4_TX_1 = 148, /* In-call recording RX */
75 SLIM_4_TX_2 = 149, /* In-call recording RX */
76 SLIM_4_RX_1 = 150, /* In-call music delivery TX */
77};
78
79enum {
80 INCALL_REC_MONO,
81 INCALL_REC_STEREO,
Neema Shetty3c9d2862012-03-11 01:25:32 -080082};
83
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -080084static u32 top_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(18);
85static u32 bottom_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(19);
86static int msm_spk_control;
87static int msm_ext_bottom_spk_pamp;
88static int msm_ext_top_spk_pamp;
89static int msm_slim_0_rx_ch = 1;
90static int msm_slim_0_tx_ch = 1;
Neema Shetty74131ac2012-05-09 13:35:26 -070091static int msm_slim_3_rx_ch = 1;
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -080092
93static int msm_btsco_rate = BTSCO_RATE_8KHZ;
94static int msm_btsco_ch = 1;
95
Helen Zeng8f925502012-03-05 16:50:17 -080096static int rec_mode = INCALL_REC_MONO;
97
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -080098static struct clk *codec_clk;
99static int clk_users;
100
101static int msm_headset_gpios_configured;
102
103static struct snd_soc_jack hs_jack;
104static struct snd_soc_jack button_jack;
105
Joonwoo Park26998702012-05-09 10:10:06 -0700106static int apq8064_hs_detect_use_gpio = -1;
107module_param(apq8064_hs_detect_use_gpio, int, 0444);
108MODULE_PARM_DESC(apq8064_hs_detect_use_gpio, "Use GPIO for headset detection");
109
110static bool apq8064_hs_detect_use_firmware;
111module_param(apq8064_hs_detect_use_firmware, bool, 0444);
112MODULE_PARM_DESC(apq8064_hs_detect_use_firmware, "Use firmware for headset "
113 "detection");
Joonwoo Parkca1516f2012-05-08 13:59:37 -0700114
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700115static int msm_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
116 bool dapm);
117
118static struct tabla_mbhc_config mbhc_cfg = {
119 .headset_jack = &hs_jack,
120 .button_jack = &button_jack,
121 .read_fw_bin = false,
122 .calibration = NULL,
123 .micbias = TABLA_MICBIAS2,
124 .mclk_cb_fn = msm_enable_codec_ext_clk,
125 .mclk_rate = TABLA_EXT_CLK_RATE,
Joonwoo Parkca1516f2012-05-08 13:59:37 -0700126 .gpio = 0,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700127 .gpio_irq = 0,
128 .gpio_level_insert = 1,
129};
Joonwoo Park0976d012011-12-22 11:48:18 -0800130
Joonwoo Park9db5fb7a2012-06-15 12:10:46 -0700131static struct mutex cdc_mclk_mutex;
132
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800133static void msm_enable_ext_spk_amp_gpio(u32 spk_amp_gpio)
134{
135 int ret = 0;
136
137 struct pm_gpio param = {
138 .direction = PM_GPIO_DIR_OUT,
139 .output_buffer = PM_GPIO_OUT_BUF_CMOS,
140 .output_value = 1,
141 .pull = PM_GPIO_PULL_NO,
142 .vin_sel = PM_GPIO_VIN_S4,
143 .out_strength = PM_GPIO_STRENGTH_MED,
144 .
145 function = PM_GPIO_FUNC_NORMAL,
146 };
147
148 if (spk_amp_gpio == bottom_spk_pamp_gpio) {
149
150 ret = gpio_request(bottom_spk_pamp_gpio, "BOTTOM_SPK_AMP");
151 if (ret) {
152 pr_err("%s: Error requesting BOTTOM SPK AMP GPIO %u\n",
153 __func__, bottom_spk_pamp_gpio);
154 return;
155 }
156 ret = pm8xxx_gpio_config(bottom_spk_pamp_gpio, &param);
157 if (ret)
158 pr_err("%s: Failed to configure Bottom Spk Ampl"
159 " gpio %u\n", __func__, bottom_spk_pamp_gpio);
160 else {
161 pr_debug("%s: enable Bottom spkr amp gpio\n", __func__);
162 gpio_direction_output(bottom_spk_pamp_gpio, 1);
163 }
164
165 } else if (spk_amp_gpio == top_spk_pamp_gpio) {
166
167 ret = gpio_request(top_spk_pamp_gpio, "TOP_SPK_AMP");
168 if (ret) {
169 pr_err("%s: Error requesting GPIO %d\n", __func__,
170 top_spk_pamp_gpio);
171 return;
172 }
173 ret = pm8xxx_gpio_config(top_spk_pamp_gpio, &param);
174 if (ret)
175 pr_err("%s: Failed to configure Top Spk Ampl"
176 " gpio %u\n", __func__, top_spk_pamp_gpio);
177 else {
178 pr_debug("%s: enable Top spkr amp gpio\n", __func__);
179 gpio_direction_output(top_spk_pamp_gpio, 1);
180 }
181 } else {
182 pr_err("%s: ERROR : Invalid External Speaker Ampl GPIO."
183 " gpio = %u\n", __func__, spk_amp_gpio);
184 return;
185 }
186}
187
188static void msm_ext_spk_power_amp_on(u32 spk)
189{
190 if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) {
191
192 if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) &&
193 (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) {
194
195 pr_debug("%s() External Bottom Speaker Ampl already "
196 "turned on. spk = 0x%08x\n", __func__, spk);
197 return;
198 }
199
200 msm_ext_bottom_spk_pamp |= spk;
201
202 if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) &&
203 (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) {
204
205 msm_enable_ext_spk_amp_gpio(bottom_spk_pamp_gpio);
206 pr_debug("%s: slepping 4 ms after turning on external "
207 " Bottom Speaker Ampl\n", __func__);
208 usleep_range(4000, 4000);
209 }
210
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700211 } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG | TOP_SPK_AMP)) {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800212
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700213 pr_debug("%s():top_spk_amp_state = 0x%x spk_event = 0x%x\n",
214 __func__, msm_ext_top_spk_pamp, spk);
215
216 if (((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) &&
217 (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) ||
218 (msm_ext_top_spk_pamp & TOP_SPK_AMP)) {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800219
220 pr_debug("%s() External Top Speaker Ampl already"
221 "turned on. spk = 0x%08x\n", __func__, spk);
222 return;
223 }
224
225 msm_ext_top_spk_pamp |= spk;
226
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700227 if (((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) &&
228 (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) ||
229 (msm_ext_top_spk_pamp & TOP_SPK_AMP)) {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800230
231 msm_enable_ext_spk_amp_gpio(top_spk_pamp_gpio);
232 pr_debug("%s: sleeping 4 ms after turning on "
233 " external Top Speaker Ampl\n", __func__);
234 usleep_range(4000, 4000);
235 }
236 } else {
237
238 pr_err("%s: ERROR : Invalid External Speaker Ampl. spk = 0x%08x\n",
239 __func__, spk);
240 return;
241 }
242}
243
244static void msm_ext_spk_power_amp_off(u32 spk)
245{
246 if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) {
247
248 if (!msm_ext_bottom_spk_pamp)
249 return;
250
251 gpio_direction_output(bottom_spk_pamp_gpio, 0);
252 gpio_free(bottom_spk_pamp_gpio);
253 msm_ext_bottom_spk_pamp = 0;
254
255 pr_debug("%s: sleeping 4 ms after turning off external Bottom"
256 " Speaker Ampl\n", __func__);
257
258 usleep_range(4000, 4000);
259
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700260 } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG | TOP_SPK_AMP)) {
261
262 pr_debug("%s: top_spk_amp_state = 0x%x spk_event = 0x%x\n",
263 __func__, msm_ext_top_spk_pamp, spk);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800264
265 if (!msm_ext_top_spk_pamp)
266 return;
267
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700268 if ((spk & TOP_SPK_AMP_POS) || (spk & TOP_SPK_AMP_NEG)) {
269
270 msm_ext_top_spk_pamp &= (~(TOP_SPK_AMP_POS |
271 TOP_SPK_AMP_NEG));
272 } else if (spk & TOP_SPK_AMP) {
273 msm_ext_top_spk_pamp &= ~TOP_SPK_AMP;
274 }
275
276 if (msm_ext_top_spk_pamp)
277 return;
278
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800279 gpio_direction_output(top_spk_pamp_gpio, 0);
280 gpio_free(top_spk_pamp_gpio);
281 msm_ext_top_spk_pamp = 0;
282
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700283 pr_debug("%s: sleeping 4 ms after ext Top Spek Ampl is off\n",
284 __func__);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800285
286 usleep_range(4000, 4000);
287 } else {
288
289 pr_err("%s: ERROR : Invalid Ext Spk Ampl. spk = 0x%08x\n",
290 __func__, spk);
291 return;
292 }
293}
294
295static void msm_ext_control(struct snd_soc_codec *codec)
296{
297 struct snd_soc_dapm_context *dapm = &codec->dapm;
298
299 pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control);
300 if (msm_spk_control == MSM8064_SPK_ON) {
301 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos");
302 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg");
303 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos");
304 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg");
305 } else {
306 snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Pos");
307 snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Neg");
308 snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Pos");
309 snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Neg");
310 }
311
312 snd_soc_dapm_sync(dapm);
313}
314
315static int msm_get_spk(struct snd_kcontrol *kcontrol,
316 struct snd_ctl_elem_value *ucontrol)
317{
318 pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control);
319 ucontrol->value.integer.value[0] = msm_spk_control;
320 return 0;
321}
322static int msm_set_spk(struct snd_kcontrol *kcontrol,
323 struct snd_ctl_elem_value *ucontrol)
324{
325 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
326
327 pr_debug("%s()\n", __func__);
328 if (msm_spk_control == ucontrol->value.integer.value[0])
329 return 0;
330
331 msm_spk_control = ucontrol->value.integer.value[0];
332 msm_ext_control(codec);
333 return 1;
334}
335static int msm_spkramp_event(struct snd_soc_dapm_widget *w,
336 struct snd_kcontrol *k, int event)
337{
338 pr_debug("%s() %x\n", __func__, SND_SOC_DAPM_EVENT_ON(event));
339
340 if (SND_SOC_DAPM_EVENT_ON(event)) {
341 if (!strncmp(w->name, "Ext Spk Bottom Pos", 18))
342 msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_POS);
343 else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18))
344 msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_NEG);
345 else if (!strncmp(w->name, "Ext Spk Top Pos", 15))
346 msm_ext_spk_power_amp_on(TOP_SPK_AMP_POS);
347 else if (!strncmp(w->name, "Ext Spk Top Neg", 15))
348 msm_ext_spk_power_amp_on(TOP_SPK_AMP_NEG);
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700349 else if (!strncmp(w->name, "Ext Spk Top", 12))
350 msm_ext_spk_power_amp_on(TOP_SPK_AMP);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800351 else {
352 pr_err("%s() Invalid Speaker Widget = %s\n",
353 __func__, w->name);
354 return -EINVAL;
355 }
356
357 } else {
358 if (!strncmp(w->name, "Ext Spk Bottom Pos", 18))
359 msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_POS);
360 else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18))
361 msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_NEG);
362 else if (!strncmp(w->name, "Ext Spk Top Pos", 15))
363 msm_ext_spk_power_amp_off(TOP_SPK_AMP_POS);
364 else if (!strncmp(w->name, "Ext Spk Top Neg", 15))
365 msm_ext_spk_power_amp_off(TOP_SPK_AMP_NEG);
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700366 else if (!strncmp(w->name, "Ext Spk Top", 12))
367 msm_ext_spk_power_amp_off(TOP_SPK_AMP);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800368 else {
369 pr_err("%s() Invalid Speaker Widget = %s\n",
370 __func__, w->name);
371 return -EINVAL;
372 }
373 }
374 return 0;
375}
376
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700377static int msm_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
378 bool dapm)
Joonwoo Park0976d012011-12-22 11:48:18 -0800379{
Joonwoo Park9db5fb7a2012-06-15 12:10:46 -0700380 int r = 0;
Joonwoo Park0976d012011-12-22 11:48:18 -0800381 pr_debug("%s: enable = %d\n", __func__, enable);
Joonwoo Park9db5fb7a2012-06-15 12:10:46 -0700382
383 mutex_lock(&cdc_mclk_mutex);
Joonwoo Park0976d012011-12-22 11:48:18 -0800384 if (enable) {
385 clk_users++;
386 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
Joonwoo Park9db5fb7a2012-06-15 12:10:46 -0700387 if (clk_users == 1) {
388 if (codec_clk) {
389 clk_set_rate(codec_clk, TABLA_EXT_CLK_RATE);
390 clk_prepare_enable(codec_clk);
391 tabla_mclk_enable(codec, 1, dapm);
392 } else {
393 pr_err("%s: Error setting Tabla MCLK\n",
394 __func__);
395 clk_users--;
396 r = -EINVAL;
397 }
Joonwoo Park0976d012011-12-22 11:48:18 -0800398 }
399 } else {
Joonwoo Park9db5fb7a2012-06-15 12:10:46 -0700400 if (clk_users > 0) {
401 clk_users--;
402 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
403 if (clk_users == 0) {
404 pr_debug("%s: disabling MCLK. clk_users = %d\n",
Joonwoo Park0976d012011-12-22 11:48:18 -0800405 __func__, clk_users);
Joonwoo Park9db5fb7a2012-06-15 12:10:46 -0700406 tabla_mclk_enable(codec, 0, dapm);
407 clk_disable_unprepare(codec_clk);
408 }
409 } else {
410 pr_err("%s: Error releasing Tabla MCLK\n", __func__);
411 r = -EINVAL;
Joonwoo Park0976d012011-12-22 11:48:18 -0800412 }
413 }
Joonwoo Park9db5fb7a2012-06-15 12:10:46 -0700414 mutex_unlock(&cdc_mclk_mutex);
415 return r;
Joonwoo Park0976d012011-12-22 11:48:18 -0800416}
417
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800418static int msm_mclk_event(struct snd_soc_dapm_widget *w,
419 struct snd_kcontrol *kcontrol, int event)
420{
421 pr_debug("%s: event = %d\n", __func__, event);
422
423 switch (event) {
424 case SND_SOC_DAPM_PRE_PMU:
425
426 clk_users++;
427 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
428
429 if (clk_users != 1)
430 return 0;
431
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800432 if (codec_clk) {
433 clk_set_rate(codec_clk, 12288000);
Asish Bhattacharya4776d962012-04-25 12:08:09 +0530434 clk_prepare_enable(codec_clk);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700435 tabla_mclk_enable(w->codec, 1, true);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800436
437 } else {
438 pr_err("%s: Error setting Tabla MCLK\n", __func__);
439 clk_users--;
440 return -EINVAL;
441 }
442 break;
443 case SND_SOC_DAPM_POST_PMD:
444
445 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
446
447 if (clk_users == 0)
448 return 0;
449
450 clk_users--;
451
452 if (!clk_users) {
453 pr_debug("%s: disabling MCLK. clk_users = %d\n",
454 __func__, clk_users);
455
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700456 tabla_mclk_enable(w->codec, 0, true);
Asish Bhattacharya4776d962012-04-25 12:08:09 +0530457 clk_disable_unprepare(codec_clk);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800458 }
459 break;
460 }
461 return 0;
462}
463
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700464static const struct snd_soc_dapm_widget apq8064_dapm_widgets[] = {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800465
466 SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0,
467 msm_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
468
469 SND_SOC_DAPM_SPK("Ext Spk Bottom Pos", msm_spkramp_event),
470 SND_SOC_DAPM_SPK("Ext Spk Bottom Neg", msm_spkramp_event),
471
472 SND_SOC_DAPM_SPK("Ext Spk Top Pos", msm_spkramp_event),
473 SND_SOC_DAPM_SPK("Ext Spk Top Neg", msm_spkramp_event),
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700474 SND_SOC_DAPM_SPK("Ext Spk Top", msm_spkramp_event),
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800475
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700476 /************ Analog MICs ************/
477 /**
478 * Analog mic7 (Front Top) on Liquid.
479 * Used as Handset mic on CDP.
480 */
481 SND_SOC_DAPM_MIC("Analog mic7", NULL),
482
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800483 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800484 SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
485 SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
486
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700487 /*********** Digital Mics ***************/
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800488 SND_SOC_DAPM_MIC("Digital Mic1", NULL),
489 SND_SOC_DAPM_MIC("Digital Mic2", NULL),
490 SND_SOC_DAPM_MIC("Digital Mic3", NULL),
491 SND_SOC_DAPM_MIC("Digital Mic4", NULL),
492 SND_SOC_DAPM_MIC("Digital Mic5", NULL),
493 SND_SOC_DAPM_MIC("Digital Mic6", NULL),
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800494};
495
Kiran Kandi323d7102012-04-18 19:56:14 -0700496static const struct snd_soc_dapm_route apq8064_common_audio_map[] = {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800497
498 {"RX_BIAS", NULL, "MCLK"},
499 {"LDO_H", NULL, "MCLK"},
500
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700501 {"HEADPHONE", NULL, "LDO_H"},
502
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800503 /* Speaker path */
504 {"Ext Spk Bottom Pos", NULL, "LINEOUT1"},
505 {"Ext Spk Bottom Neg", NULL, "LINEOUT3"},
506
507 {"Ext Spk Top Pos", NULL, "LINEOUT2"},
508 {"Ext Spk Top Neg", NULL, "LINEOUT4"},
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700509 {"Ext Spk Top", NULL, "LINEOUT5"},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800510
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700511 /************ Analog MIC Paths ************/
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800512
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700513 /* Headset Mic */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800514 {"AMIC2", NULL, "MIC BIAS2 External"},
515 {"MIC BIAS2 External", NULL, "Headset Mic"},
516
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700517 /* Headset ANC microphones */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800518 {"AMIC3", NULL, "MIC BIAS3 Internal1"},
519 {"MIC BIAS3 Internal1", NULL, "ANCRight Headset Mic"},
520
521 {"AMIC4", NULL, "MIC BIAS1 Internal2"},
522 {"MIC BIAS1 Internal2", NULL, "ANCLeft Headset Mic"},
Kiran Kandi323d7102012-04-18 19:56:14 -0700523};
524
525static const struct snd_soc_dapm_route apq8064_mtp_audio_map[] = {
526
527 /************ Digital MIC Paths ************/
528
529 /*
530 * Digital Mic1 (Front bottom Left) on MTP.
531 * Conncted to DMIC1 Input on Tabla codec.
532 */
533 {"DMIC1", NULL, "MIC BIAS1 External"},
534 {"MIC BIAS1 External", NULL, "Digital Mic1"},
535
536 /**
537 * Digital Mic2 (Front bottom right) on MTP.
538 * Conncted to DMIC2 Input on Tabla codec.
539 */
540 {"DMIC2", NULL, "MIC BIAS1 External"},
541 {"MIC BIAS1 External", NULL, "Digital Mic2"},
542
543 /**
544 * Digital Mic3 (Back bottom) on MTP.
545 * Conncted to DMIC3 Input on Tabla codec.
546 */
547 {"DMIC3", NULL, "MIC BIAS3 External"},
548 {"MIC BIAS3 External", NULL, "Digital Mic3"},
549
550 /**
551 * Digital Mic4 (Back top) on MTP.
552 * Conncted to DMIC4 Input on Tabla codec.
553 */
554 {"DMIC4", NULL, "MIC BIAS3 External"},
555 {"MIC BIAS3 External", NULL, "Digital Mic4"},
556
557 /**
558 * Digital Mic5 (Top front Mic) on MTP.
559 * Conncted to DMIC6 Input on Tabla codec.
560 */
561 {"DMIC6", NULL, "MIC BIAS4 External"},
562 {"MIC BIAS4 External", NULL, "Digital Mic5"},
563
564};
565
566static const struct snd_soc_dapm_route apq8064_liquid_cdp_audio_map[] = {
567
568 /************ Analog MIC Paths ************/
569 /**
570 * Analog mic7 (Front Top Mic) on Liquid.
571 * Used as Handset mic on CDP.
572 * Not there on MTP.
573 */
574 {"AMIC1", NULL, "MIC BIAS1 External"},
575 {"MIC BIAS1 External", NULL, "Analog mic7"},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800576
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800577
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700578 /************ Digital MIC Paths ************/
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800579 /**
580 * The digital Mic routes are setup considering
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700581 * Liquid as default device.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800582 */
583
584 /**
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700585 * Digital Mic1 (Front bottom left corner) on Liquid.
586 * Digital Mic2 (Front bottom right) on MTP.
587 * Digital Mic GM1 on CDP mainboard.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800588 * Conncted to DMIC2 Input on Tabla codec.
589 */
590 {"DMIC2", NULL, "MIC BIAS1 External"},
591 {"MIC BIAS1 External", NULL, "Digital Mic1"},
592
593 /**
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700594 * Digital Mic2 (Front left side) on Liquid.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800595 * Digital Mic GM2 on CDP mainboard.
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700596 * Not there on MTP.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800597 * Conncted to DMIC3 Input on Tabla codec.
598 */
599 {"DMIC3", NULL, "MIC BIAS3 External"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700600 {"MIC BIAS3 External", NULL, "Digital Mic2"},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800601
602 /**
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700603 * Digital Mic3. Front bottom left of middle on Liquid.
604 * Digital Mic5 (Top front Mic) on MTP.
605 * Digital Mic GM5 on CDP mainboard.
606 * Conncted to DMIC6 Input on Tabla codec.
607 */
608 {"DMIC6", NULL, "MIC BIAS4 External"},
609 {"MIC BIAS4 External", NULL, "Digital Mic3"},
610
611 /**
612 * Digital Mic4. Back bottom on Liquid.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800613 * Digital Mic GM3 on CDP mainboard.
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700614 * Top Front Mic on MTP.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800615 * Conncted to DMIC5 Input on Tabla codec.
616 */
617 {"DMIC5", NULL, "MIC BIAS4 External"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700618 {"MIC BIAS4 External", NULL, "Digital Mic4"},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800619
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700620 /**
621 * Digital Mic5. Front bottom right of middle on Liquid.
622 * Digital Mic GM6 on CDP mainboard.
623 * Not there on MTP.
624 * Conncted to DMIC4 Input on Tabla codec.
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800625 */
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700626 {"DMIC4", NULL, "MIC BIAS3 External"},
627 {"MIC BIAS3 External", NULL, "Digital Mic5"},
628
629 /* Digital Mic6 (Front bottom right corner) on Liquid.
630 * Digital Mic1 (Front bottom Left) on MTP.
631 * Digital Mic GM4 on CDP.
632 * Conncted to DMIC1 Input on Tabla codec.
633 */
634 {"DMIC1", NULL, "MIC BIAS1 External"},
635 {"MIC BIAS1 External", NULL, "Digital Mic6"},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800636};
637
638static const char *spk_function[] = {"Off", "On"};
639static const char *slim0_rx_ch_text[] = {"One", "Two"};
640static const char *slim0_tx_ch_text[] = {"One", "Two", "Three", "Four"};
641
642static const struct soc_enum msm_enum[] = {
643 SOC_ENUM_SINGLE_EXT(2, spk_function),
644 SOC_ENUM_SINGLE_EXT(2, slim0_rx_ch_text),
645 SOC_ENUM_SINGLE_EXT(4, slim0_tx_ch_text),
646};
647
648static const char *btsco_rate_text[] = {"8000", "16000"};
649static const struct soc_enum msm_btsco_enum[] = {
650 SOC_ENUM_SINGLE_EXT(2, btsco_rate_text),
651};
652
653static int msm_slim_0_rx_ch_get(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_value *ucontrol)
655{
656 pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__,
657 msm_slim_0_rx_ch);
658 ucontrol->value.integer.value[0] = msm_slim_0_rx_ch - 1;
659 return 0;
660}
661
662static int msm_slim_0_rx_ch_put(struct snd_kcontrol *kcontrol,
663 struct snd_ctl_elem_value *ucontrol)
664{
665 msm_slim_0_rx_ch = ucontrol->value.integer.value[0] + 1;
666
667 pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__,
668 msm_slim_0_rx_ch);
669 return 1;
670}
671
672static int msm_slim_0_tx_ch_get(struct snd_kcontrol *kcontrol,
673 struct snd_ctl_elem_value *ucontrol)
674{
675 pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__,
676 msm_slim_0_tx_ch);
677 ucontrol->value.integer.value[0] = msm_slim_0_tx_ch - 1;
678 return 0;
679}
680
681static int msm_slim_0_tx_ch_put(struct snd_kcontrol *kcontrol,
682 struct snd_ctl_elem_value *ucontrol)
683{
684 msm_slim_0_tx_ch = ucontrol->value.integer.value[0] + 1;
685
686 pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__,
687 msm_slim_0_tx_ch);
688 return 1;
689}
690
Neema Shetty74131ac2012-05-09 13:35:26 -0700691static int msm_slim_3_rx_ch_get(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_value *ucontrol)
693{
694 pr_debug("%s: msm_slim_3_rx_ch = %d\n", __func__,
695 msm_slim_3_rx_ch);
696 ucontrol->value.integer.value[0] = msm_slim_3_rx_ch - 1;
697 return 0;
698}
699
700static int msm_slim_3_rx_ch_put(struct snd_kcontrol *kcontrol,
701 struct snd_ctl_elem_value *ucontrol)
702{
703 msm_slim_3_rx_ch = ucontrol->value.integer.value[0] + 1;
704
705 pr_debug("%s: msm_slim_3_rx_ch = %d\n", __func__,
706 msm_slim_3_rx_ch);
707 return 1;
708}
709
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800710static int msm_btsco_rate_get(struct snd_kcontrol *kcontrol,
711 struct snd_ctl_elem_value *ucontrol)
712{
713 pr_debug("%s: msm_btsco_rate = %d", __func__,
714 msm_btsco_rate);
715 ucontrol->value.integer.value[0] = msm_btsco_rate;
716 return 0;
717}
718
719static int msm_btsco_rate_put(struct snd_kcontrol *kcontrol,
720 struct snd_ctl_elem_value *ucontrol)
721{
722 switch (ucontrol->value.integer.value[0]) {
723 case 0:
724 msm_btsco_rate = BTSCO_RATE_8KHZ;
725 break;
726 case 1:
727 msm_btsco_rate = BTSCO_RATE_16KHZ;
728 break;
729 default:
730 msm_btsco_rate = BTSCO_RATE_8KHZ;
731 break;
732 }
733 pr_debug("%s: msm_btsco_rate = %d\n", __func__,
734 msm_btsco_rate);
735 return 0;
736}
737
Helen Zeng8f925502012-03-05 16:50:17 -0800738static int msm_incall_rec_mode_get(struct snd_kcontrol *kcontrol,
739 struct snd_ctl_elem_value *ucontrol)
740{
741 ucontrol->value.integer.value[0] = rec_mode;
742 return 0;
743}
744
745static int msm_incall_rec_mode_put(struct snd_kcontrol *kcontrol,
746 struct snd_ctl_elem_value *ucontrol)
747{
748
749 rec_mode = ucontrol->value.integer.value[0];
750 pr_debug("%s: rec_mode:%d\n", __func__, rec_mode);
751
752 return 0;
753}
754
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800755static const struct snd_kcontrol_new tabla_msm_controls[] = {
756 SOC_ENUM_EXT("Speaker Function", msm_enum[0], msm_get_spk,
757 msm_set_spk),
758 SOC_ENUM_EXT("SLIM_0_RX Channels", msm_enum[1],
759 msm_slim_0_rx_ch_get, msm_slim_0_rx_ch_put),
760 SOC_ENUM_EXT("SLIM_0_TX Channels", msm_enum[2],
761 msm_slim_0_tx_ch_get, msm_slim_0_tx_ch_put),
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -0800762 SOC_ENUM_EXT("Internal BTSCO SampleRate", msm_btsco_enum[0],
763 msm_btsco_rate_get, msm_btsco_rate_put),
Steve Mucklef132c6c2012-06-06 18:30:57 -0700764 SOC_SINGLE_EXT("Incall Rec Mode", SND_SOC_NOPM, 0, 1, 0,
Helen Zeng8f925502012-03-05 16:50:17 -0800765 msm_incall_rec_mode_get, msm_incall_rec_mode_put),
Neema Shetty74131ac2012-05-09 13:35:26 -0700766 SOC_ENUM_EXT("SLIM_3_RX Channels", msm_enum[1],
767 msm_slim_3_rx_ch_get, msm_slim_3_rx_ch_put),
768};
769
Joonwoo Park0976d012011-12-22 11:48:18 -0800770static void *def_tabla_mbhc_cal(void)
771{
772 void *tabla_cal;
773 struct tabla_mbhc_btn_detect_cfg *btn_cfg;
774 u16 *btn_low, *btn_high;
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800775 u8 *n_ready, *n_cic, *gain;
Joonwoo Park0976d012011-12-22 11:48:18 -0800776
777 tabla_cal = kzalloc(TABLA_MBHC_CAL_SIZE(TABLA_MBHC_DEF_BUTTONS,
778 TABLA_MBHC_DEF_RLOADS),
779 GFP_KERNEL);
780 if (!tabla_cal) {
781 pr_err("%s: out of memory\n", __func__);
782 return NULL;
783 }
784
785#define S(X, Y) ((TABLA_MBHC_CAL_GENERAL_PTR(tabla_cal)->X) = (Y))
786 S(t_ldoh, 100);
787 S(t_bg_fast_settle, 100);
788 S(t_shutdown_plug_rem, 255);
789 S(mbhc_nsa, 4);
790 S(mbhc_navg, 4);
791#undef S
792#define S(X, Y) ((TABLA_MBHC_CAL_PLUG_DET_PTR(tabla_cal)->X) = (Y))
793 S(mic_current, TABLA_PID_MIC_5_UA);
794 S(hph_current, TABLA_PID_MIC_5_UA);
795 S(t_mic_pid, 100);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800796 S(t_ins_complete, 250);
Joonwoo Park0976d012011-12-22 11:48:18 -0800797 S(t_ins_retry, 200);
798#undef S
799#define S(X, Y) ((TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla_cal)->X) = (Y))
800 S(v_no_mic, 30);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800801 S(v_hs_max, 1550);
Joonwoo Park0976d012011-12-22 11:48:18 -0800802#undef S
803#define S(X, Y) ((TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal)->X) = (Y))
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800804 S(c[0], 62);
805 S(c[1], 124);
806 S(nc, 1);
807 S(n_meas, 3);
Joonwoo Park0976d012011-12-22 11:48:18 -0800808 S(mbhc_nsc, 11);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800809 S(n_btn_meas, 1);
810 S(n_btn_con, 2);
Joonwoo Park0976d012011-12-22 11:48:18 -0800811 S(num_btn, TABLA_MBHC_DEF_BUTTONS);
812 S(v_btn_press_delta_sta, 100);
813 S(v_btn_press_delta_cic, 50);
814#undef S
815 btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal);
816 btn_low = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_LOW);
817 btn_high = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_HIGH);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800818 btn_low[0] = -50;
819 btn_high[0] = 10;
820 btn_low[1] = 11;
821 btn_high[1] = 38;
822 btn_low[2] = 39;
823 btn_high[2] = 64;
824 btn_low[3] = 65;
825 btn_high[3] = 91;
826 btn_low[4] = 92;
827 btn_high[4] = 115;
828 btn_low[5] = 116;
829 btn_high[5] = 141;
830 btn_low[6] = 142;
831 btn_high[6] = 163;
832 btn_low[7] = 164;
833 btn_high[7] = 250;
834 n_ready = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_READY);
835 n_ready[0] = 48;
836 n_ready[1] = 38;
Joonwoo Park0976d012011-12-22 11:48:18 -0800837 n_cic = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_CIC);
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -0800838 n_cic[0] = 60;
839 n_cic[1] = 47;
Joonwoo Park0976d012011-12-22 11:48:18 -0800840 gain = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_GAIN);
841 gain[0] = 11;
842 gain[1] = 9;
843
844 return tabla_cal;
845}
846
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800847static int msm_hw_params(struct snd_pcm_substream *substream,
848 struct snd_pcm_hw_params *params)
849{
850 struct snd_soc_pcm_runtime *rtd = substream->private_data;
851 struct snd_soc_dai *codec_dai = rtd->codec_dai;
852 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
853 int ret = 0;
854 unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
855 unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700856 unsigned int num_tx_ch = 0;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800857
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700858
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800859 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700860
861 pr_debug("%s: rx_0_ch=%d\n", __func__, msm_slim_0_rx_ch);
862
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800863 ret = snd_soc_dai_get_channel_map(codec_dai,
864 &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
865 if (ret < 0) {
866 pr_err("%s: failed to get codec chan map\n", __func__);
867 goto end;
868 }
869
870 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
871 msm_slim_0_rx_ch, rx_ch);
872 if (ret < 0) {
873 pr_err("%s: failed to set cpu chan map\n", __func__);
874 goto end;
875 }
876 ret = snd_soc_dai_set_channel_map(codec_dai, 0, 0,
877 msm_slim_0_rx_ch, rx_ch);
878 if (ret < 0) {
879 pr_err("%s: failed to set codec channel map\n",
880 __func__);
881 goto end;
882 }
883 } else {
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700884
885 if (codec_dai->id == 2)
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700886 num_tx_ch = msm_slim_0_tx_ch;
Neema Shettye5cae8e2012-04-27 18:07:37 -0700887 else if (codec_dai->id == 5) {
888 /* DAI 5 is used for external EC reference from codec.
889 * Since Rx is fed as reference for EC, the config of
890 * this DAI is based on that of the Rx path.
891 */
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700892 num_tx_ch = msm_slim_0_rx_ch;
Neema Shettye5cae8e2012-04-27 18:07:37 -0700893 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700894
895 pr_debug("%s: %s_tx_dai_id_%d_ch=%d\n", __func__,
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700896 codec_dai->name, codec_dai->id, num_tx_ch);
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700897
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800898 ret = snd_soc_dai_get_channel_map(codec_dai,
899 &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
900 if (ret < 0) {
901 pr_err("%s: failed to get codec chan map\n", __func__);
902 goto end;
903 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700904
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800905 ret = snd_soc_dai_set_channel_map(cpu_dai,
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700906 num_tx_ch, tx_ch, 0 , 0);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800907 if (ret < 0) {
908 pr_err("%s: failed to set cpu chan map\n", __func__);
909 goto end;
910 }
911 ret = snd_soc_dai_set_channel_map(codec_dai,
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700912 num_tx_ch, tx_ch, 0, 0);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800913 if (ret < 0) {
914 pr_err("%s: failed to set codec channel map\n",
915 __func__);
916 goto end;
917 }
918
919
920 }
921end:
922 return ret;
923}
924
Helen Zengf3b17fb2012-02-28 15:07:38 -0800925static int msm_stubrx_init(struct snd_soc_pcm_runtime *rtd)
926{
927 rtd->pmdown_time = 0;
928
929 return 0;
930}
931
Kiran Kandi97fe19d2012-05-20 22:34:04 -0700932static int msm_slimbus_2_hw_params(struct snd_pcm_substream *substream,
933 struct snd_pcm_hw_params *params)
934{
935 struct snd_soc_pcm_runtime *rtd = substream->private_data;
936 struct snd_soc_dai *codec_dai = rtd->codec_dai;
937 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
938 int ret = 0;
939 unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
940 unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
941 unsigned int num_tx_ch = 0;
942 unsigned int num_rx_ch = 0;
943
944 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
945
946 num_rx_ch = params_channels(params);
947
948 pr_debug("%s: %s rx_dai_id = %d num_ch = %d\n", __func__,
949 codec_dai->name, codec_dai->id, num_rx_ch);
950
951 ret = snd_soc_dai_get_channel_map(codec_dai,
952 &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
953 if (ret < 0) {
954 pr_err("%s: failed to get codec chan map\n", __func__);
955 goto end;
956 }
957
958 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
959 num_rx_ch, rx_ch);
960 if (ret < 0) {
961 pr_err("%s: failed to set cpu chan map\n", __func__);
962 goto end;
963 }
964 ret = snd_soc_dai_set_channel_map(codec_dai, 0, 0,
965 num_rx_ch, rx_ch);
966 if (ret < 0) {
967 pr_err("%s: failed to set codec channel map\n",
968 __func__);
969 goto end;
970 }
971 } else {
972
973 num_tx_ch = params_channels(params);
974
975 pr_debug("%s: %s tx_dai_id = %d num_ch = %d\n", __func__,
976 codec_dai->name, codec_dai->id, num_tx_ch);
977
978 ret = snd_soc_dai_get_channel_map(codec_dai,
979 &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
980 if (ret < 0) {
981 pr_err("%s: failed to get codec chan map\n", __func__);
982 goto end;
983 }
984
985 ret = snd_soc_dai_set_channel_map(cpu_dai,
986 num_tx_ch, tx_ch, 0 , 0);
987 if (ret < 0) {
988 pr_err("%s: failed to set cpu chan map\n", __func__);
989 goto end;
990 }
991 ret = snd_soc_dai_set_channel_map(codec_dai,
992 num_tx_ch, tx_ch, 0, 0);
993 if (ret < 0) {
994 pr_err("%s: failed to set codec channel map\n",
995 __func__);
996 goto end;
997 }
998 }
999end:
1000 return ret;
1001}
1002
Neema Shetty3c9d2862012-03-11 01:25:32 -08001003static int msm_slimbus_1_hw_params(struct snd_pcm_substream *substream,
1004 struct snd_pcm_hw_params *params)
1005{
1006 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1007 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1008 int ret = 0;
1009 unsigned int rx_ch = SLIM_1_RX_1, tx_ch = SLIM_1_TX_1;
1010
1011 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1012 pr_debug("%s: APQ BT/USB TX -> SLIMBUS_1_RX -> MDM TX shared ch %d\n",
1013 __func__, rx_ch);
1014
1015 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0, 1, &rx_ch);
1016 if (ret < 0) {
1017 pr_err("%s: Erorr %d setting SLIM_1 RX channel map\n",
1018 __func__, ret);
1019
1020 goto end;
1021 }
1022 } else {
1023 pr_debug("%s: MDM RX -> SLIMBUS_1_TX -> APQ BT/USB Rx shared ch %d\n",
1024 __func__, tx_ch);
1025
1026 ret = snd_soc_dai_set_channel_map(cpu_dai, 1, &tx_ch, 0, 0);
1027 if (ret < 0) {
1028 pr_err("%s: Erorr %d setting SLIM_1 TX channel map\n",
1029 __func__, ret);
1030
1031 goto end;
1032 }
1033 }
1034
1035end:
1036 return ret;
1037}
1038
Neema Shetty74131ac2012-05-09 13:35:26 -07001039static int msm_slimbus_3_hw_params(struct snd_pcm_substream *substream,
1040 struct snd_pcm_hw_params *params)
1041{
1042 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1043 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1044 int ret = 0;
1045 unsigned int rx_ch[2] = {SLIM_3_RX_1, SLIM_3_RX_2};
Helen Zeng38c3c962012-05-17 14:56:20 -07001046 unsigned int tx_ch[2] = {SLIM_3_TX_1, SLIM_3_TX_2};
Neema Shetty74131ac2012-05-09 13:35:26 -07001047
1048 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1049 pr_debug("%s: slim_3_rx_ch %d, sch %d %d\n",
1050 __func__, msm_slim_3_rx_ch,
1051 rx_ch[0], rx_ch[1]);
1052
1053 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
1054 msm_slim_3_rx_ch, rx_ch);
1055 if (ret < 0) {
1056 pr_err("%s: Erorr %d setting SLIM_3 RX channel map\n",
1057 __func__, ret);
1058
1059 goto end;
1060 }
1061 } else {
Helen Zeng38c3c962012-05-17 14:56:20 -07001062 pr_debug("%s: MDM RX -> SLIMBUS_3_TX -> APQ HDMI ch: %d, %d\n",
1063 __func__, tx_ch[0], tx_ch[1]);
1064
1065 ret = snd_soc_dai_set_channel_map(cpu_dai, 2, tx_ch, 0, 0);
1066 if (ret < 0) {
1067 pr_err("%s: Erorr %d setting SLIM_3 TX channel map\n",
1068 __func__, ret);
1069
1070 goto end;
1071 }
Neema Shetty74131ac2012-05-09 13:35:26 -07001072 }
1073
1074end:
1075 return ret;
1076}
1077
Helen Zeng8f925502012-03-05 16:50:17 -08001078static int msm_slimbus_4_hw_params(struct snd_pcm_substream *substream,
1079 struct snd_pcm_hw_params *params)
1080{
1081 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1082 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1083 int ret = 0;
1084 unsigned int rx_ch = SLIM_4_RX_1, tx_ch[2];
1085
1086 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1087 pr_debug("%s: APQ Incall Playback SLIMBUS_4_RX -> MDM TX shared ch %d\n",
1088 __func__, rx_ch);
1089
1090 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0, 1, &rx_ch);
1091 if (ret < 0) {
1092 pr_err("%s: Erorr %d setting SLIM_4 RX channel map\n",
1093 __func__, ret);
1094
1095 }
1096 } else {
1097 if (rec_mode == INCALL_REC_STEREO) {
1098 tx_ch[0] = SLIM_4_TX_1;
1099 tx_ch[1] = SLIM_4_TX_2;
1100 ret = snd_soc_dai_set_channel_map(cpu_dai, 2,
1101 tx_ch, 0, 0);
1102 } else {
1103 tx_ch[0] = SLIM_4_TX_1;
1104 ret = snd_soc_dai_set_channel_map(cpu_dai, 1,
1105 tx_ch, 0, 0);
1106 }
1107 pr_debug("%s: Incall Record shared tx_ch[0]:%d, tx_ch[1]:%d\n",
1108 __func__, tx_ch[0], tx_ch[1]);
1109
1110 if (ret < 0) {
1111 pr_err("%s: Erorr %d setting SLIM_4 TX channel map\n",
1112 __func__, ret);
1113
1114 }
1115 }
1116
1117 return ret;
1118}
1119
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001120static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
1121{
1122 int err;
Joonwoo Park26998702012-05-09 10:10:06 -07001123 uint32_t revision;
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001124 struct snd_soc_codec *codec = rtd->codec;
1125 struct snd_soc_dapm_context *dapm = &codec->dapm;
Kuirong Wanga9c3acc2012-02-09 17:00:45 -08001126 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001127
Kuirong Wanga9c3acc2012-02-09 17:00:45 -08001128 pr_debug("%s(), dev_name%s\n", __func__, dev_name(cpu_dai->dev));
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001129
1130 /*if (machine_is_msm_liquid()) {
1131 top_spk_pamp_gpio = (PM8921_GPIO_PM_TO_SYS(19));
1132 bottom_spk_pamp_gpio = (PM8921_GPIO_PM_TO_SYS(18));
1133 }*/
1134
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001135 snd_soc_dapm_new_controls(dapm, apq8064_dapm_widgets,
1136 ARRAY_SIZE(apq8064_dapm_widgets));
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001137
Kiran Kandi323d7102012-04-18 19:56:14 -07001138 snd_soc_dapm_add_routes(dapm, apq8064_common_audio_map,
1139 ARRAY_SIZE(apq8064_common_audio_map));
1140
1141 if (machine_is_apq8064_mtp()) {
1142 snd_soc_dapm_add_routes(dapm, apq8064_mtp_audio_map,
1143 ARRAY_SIZE(apq8064_mtp_audio_map));
1144 } else {
1145 snd_soc_dapm_add_routes(dapm, apq8064_liquid_cdp_audio_map,
1146 ARRAY_SIZE(apq8064_liquid_cdp_audio_map));
1147 }
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001148
1149 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos");
1150 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg");
1151 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos");
1152 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg");
1153
1154 snd_soc_dapm_sync(dapm);
1155
1156 err = snd_soc_jack_new(codec, "Headset Jack",
1157 (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR),
1158 &hs_jack);
1159 if (err) {
1160 pr_err("failed to create new jack\n");
1161 return err;
1162 }
1163
1164 err = snd_soc_jack_new(codec, "Button Jack",
Swaminathan Sathappan4ea7f1a02012-02-29 12:55:55 -08001165 TABLA_JACK_BUTTON_MASK, &button_jack);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001166 if (err) {
1167 pr_err("failed to create new jack\n");
1168 return err;
1169 }
1170
Kuirong Wanga9c3acc2012-02-09 17:00:45 -08001171 codec_clk = clk_get(cpu_dai->dev, "osr_clk");
1172
Joonwoo Park26998702012-05-09 10:10:06 -07001173 /* APQ8064 Rev 1.1 CDP and Liquid have mechanical switch */
1174 revision = socinfo_get_version();
1175 if (apq8064_hs_detect_use_gpio != -1) {
1176 if (apq8064_hs_detect_use_gpio == 1)
1177 pr_debug("%s: MBHC mechanical is enabled by request\n",
1178 __func__);
1179 else if (apq8064_hs_detect_use_gpio == 0)
1180 pr_debug("%s: MBHC mechanical is disabled by request\n",
1181 __func__);
1182 else
1183 pr_warn("%s: Invalid hs_detect_use_gpio %d\n", __func__,
1184 apq8064_hs_detect_use_gpio);
1185 } else if (SOCINFO_VERSION_MAJOR(revision) == 0) {
1186 pr_warn("%s: Unknown HW revision detected %d.%d\n", __func__,
1187 SOCINFO_VERSION_MAJOR(revision),
1188 SOCINFO_VERSION_MINOR(revision));
1189 } else if ((SOCINFO_VERSION_MAJOR(revision) == 1 &&
1190 SOCINFO_VERSION_MINOR(revision) >= 1 &&
1191 (machine_is_apq8064_cdp() ||
1192 machine_is_apq8064_liquid())) ||
1193 SOCINFO_VERSION_MAJOR(revision) > 1) {
1194 pr_debug("%s: MBHC mechanical switch available APQ8064 "
1195 "detected\n", __func__);
1196 apq8064_hs_detect_use_gpio = 1;
1197 }
1198
1199 if (apq8064_hs_detect_use_gpio == 1) {
1200 pr_debug("%s: Using MBHC mechanical switch\n", __func__);
Joonwoo Parkca1516f2012-05-08 13:59:37 -07001201 mbhc_cfg.gpio = JACK_DETECT_GPIO;
1202 mbhc_cfg.gpio_irq = gpio_to_irq(JACK_DETECT_GPIO);
1203 err = gpio_request(mbhc_cfg.gpio, "MBHC_HS_DETECT");
1204 if (err < 0) {
1205 pr_err("%s: gpio_request %d failed %d\n", __func__,
1206 mbhc_cfg.gpio, err);
1207 return err;
1208 }
1209 gpio_direction_input(JACK_DETECT_GPIO);
Joonwoo Park26998702012-05-09 10:10:06 -07001210 } else
1211 pr_debug("%s: Not using MBHC mechanical switch\n", __func__);
1212
1213 mbhc_cfg.read_fw_bin = apq8064_hs_detect_use_firmware;
Joonwoo Parkca1516f2012-05-08 13:59:37 -07001214
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001215 err = tabla_hs_detect(codec, &mbhc_cfg);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001216
Joonwoo Park03324832012-03-19 19:36:16 -07001217 return err;
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001218}
1219
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001220static int msm_slim_0_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1221 struct snd_pcm_hw_params *params)
1222{
1223 struct snd_interval *rate = hw_param_interval(params,
1224 SNDRV_PCM_HW_PARAM_RATE);
1225
1226 struct snd_interval *channels = hw_param_interval(params,
1227 SNDRV_PCM_HW_PARAM_CHANNELS);
1228
1229 pr_debug("%s()\n", __func__);
1230 rate->min = rate->max = 48000;
1231 channels->min = channels->max = msm_slim_0_rx_ch;
1232
1233 return 0;
1234}
1235
1236static int msm_slim_0_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1237 struct snd_pcm_hw_params *params)
1238{
1239 struct snd_interval *rate = hw_param_interval(params,
1240 SNDRV_PCM_HW_PARAM_RATE);
1241
1242 struct snd_interval *channels = hw_param_interval(params,
1243 SNDRV_PCM_HW_PARAM_CHANNELS);
1244
1245 pr_debug("%s()\n", __func__);
1246 rate->min = rate->max = 48000;
1247 channels->min = channels->max = msm_slim_0_tx_ch;
1248
1249 return 0;
1250}
1251
Neema Shetty74131ac2012-05-09 13:35:26 -07001252static int msm_slim_3_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1253 struct snd_pcm_hw_params *params)
1254{
1255 struct snd_interval *rate = hw_param_interval(params,
1256 SNDRV_PCM_HW_PARAM_RATE);
1257
1258 struct snd_interval *channels = hw_param_interval(params,
1259 SNDRV_PCM_HW_PARAM_CHANNELS);
1260
1261 pr_debug("%s()\n", __func__);
1262 rate->min = rate->max = 48000;
1263 channels->min = channels->max = msm_slim_3_rx_ch;
1264
1265 return 0;
1266}
1267
Helen Zeng38c3c962012-05-17 14:56:20 -07001268static int msm_slim_3_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1269 struct snd_pcm_hw_params *params)
1270{
1271 struct snd_interval *rate = hw_param_interval(params,
1272 SNDRV_PCM_HW_PARAM_RATE);
1273
1274 struct snd_interval *channels = hw_param_interval(params,
1275 SNDRV_PCM_HW_PARAM_CHANNELS);
1276
1277 pr_debug("%s()\n", __func__);
1278 rate->min = rate->max = 48000;
1279 channels->min = channels->max = 2;
1280
1281 return 0;
1282}
1283
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001284static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1285 struct snd_pcm_hw_params *params)
1286{
1287 struct snd_interval *rate = hw_param_interval(params,
1288 SNDRV_PCM_HW_PARAM_RATE);
1289
1290 pr_debug("%s()\n", __func__);
1291 rate->min = rate->max = 48000;
1292
1293 return 0;
1294}
1295
Swaminathan Sathappanfd9dbad2012-02-15 16:56:44 -08001296static int msm_hdmi_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1297 struct snd_pcm_hw_params *params)
1298{
1299 struct snd_interval *rate = hw_param_interval(params,
1300 SNDRV_PCM_HW_PARAM_RATE);
1301
1302 struct snd_interval *channels = hw_param_interval(params,
1303 SNDRV_PCM_HW_PARAM_CHANNELS);
1304
1305 pr_debug("%s channels->min %u channels->max %u ()\n", __func__,
1306 channels->min, channels->max);
1307
1308 rate->min = rate->max = 48000;
1309
1310 return 0;
1311}
1312
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001313static int msm_btsco_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
1314 struct snd_pcm_hw_params *params)
1315{
1316 struct snd_interval *rate = hw_param_interval(params,
1317 SNDRV_PCM_HW_PARAM_RATE);
1318
1319 struct snd_interval *channels = hw_param_interval(params,
1320 SNDRV_PCM_HW_PARAM_CHANNELS);
1321
1322 rate->min = rate->max = msm_btsco_rate;
1323 channels->min = channels->max = msm_btsco_ch;
1324
1325 return 0;
1326}
1327static int msm_auxpcm_be_params_fixup(struct snd_soc_pcm_runtime *rtd,
1328 struct snd_pcm_hw_params *params)
1329{
1330 struct snd_interval *rate = hw_param_interval(params,
1331 SNDRV_PCM_HW_PARAM_RATE);
1332
1333 struct snd_interval *channels = hw_param_interval(params,
1334 SNDRV_PCM_HW_PARAM_CHANNELS);
1335
1336 /* PCM only supports mono output with 8khz sample rate */
1337 rate->min = rate->max = 8000;
1338 channels->min = channels->max = 1;
1339
1340 return 0;
1341}
Neema Shetty3c9d2862012-03-11 01:25:32 -08001342
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001343static int msm_aux_pcm_get_gpios(void)
1344{
1345 int ret = 0;
1346
1347 pr_debug("%s\n", __func__);
1348
1349 ret = gpio_request(GPIO_AUX_PCM_DOUT, "AUX PCM DOUT");
1350 if (ret < 0) {
1351 pr_err("%s: Failed to request gpio(%d): AUX PCM DOUT",
1352 __func__, GPIO_AUX_PCM_DOUT);
1353 goto fail_dout;
1354 }
1355
1356 ret = gpio_request(GPIO_AUX_PCM_DIN, "AUX PCM DIN");
1357 if (ret < 0) {
1358 pr_err("%s: Failed to request gpio(%d): AUX PCM DIN",
1359 __func__, GPIO_AUX_PCM_DIN);
1360 goto fail_din;
1361 }
1362
1363 ret = gpio_request(GPIO_AUX_PCM_SYNC, "AUX PCM SYNC");
1364 if (ret < 0) {
1365 pr_err("%s: Failed to request gpio(%d): AUX PCM SYNC",
1366 __func__, GPIO_AUX_PCM_SYNC);
1367 goto fail_sync;
1368 }
1369 ret = gpio_request(GPIO_AUX_PCM_CLK, "AUX PCM CLK");
1370 if (ret < 0) {
1371 pr_err("%s: Failed to request gpio(%d): AUX PCM CLK",
1372 __func__, GPIO_AUX_PCM_CLK);
1373 goto fail_clk;
1374 }
1375
1376 return 0;
1377
1378fail_clk:
1379 gpio_free(GPIO_AUX_PCM_SYNC);
1380fail_sync:
1381 gpio_free(GPIO_AUX_PCM_DIN);
1382fail_din:
1383 gpio_free(GPIO_AUX_PCM_DOUT);
1384fail_dout:
1385
1386 return ret;
1387}
1388
1389static int msm_aux_pcm_free_gpios(void)
1390{
1391 gpio_free(GPIO_AUX_PCM_DIN);
1392 gpio_free(GPIO_AUX_PCM_DOUT);
1393 gpio_free(GPIO_AUX_PCM_SYNC);
1394 gpio_free(GPIO_AUX_PCM_CLK);
1395
1396 return 0;
1397}
1398static int msm_startup(struct snd_pcm_substream *substream)
1399{
Kiran Kandi97fe19d2012-05-20 22:34:04 -07001400 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1401
1402 pr_debug("%s(): dai_link_str_name = %s cpu_dai = %s codec_dai = %s\n",
1403 __func__, rtd->dai_link->stream_name,
1404 rtd->dai_link->cpu_dai_name,
1405 rtd->dai_link->codec_dai_name);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001406 return 0;
1407}
1408
1409static int msm_auxpcm_startup(struct snd_pcm_substream *substream)
1410{
1411 int ret = 0;
1412
1413 pr_debug("%s(): substream = %s\n", __func__, substream->name);
1414 ret = msm_aux_pcm_get_gpios();
1415 if (ret < 0) {
1416 pr_err("%s: Aux PCM GPIO request failed\n", __func__);
1417 return -EINVAL;
1418 }
1419 return 0;
1420}
1421
Neema Shettya58b9a22012-06-18 19:03:23 -07001422static int msm_slimbus_1_startup(struct snd_pcm_substream *substream)
1423{
1424 struct slim_controller *slim = slim_busnum_to_ctrl(1);
1425
1426 pr_debug("%s(): substream = %s stream = %d\n", __func__,
1427 substream->name, substream->stream);
1428
1429 if (slim != NULL)
1430 pm_runtime_get_sync(slim->dev.parent);
1431
1432 return 0;
1433}
1434
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001435static void msm_auxpcm_shutdown(struct snd_pcm_substream *substream)
1436{
1437
1438 pr_debug("%s(): substream = %s\n", __func__, substream->name);
1439 msm_aux_pcm_free_gpios();
1440}
1441
1442static void msm_shutdown(struct snd_pcm_substream *substream)
1443{
Kiran Kandi97fe19d2012-05-20 22:34:04 -07001444 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1445
1446 pr_debug("%s(): dai_link_str_name = %s cpu_dai = %s codec_dai = %s\n",
1447 __func__, rtd->dai_link->stream_name,
1448 rtd->dai_link->cpu_dai_name, rtd->dai_link->codec_dai_name);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001449}
1450
Neema Shettya58b9a22012-06-18 19:03:23 -07001451static void msm_slimbus_1_shutdown(struct snd_pcm_substream *substream)
1452{
1453 struct slim_controller *slim = slim_busnum_to_ctrl(1);
1454
1455 pr_debug("%s(): substream = %s stream = %d\n", __func__,
1456 substream->name, substream->stream);
1457
1458 if (slim != NULL) {
1459 pm_runtime_mark_last_busy(slim->dev.parent);
1460 pm_runtime_put(slim->dev.parent);
1461 }
1462}
1463
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001464static struct snd_soc_ops msm_be_ops = {
1465 .startup = msm_startup,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08001466 .hw_params = msm_hw_params,
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001467 .shutdown = msm_shutdown,
1468};
1469
1470static struct snd_soc_ops msm_auxpcm_be_ops = {
1471 .startup = msm_auxpcm_startup,
1472 .shutdown = msm_auxpcm_shutdown,
1473};
1474
Neema Shetty3c9d2862012-03-11 01:25:32 -08001475static struct snd_soc_ops msm_slimbus_1_be_ops = {
Neema Shettya58b9a22012-06-18 19:03:23 -07001476 .startup = msm_slimbus_1_startup,
Neema Shetty3c9d2862012-03-11 01:25:32 -08001477 .hw_params = msm_slimbus_1_hw_params,
Neema Shettya58b9a22012-06-18 19:03:23 -07001478 .shutdown = msm_slimbus_1_shutdown,
Neema Shetty3c9d2862012-03-11 01:25:32 -08001479};
1480
Neema Shetty74131ac2012-05-09 13:35:26 -07001481static struct snd_soc_ops msm_slimbus_3_be_ops = {
1482 .startup = msm_startup,
1483 .hw_params = msm_slimbus_3_hw_params,
1484 .shutdown = msm_shutdown,
1485};
1486
Helen Zeng8f925502012-03-05 16:50:17 -08001487static struct snd_soc_ops msm_slimbus_4_be_ops = {
1488 .startup = msm_startup,
1489 .hw_params = msm_slimbus_4_hw_params,
1490 .shutdown = msm_shutdown,
1491};
1492
Kiran Kandi97fe19d2012-05-20 22:34:04 -07001493static struct snd_soc_ops msm_slimbus_2_be_ops = {
1494 .startup = msm_startup,
1495 .hw_params = msm_slimbus_2_hw_params,
1496 .shutdown = msm_shutdown,
1497};
1498
1499
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001500/* Digital audio interface glue - connects codec <---> CPU */
1501static struct snd_soc_dai_link msm_dai[] = {
1502 /* FrontEnd DAI Links */
1503 {
1504 .name = "MSM8960 Media1",
1505 .stream_name = "MultiMedia1",
1506 .cpu_dai_name = "MultiMedia1",
1507 .platform_name = "msm-pcm-dsp",
1508 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001509 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
1510 .codec_dai_name = "snd-soc-dummy-dai",
1511 .codec_name = "snd-soc-dummy",
1512 .ignore_suspend = 1,
1513 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001514 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA1
1515 },
1516 {
1517 .name = "MSM8960 Media2",
1518 .stream_name = "MultiMedia2",
1519 .cpu_dai_name = "MultiMedia2",
Bharath Ramachandramurthyf79f92b2012-03-29 12:11:54 -07001520 .platform_name = "msm-multi-ch-pcm-dsp",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001521 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001522 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
1523 .codec_dai_name = "snd-soc-dummy-dai",
1524 .codec_name = "snd-soc-dummy",
1525 .ignore_suspend = 1,
1526 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001527 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA2,
1528 },
1529 {
1530 .name = "Circuit-Switch Voice",
1531 .stream_name = "CS-Voice",
1532 .cpu_dai_name = "CS-VOICE",
1533 .platform_name = "msm-pcm-voice",
1534 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001535 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001536 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1537 .ignore_suspend = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001538 .codec_dai_name = "snd-soc-dummy-dai",
1539 .codec_name = "snd-soc-dummy",
1540 .ignore_suspend = 1,
1541 .ignore_pmdown_time = 1, /* this dainlink has playback support */
1542 .be_id = MSM_FRONTEND_DAI_CS_VOICE,
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001543 },
1544 {
1545 .name = "MSM VoIP",
1546 .stream_name = "VoIP",
1547 .cpu_dai_name = "VoIP",
1548 .platform_name = "msm-voip-dsp",
1549 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001550 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
1551 .codec_dai_name = "snd-soc-dummy-dai",
1552 .codec_name = "snd-soc-dummy",
1553 .ignore_suspend = 1,
1554 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001555 .be_id = MSM_FRONTEND_DAI_VOIP,
1556 },
1557 {
1558 .name = "MSM8960 LPA",
1559 .stream_name = "LPA",
1560 .cpu_dai_name = "MultiMedia3",
1561 .platform_name = "msm-pcm-lpa",
1562 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001563 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
1564 .codec_dai_name = "snd-soc-dummy-dai",
1565 .codec_name = "snd-soc-dummy",
1566 .ignore_suspend = 1,
1567 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001568 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA3,
1569 },
1570 /* Hostless PMC purpose */
1571 {
1572 .name = "SLIMBUS_0 Hostless",
1573 .stream_name = "SLIMBUS_0 Hostless",
1574 .cpu_dai_name = "SLIMBUS0_HOSTLESS",
1575 .platform_name = "msm-pcm-hostless",
1576 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001577 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001578 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1579 .ignore_suspend = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001580 .ignore_pmdown_time = 1, /* this dainlink has playback support */
1581 .codec_dai_name = "snd-soc-dummy-dai",
1582 .codec_name = "snd-soc-dummy",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001583 /* .be_id = do not care */
1584 },
1585 {
1586 .name = "INT_FM Hostless",
1587 .stream_name = "INT_FM Hostless",
1588 .cpu_dai_name = "INT_FM_HOSTLESS",
1589 .platform_name = "msm-pcm-hostless",
1590 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001591 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001592 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1593 .ignore_suspend = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001594 .ignore_pmdown_time = 1, /* this dainlink has playback support */
1595 .codec_dai_name = "snd-soc-dummy-dai",
1596 .codec_name = "snd-soc-dummy",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001597 /* .be_id = do not care */
1598 },
1599 {
1600 .name = "MSM AFE-PCM RX",
1601 .stream_name = "AFE-PROXY RX",
1602 .cpu_dai_name = "msm-dai-q6.241",
1603 .codec_name = "msm-stub-codec.1",
1604 .codec_dai_name = "msm-stub-rx",
1605 .platform_name = "msm-pcm-afe",
1606 .ignore_suspend = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001607 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001608 },
1609 {
1610 .name = "MSM AFE-PCM TX",
1611 .stream_name = "AFE-PROXY TX",
1612 .cpu_dai_name = "msm-dai-q6.240",
1613 .codec_name = "msm-stub-codec.1",
1614 .codec_dai_name = "msm-stub-tx",
1615 .platform_name = "msm-pcm-afe",
1616 .ignore_suspend = 1,
1617 },
Neema Shettyb9451242012-02-16 15:37:59 -08001618 {
Bharath Ramachandramurthyf79f92b2012-03-29 12:11:54 -07001619 .name = "MSM8960 Compr",
1620 .stream_name = "COMPR",
1621 .cpu_dai_name = "MultiMedia4",
1622 .platform_name = "msm-compr-dsp",
1623 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001624 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
1625 .codec_dai_name = "snd-soc-dummy-dai",
1626 .codec_name = "snd-soc-dummy",
1627 .ignore_suspend = 1,
1628 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyf79f92b2012-03-29 12:11:54 -07001629 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA4,
1630 },
1631 {
1632 .name = "AUXPCM Hostless",
1633 .stream_name = "AUXPCM Hostless",
1634 .cpu_dai_name = "AUXPCM_HOSTLESS",
1635 .platform_name = "msm-pcm-hostless",
1636 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001637 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
Bharath Ramachandramurthyf79f92b2012-03-29 12:11:54 -07001638 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1639 .ignore_suspend = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001640 .ignore_pmdown_time = 1, /* this dainlink has playback support */
1641 .codec_dai_name = "snd-soc-dummy-dai",
1642 .codec_name = "snd-soc-dummy",
Bharath Ramachandramurthyf79f92b2012-03-29 12:11:54 -07001643 },
1644 /* HDMI Hostless */
1645 {
1646 .name = "HDMI_RX_HOSTLESS",
1647 .stream_name = "HDMI_RX_HOSTLESS",
1648 .cpu_dai_name = "HDMI_HOSTLESS",
1649 .platform_name = "msm-pcm-hostless",
1650 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001651 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
Bharath Ramachandramurthyf79f92b2012-03-29 12:11:54 -07001652 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001653 .codec_dai_name = "snd-soc-dummy-dai",
1654 .codec_name = "snd-soc-dummy",
Bharath Ramachandramurthyf79f92b2012-03-29 12:11:54 -07001655 .ignore_suspend = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001656 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyf79f92b2012-03-29 12:11:54 -07001657 },
1658 {
Neema Shettyb9451242012-02-16 15:37:59 -08001659 .name = "Voice Stub",
1660 .stream_name = "Voice Stub",
1661 .cpu_dai_name = "VOICE_STUB",
1662 .platform_name = "msm-pcm-hostless",
1663 .dynamic = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001664 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
Neema Shettyb9451242012-02-16 15:37:59 -08001665 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1666 .ignore_suspend = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001667 .ignore_pmdown_time = 1, /* this dainlink has playback support */
1668 .codec_dai_name = "snd-soc-dummy-dai",
1669 .codec_name = "snd-soc-dummy",
Neema Shettyb9451242012-02-16 15:37:59 -08001670 },
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001671 /* Backend DAI Links */
1672 {
1673 .name = LPASS_BE_SLIMBUS_0_RX,
1674 .stream_name = "Slimbus Playback",
1675 .cpu_dai_name = "msm-dai-q6.16384",
1676 .platform_name = "msm-pcm-routing",
1677 .codec_name = "tabla_codec",
1678 .codec_dai_name = "tabla_rx1",
1679 .no_pcm = 1,
1680 .be_id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
1681 .init = &msm_audrx_init,
1682 .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
1683 .ops = &msm_be_ops,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001684 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001685 },
1686 {
1687 .name = LPASS_BE_SLIMBUS_0_TX,
1688 .stream_name = "Slimbus Capture",
1689 .cpu_dai_name = "msm-dai-q6.16385",
1690 .platform_name = "msm-pcm-routing",
1691 .codec_name = "tabla_codec",
1692 .codec_dai_name = "tabla_tx1",
1693 .no_pcm = 1,
1694 .be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
1695 .be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
1696 .ops = &msm_be_ops,
1697 },
1698 /* Backend BT/FM DAI Links */
1699 {
1700 .name = LPASS_BE_INT_BT_SCO_RX,
1701 .stream_name = "Internal BT-SCO Playback",
1702 .cpu_dai_name = "msm-dai-q6.12288",
1703 .platform_name = "msm-pcm-routing",
1704 .codec_name = "msm-stub-codec.1",
1705 .codec_dai_name = "msm-stub-rx",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001706 .no_pcm = 1,
1707 .be_id = MSM_BACKEND_DAI_INT_BT_SCO_RX,
1708 .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001709 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001710 },
1711 {
1712 .name = LPASS_BE_INT_BT_SCO_TX,
1713 .stream_name = "Internal BT-SCO Capture",
1714 .cpu_dai_name = "msm-dai-q6.12289",
1715 .platform_name = "msm-pcm-routing",
1716 .codec_name = "msm-stub-codec.1",
1717 .codec_dai_name = "msm-stub-tx",
1718 .no_pcm = 1,
1719 .be_id = MSM_BACKEND_DAI_INT_BT_SCO_TX,
1720 .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
1721 },
1722 {
1723 .name = LPASS_BE_INT_FM_RX,
1724 .stream_name = "Internal FM Playback",
1725 .cpu_dai_name = "msm-dai-q6.12292",
1726 .platform_name = "msm-pcm-routing",
1727 .codec_name = "msm-stub-codec.1",
1728 .codec_dai_name = "msm-stub-rx",
1729 .no_pcm = 1,
1730 .be_id = MSM_BACKEND_DAI_INT_FM_RX,
1731 .be_hw_params_fixup = msm_be_hw_params_fixup,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001732 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001733 },
1734 {
1735 .name = LPASS_BE_INT_FM_TX,
1736 .stream_name = "Internal FM Capture",
1737 .cpu_dai_name = "msm-dai-q6.12293",
1738 .platform_name = "msm-pcm-routing",
1739 .codec_name = "msm-stub-codec.1",
1740 .codec_dai_name = "msm-stub-tx",
1741 .no_pcm = 1,
1742 .be_id = MSM_BACKEND_DAI_INT_FM_TX,
1743 .be_hw_params_fixup = msm_be_hw_params_fixup,
1744 },
1745 /* HDMI BACK END DAI Link */
1746 {
1747 .name = LPASS_BE_HDMI,
1748 .stream_name = "HDMI Playback",
Swaminathan Sathappanfd9dbad2012-02-15 16:56:44 -08001749 .cpu_dai_name = "msm-dai-q6-hdmi.8",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001750 .platform_name = "msm-pcm-routing",
1751 .codec_name = "msm-stub-codec.1",
1752 .codec_dai_name = "msm-stub-rx",
1753 .no_pcm = 1,
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001754 .be_id = MSM_BACKEND_DAI_HDMI_RX,
Swaminathan Sathappanfd9dbad2012-02-15 16:56:44 -08001755 .be_hw_params_fixup = msm_hdmi_be_hw_params_fixup,
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001756 },
1757 /* Backend AFE DAI Links */
1758 {
1759 .name = LPASS_BE_AFE_PCM_RX,
1760 .stream_name = "AFE Playback",
1761 .cpu_dai_name = "msm-dai-q6.224",
1762 .platform_name = "msm-pcm-routing",
1763 .codec_name = "msm-stub-codec.1",
1764 .codec_dai_name = "msm-stub-rx",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001765 .no_pcm = 1,
1766 .be_id = MSM_BACKEND_DAI_AFE_PCM_RX,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001767 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001768 },
1769 {
1770 .name = LPASS_BE_AFE_PCM_TX,
1771 .stream_name = "AFE Capture",
1772 .cpu_dai_name = "msm-dai-q6.225",
1773 .platform_name = "msm-pcm-routing",
1774 .codec_name = "msm-stub-codec.1",
1775 .codec_dai_name = "msm-stub-tx",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001776 .no_pcm = 1,
1777 .be_id = MSM_BACKEND_DAI_AFE_PCM_TX,
1778 },
1779 /* AUX PCM Backend DAI Links */
1780 {
1781 .name = LPASS_BE_AUXPCM_RX,
1782 .stream_name = "AUX PCM Playback",
1783 .cpu_dai_name = "msm-dai-q6.2",
1784 .platform_name = "msm-pcm-routing",
1785 .codec_name = "msm-stub-codec.1",
1786 .codec_dai_name = "msm-stub-rx",
1787 .no_pcm = 1,
1788 .be_id = MSM_BACKEND_DAI_AUXPCM_RX,
1789 .be_hw_params_fixup = msm_auxpcm_be_params_fixup,
1790 .ops = &msm_auxpcm_be_ops,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001791 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001792 },
1793 {
1794 .name = LPASS_BE_AUXPCM_TX,
1795 .stream_name = "AUX PCM Capture",
1796 .cpu_dai_name = "msm-dai-q6.3",
1797 .platform_name = "msm-pcm-routing",
1798 .codec_name = "msm-stub-codec.1",
1799 .codec_dai_name = "msm-stub-tx",
1800 .no_pcm = 1,
1801 .be_id = MSM_BACKEND_DAI_AUXPCM_TX,
1802 .be_hw_params_fixup = msm_auxpcm_be_params_fixup,
1803 },
Neema Shettyb9451242012-02-16 15:37:59 -08001804 {
1805 .name = LPASS_BE_STUB_RX,
1806 .stream_name = "Stub Playback",
1807 .cpu_dai_name = "msm-dai-stub",
1808 .platform_name = "msm-pcm-routing",
1809 .codec_name = "tabla_codec",
1810 .codec_dai_name = "tabla_rx2",
1811 .no_pcm = 1,
Neema Shettye5cae8e2012-04-27 18:07:37 -07001812 .be_id = MSM_BACKEND_DAI_EXTPROC_RX,
Neema Shettyb9451242012-02-16 15:37:59 -08001813 .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
Helen Zengf3b17fb2012-02-28 15:07:38 -08001814 .init = &msm_stubrx_init,
Neema Shettyb9451242012-02-16 15:37:59 -08001815 .ops = &msm_be_ops,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001816 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Neema Shettyb9451242012-02-16 15:37:59 -08001817 },
1818 {
1819 .name = LPASS_BE_STUB_TX,
1820 .stream_name = "Stub Capture",
1821 .cpu_dai_name = "msm-dai-stub",
1822 .platform_name = "msm-pcm-routing",
1823 .codec_name = "tabla_codec",
1824 .codec_dai_name = "tabla_tx1",
1825 .no_pcm = 1,
Neema Shettye5cae8e2012-04-27 18:07:37 -07001826 .be_id = MSM_BACKEND_DAI_EXTPROC_TX,
Neema Shettyb9451242012-02-16 15:37:59 -08001827 .be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
1828 .ops = &msm_be_ops,
1829 },
Neema Shetty3c9d2862012-03-11 01:25:32 -08001830 {
1831 .name = LPASS_BE_SLIMBUS_1_RX,
1832 .stream_name = "Slimbus1 Playback",
1833 .cpu_dai_name = "msm-dai-q6.16386",
1834 .platform_name = "msm-pcm-routing",
1835 .codec_name = "msm-stub-codec.1",
1836 .codec_dai_name = "msm-stub-rx",
1837 .no_pcm = 1,
1838 .be_id = MSM_BACKEND_DAI_SLIMBUS_1_RX,
1839 .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
1840 .ops = &msm_slimbus_1_be_ops,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001841 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Neema Shetty3c9d2862012-03-11 01:25:32 -08001842
1843 },
1844 {
1845 .name = LPASS_BE_SLIMBUS_1_TX,
1846 .stream_name = "Slimbus1 Capture",
1847 .cpu_dai_name = "msm-dai-q6.16387",
1848 .platform_name = "msm-pcm-routing",
1849 .codec_name = "msm-stub-codec.1",
1850 .codec_dai_name = "msm-stub-tx",
1851 .no_pcm = 1,
1852 .be_id = MSM_BACKEND_DAI_SLIMBUS_1_TX,
1853 .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
1854 .ops = &msm_slimbus_1_be_ops,
1855 },
Kiran Kandi97fe19d2012-05-20 22:34:04 -07001856 /* Ultrasound TX Back End DAI Link */
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001857 {
Kiran Kandi97fe19d2012-05-20 22:34:04 -07001858 .name = "SLIMBUS_2 Hostless Capture",
1859 .stream_name = "SLIMBUS_2 Hostless Capture",
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001860 .cpu_dai_name = "msm-dai-q6.16389",
1861 .platform_name = "msm-pcm-hostless",
1862 .codec_name = "tabla_codec",
1863 .codec_dai_name = "tabla_tx2",
Swaminathan Sathappan630c5a42012-05-10 17:33:01 -07001864 .ignore_suspend = 1,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001865 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
Kiran Kandi97fe19d2012-05-20 22:34:04 -07001866 .ops = &msm_slimbus_2_be_ops,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001867 },
Kiran Kandi97fe19d2012-05-20 22:34:04 -07001868 /* Ultrasound RX Back End DAI Link */
1869 {
1870 .name = "SLIMBUS_2 Hostless Playback",
1871 .stream_name = "SLIMBUS_2 Hostless Playback",
1872 .cpu_dai_name = "msm-dai-q6.16388",
1873 .platform_name = "msm-pcm-hostless",
1874 .codec_name = "tabla_codec",
1875 .codec_dai_name = "tabla_rx3",
1876 .ignore_suspend = 1,
1877 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1878 .ops = &msm_slimbus_2_be_ops,
1879 },
Helen Zeng8f925502012-03-05 16:50:17 -08001880 /* Incall Music Back End DAI Link */
1881 {
1882 .name = LPASS_BE_SLIMBUS_4_RX,
1883 .stream_name = "Slimbus4 Playback",
1884 .cpu_dai_name = "msm-dai-q6.16392",
1885 .platform_name = "msm-pcm-routing",
1886 .codec_name = "msm-stub-codec.1",
1887 .codec_dai_name = "msm-stub-rx",
1888 .no_pcm = 1,
Helen Zeng8f925502012-03-05 16:50:17 -08001889 .be_id = MSM_BACKEND_DAI_SLIMBUS_4_RX,
1890 .be_hw_params_fixup = msm_be_hw_params_fixup,
1891 .ops = &msm_slimbus_4_be_ops,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001892 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Helen Zeng8f925502012-03-05 16:50:17 -08001893 },
1894 /* Incall Record Back End DAI Link */
1895 {
1896 .name = LPASS_BE_SLIMBUS_4_TX,
1897 .stream_name = "Slimbus4 Capture",
1898 .cpu_dai_name = "msm-dai-q6.16393",
1899 .platform_name = "msm-pcm-routing",
1900 .codec_name = "msm-stub-codec.1",
1901 .codec_dai_name = "msm-stub-tx",
1902 .no_pcm = 1,
Helen Zeng8f925502012-03-05 16:50:17 -08001903 .be_id = MSM_BACKEND_DAI_SLIMBUS_4_TX,
1904 .be_hw_params_fixup = msm_be_hw_params_fixup,
Helen Zeng8f925502012-03-05 16:50:17 -08001905 .ops = &msm_slimbus_4_be_ops,
1906 },
Neema Shettye5cae8e2012-04-27 18:07:37 -07001907 {
1908 .name = LPASS_BE_STUB_1_TX,
1909 .stream_name = "Stub1 Capture",
1910 .cpu_dai_name = "msm-dai-stub",
1911 .platform_name = "msm-pcm-routing",
1912 .codec_name = "tabla_codec",
1913 .codec_dai_name = "tabla_tx3",
1914 .no_pcm = 1,
1915 .be_id = MSM_BACKEND_DAI_EXTPROC_EC_TX,
1916 /* This BE is used for external EC reference from codec. Since
1917 * Rx is fed as reference for EC, the config of this DAI is
1918 * based on that of the Rx path.
1919 */
1920 .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
1921 .ops = &msm_be_ops,
1922 },
Neema Shetty74131ac2012-05-09 13:35:26 -07001923 {
1924
1925 .name = LPASS_BE_SLIMBUS_3_RX,
1926 .stream_name = "Slimbus3 Playback",
1927 .cpu_dai_name = "msm-dai-q6.16390",
1928 .platform_name = "msm-pcm-routing",
1929 .codec_name = "msm-stub-codec.1",
1930 .codec_dai_name = "msm-stub-rx",
Neema Shetty74131ac2012-05-09 13:35:26 -07001931 .no_pcm = 1,
1932 .be_id = MSM_BACKEND_DAI_SLIMBUS_3_RX,
1933 .be_hw_params_fixup = msm_slim_3_rx_be_hw_params_fixup,
1934 .ops = &msm_slimbus_3_be_ops,
Steve Mucklef132c6c2012-06-06 18:30:57 -07001935 .ignore_pmdown_time = 1, /* this dainlink has playback support */
Neema Shetty74131ac2012-05-09 13:35:26 -07001936 },
Helen Zeng38c3c962012-05-17 14:56:20 -07001937 {
1938 .name = LPASS_BE_SLIMBUS_3_TX,
1939 .stream_name = "Slimbus3 Capture",
1940 .cpu_dai_name = "msm-dai-q6.16391",
1941 .platform_name = "msm-pcm-routing",
1942 .codec_name = "msm-stub-codec.1",
1943 .codec_dai_name = "msm-stub-tx",
1944 .no_pcm = 1,
1945 .be_id = MSM_BACKEND_DAI_SLIMBUS_3_TX,
1946 .be_hw_params_fixup = msm_slim_3_tx_be_hw_params_fixup,
1947 .ops = &msm_slimbus_3_be_ops,
1948 },
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001949};
1950
1951struct snd_soc_card snd_soc_card_msm = {
Swaminathan Sathappanc165a3a2012-02-29 12:44:31 -08001952 .name = "apq8064-tabla-snd-card",
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001953 .dai_link = msm_dai,
1954 .num_links = ARRAY_SIZE(msm_dai),
Steve Mucklef132c6c2012-06-06 18:30:57 -07001955 .controls = tabla_msm_controls,
1956 .num_controls = ARRAY_SIZE(tabla_msm_controls),
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08001957};
1958
1959static struct platform_device *msm_snd_device;
1960
1961static int msm_configure_headset_mic_gpios(void)
1962{
1963 int ret;
1964 struct pm_gpio param = {
1965 .direction = PM_GPIO_DIR_OUT,
1966 .output_buffer = PM_GPIO_OUT_BUF_CMOS,
1967 .output_value = 1,
1968 .pull = PM_GPIO_PULL_NO,
1969 .vin_sel = PM_GPIO_VIN_S4,
1970 .out_strength = PM_GPIO_STRENGTH_MED,
1971 .function = PM_GPIO_FUNC_NORMAL,
1972 };
1973
1974 ret = gpio_request(PM8921_GPIO_PM_TO_SYS(23), "AV_SWITCH");
1975 if (ret) {
1976 pr_err("%s: Failed to request gpio %d\n", __func__,
1977 PM8921_GPIO_PM_TO_SYS(23));
1978 return ret;
1979 }
1980
1981 ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(23), &param);
1982 if (ret)
1983 pr_err("%s: Failed to configure gpio %d\n", __func__,
1984 PM8921_GPIO_PM_TO_SYS(23));
1985 else
1986 gpio_direction_output(PM8921_GPIO_PM_TO_SYS(23), 0);
1987
1988 ret = gpio_request(PM8921_GPIO_PM_TO_SYS(35), "US_EURO_SWITCH");
1989 if (ret) {
1990 pr_err("%s: Failed to request gpio %d\n", __func__,
1991 PM8921_GPIO_PM_TO_SYS(35));
1992 gpio_free(PM8921_GPIO_PM_TO_SYS(23));
1993 return ret;
1994 }
1995 ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(35), &param);
1996 if (ret)
1997 pr_err("%s: Failed to configure gpio %d\n", __func__,
1998 PM8921_GPIO_PM_TO_SYS(35));
1999 else
2000 gpio_direction_output(PM8921_GPIO_PM_TO_SYS(35), 0);
2001
2002 return 0;
2003}
2004static void msm_free_headset_mic_gpios(void)
2005{
2006 if (msm_headset_gpios_configured) {
2007 gpio_free(PM8921_GPIO_PM_TO_SYS(23));
2008 gpio_free(PM8921_GPIO_PM_TO_SYS(35));
2009 }
2010}
2011
2012static int __init msm_audio_init(void)
2013{
2014 int ret;
2015
Santosh Mardi911b27fd2012-04-04 03:09:01 +05302016 if (!cpu_is_apq8064() || (socinfo_get_id() == 130)) {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08002017 pr_err("%s: Not the right machine type\n", __func__);
2018 return -ENODEV;
2019 }
2020
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002021 mbhc_cfg.calibration = def_tabla_mbhc_cal();
2022 if (!mbhc_cfg.calibration) {
Joonwoo Park0976d012011-12-22 11:48:18 -08002023 pr_err("Calibration data allocation failed\n");
2024 return -ENOMEM;
2025 }
2026
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08002027 msm_snd_device = platform_device_alloc("soc-audio", 0);
2028 if (!msm_snd_device) {
2029 pr_err("Platform device allocation failed\n");
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002030 kfree(mbhc_cfg.calibration);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08002031 return -ENOMEM;
2032 }
2033
2034 platform_set_drvdata(msm_snd_device, &snd_soc_card_msm);
2035 ret = platform_device_add(msm_snd_device);
2036 if (ret) {
2037 platform_device_put(msm_snd_device);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002038 kfree(mbhc_cfg.calibration);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08002039 return ret;
2040 }
2041
2042 if (msm_configure_headset_mic_gpios()) {
2043 pr_err("%s Fail to configure headset mic gpios\n", __func__);
2044 msm_headset_gpios_configured = 0;
2045 } else
2046 msm_headset_gpios_configured = 1;
2047
Joonwoo Park9db5fb7a2012-06-15 12:10:46 -07002048 mutex_init(&cdc_mclk_mutex);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08002049 return ret;
2050
2051}
2052module_init(msm_audio_init);
2053
2054static void __exit msm_audio_exit(void)
2055{
Santosh Mardi911b27fd2012-04-04 03:09:01 +05302056 if (!cpu_is_apq8064() || (socinfo_get_id() == 130)) {
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08002057 pr_err("%s: Not the right machine type\n", __func__);
2058 return ;
2059 }
2060 msm_free_headset_mic_gpios();
2061 platform_device_unregister(msm_snd_device);
Joonwoo Parkca1516f2012-05-08 13:59:37 -07002062 if (mbhc_cfg.gpio)
2063 gpio_free(mbhc_cfg.gpio);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002064 kfree(mbhc_cfg.calibration);
Joonwoo Park9db5fb7a2012-06-15 12:10:46 -07002065 mutex_destroy(&cdc_mclk_mutex);
Bharath Ramachandramurthyb8e797f2011-11-30 12:08:42 -08002066}
2067module_exit(msm_audio_exit);
2068
2069MODULE_DESCRIPTION("ALSA SoC msm");
2070MODULE_LICENSE("GPL v2");