blob: ea05a58ebc6b2039d4df31489412f8cb1d240a16 [file] [log] [blame]
Santosh Mardi603fbb92012-03-22 03:45:46 +05301/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/clk.h>
14#include <linux/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>
20#include <linux/slab.h>
21#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 <sound/pcm_params.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 MPQ8064_SPK_ON 1
39#define MPQ8064_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 BOTTOM_SPK_AMP_POS 0x1
45#define BOTTOM_SPK_AMP_NEG 0x2
46#define TOP_SPK_AMP_POS 0x4
47#define TOP_SPK_AMP_NEG 0x8
48
49#define TABLA_EXT_CLK_RATE 12288000
50
51#define TABLA_MBHC_DEF_BUTTONS 8
52#define TABLA_MBHC_DEF_RLOADS 5
53
54#define GPIO_SEC_I2S_RX_SCK 47
55#define GPIO_SEC_I2S_RX_WS 48
56#define GPIO_SEC_I2S_RX_DOUT 49
57#define GPIO_SEC_I2S_RX_MCLK 50
58#define I2S_MCLK_RATE 1536000
59
Kuirong Wang9ddff202012-03-31 14:49:39 -070060#define GPIO_MI2S_WS 27
61#define GPIO_MI2S_SCLK 28
62#define GPIO_MI2S_DOUT3 29
63#define GPIO_MI2S_DOUT2 30
64#define GPIO_MI2S_DOUT1 31
65#define GPIO_MI2S_DOUT0 32
66#define GPIO_MI2S_MCLK 33
67
Santosh Mardi603fbb92012-03-22 03:45:46 +053068static struct clk *sec_i2s_rx_osr_clk;
69static struct clk *sec_i2s_rx_bit_clk;
70
71struct request_gpio {
72 unsigned gpio_no;
73 char *gpio_name;
74};
75
76static struct request_gpio sec_i2s_rx_gpio[] = {
77 {
78 .gpio_no = GPIO_SEC_I2S_RX_MCLK,
79 .gpio_name = "SEC_I2S_RX_MCLK",
80 },
81 {
82 .gpio_no = GPIO_SEC_I2S_RX_SCK,
83 .gpio_name = "SEC_I2S_RX_SCK",
84 },
85 {
86 .gpio_no = GPIO_SEC_I2S_RX_WS,
87 .gpio_name = "SEC_I2S_RX_WS",
88 },
89 {
90 .gpio_no = GPIO_SEC_I2S_RX_DOUT,
91 .gpio_name = "SEC_I2S_RX_DOUT",
92 },
93};
94
Kuirong Wang9ddff202012-03-31 14:49:39 -070095static struct request_gpio mi2s_gpio[] = {
96 {
97 .gpio_no = GPIO_MI2S_WS,
98 .gpio_name = "MI2S_WS",
99 },
100 {
101 .gpio_no = GPIO_MI2S_SCLK,
102 .gpio_name = "MI2S_SCLK",
103 },
104 {
105 .gpio_no = GPIO_MI2S_DOUT3,
106 .gpio_name = "MI2S_DOUT3",
107 },
108 {
109 .gpio_no = GPIO_MI2S_DOUT2,
110 .gpio_name = "MI2S_DOUT2",
111 },
112 {
113 .gpio_no = GPIO_MI2S_DOUT1,
114 .gpio_name = "MI2S_DOUT1",
115 },
116 {
117 .gpio_no = GPIO_MI2S_DOUT0,
118 .gpio_name = "MI2S_DOUT0",
119 },
120 {
121 .gpio_no = GPIO_MI2S_MCLK,
122 .gpio_name = "MI2S_MCLK",
123 },
124};
125
126static struct clk *mi2s_bit_clk;
127
128
129
Santosh Mardi603fbb92012-03-22 03:45:46 +0530130static u32 top_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(18);
131static u32 bottom_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(19);
132static int msm_spk_control;
133static int msm_ext_bottom_spk_pamp;
134static int msm_ext_top_spk_pamp;
135static int msm_slim_0_rx_ch = 1;
136static int msm_slim_0_tx_ch = 1;
137
138static struct clk *codec_clk;
139static int clk_users;
140
141static int msm_headset_gpios_configured;
142
143static struct snd_soc_jack hs_jack;
144static struct snd_soc_jack button_jack;
145
146static int msm_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
147 bool dapm);
148
149static struct tabla_mbhc_config mbhc_cfg = {
150 .headset_jack = &hs_jack,
151 .button_jack = &button_jack,
152 .read_fw_bin = false,
153 .calibration = NULL,
154 .micbias = TABLA_MICBIAS2,
155 .mclk_cb_fn = msm_enable_codec_ext_clk,
156 .mclk_rate = TABLA_EXT_CLK_RATE,
157 .gpio = 0, /* MBHC GPIO is not configured */
158 .gpio_irq = 0,
159 .gpio_level_insert = 1,
160};
161
162static void msm_enable_ext_spk_amp_gpio(u32 spk_amp_gpio)
163{
164 int ret = 0;
165
166 struct pm_gpio param = {
167 .direction = PM_GPIO_DIR_OUT,
168 .output_buffer = PM_GPIO_OUT_BUF_CMOS,
169 .output_value = 1,
170 .pull = PM_GPIO_PULL_NO,
171 .vin_sel = PM_GPIO_VIN_S4,
172 .out_strength = PM_GPIO_STRENGTH_MED,
173 .
174 function = PM_GPIO_FUNC_NORMAL,
175 };
176
177 if (spk_amp_gpio == bottom_spk_pamp_gpio) {
178
179 ret = gpio_request(bottom_spk_pamp_gpio, "BOTTOM_SPK_AMP");
180 if (ret) {
181 pr_err("%s: Error requesting BOTTOM SPK AMP GPIO %u\n",
182 __func__, bottom_spk_pamp_gpio);
183 return;
184 }
185 ret = pm8xxx_gpio_config(bottom_spk_pamp_gpio, &param);
186 if (ret)
187 pr_err("%s: Failed to configure Bottom Spk Ampl"
188 " gpio %u\n", __func__, bottom_spk_pamp_gpio);
189 else {
190 pr_debug("%s: enable Bottom spkr amp gpio\n", __func__);
191 gpio_direction_output(bottom_spk_pamp_gpio, 1);
192 }
193
194 } else if (spk_amp_gpio == top_spk_pamp_gpio) {
195
196 ret = gpio_request(top_spk_pamp_gpio, "TOP_SPK_AMP");
197 if (ret) {
198 pr_err("%s: Error requesting GPIO %d\n", __func__,
199 top_spk_pamp_gpio);
200 return;
201 }
202 ret = pm8xxx_gpio_config(top_spk_pamp_gpio, &param);
203 if (ret)
204 pr_err("%s: Failed to configure Top Spk Ampl"
205 " gpio %u\n", __func__, top_spk_pamp_gpio);
206 else {
207 pr_debug("%s: enable Top spkr amp gpio\n", __func__);
208 gpio_direction_output(top_spk_pamp_gpio, 1);
209 }
210 } else {
211 pr_err("%s: ERROR : Invalid External Speaker Ampl GPIO."
212 " gpio = %u\n", __func__, spk_amp_gpio);
213 return;
214 }
215}
216
217static void msm_ext_spk_power_amp_on(u32 spk)
218{
219 if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) {
220
221 if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) &&
222 (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) {
223
224 pr_debug("%s() External Bottom Speaker Ampl already "
225 "turned on. spk = 0x%08x\n", __func__, spk);
226 return;
227 }
228
229 msm_ext_bottom_spk_pamp |= spk;
230
231 if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) &&
232 (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) {
233
234 msm_enable_ext_spk_amp_gpio(bottom_spk_pamp_gpio);
235 pr_debug("%s: slepping 4 ms after turning on external "
236 " Bottom Speaker Ampl\n", __func__);
237 usleep_range(4000, 4000);
238 }
239
240 } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG)) {
241
242 if ((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) &&
243 (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) {
244
245 pr_debug("%s() External Top Speaker Ampl already"
246 "turned on. spk = 0x%08x\n", __func__, spk);
247 return;
248 }
249
250 msm_ext_top_spk_pamp |= spk;
251
252 if ((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) &&
253 (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) {
254
255 msm_enable_ext_spk_amp_gpio(top_spk_pamp_gpio);
256 pr_debug("%s: sleeping 4 ms after turning on "
257 " external Top Speaker Ampl\n", __func__);
258 usleep_range(4000, 4000);
259 }
260 } else {
261
262 pr_err("%s: ERROR : Invalid External Speaker Ampl. spk = 0x%08x\n",
263 __func__, spk);
264 return;
265 }
266}
267
268static void msm_ext_spk_power_amp_off(u32 spk)
269{
270 if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) {
271
272 if (!msm_ext_bottom_spk_pamp)
273 return;
274
275 gpio_direction_output(bottom_spk_pamp_gpio, 0);
276 gpio_free(bottom_spk_pamp_gpio);
277 msm_ext_bottom_spk_pamp = 0;
278
279 pr_debug("%s: sleeping 4 ms after turning off external Bottom"
280 " Speaker Ampl\n", __func__);
281
282 usleep_range(4000, 4000);
283
284 } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG)) {
285
286 if (!msm_ext_top_spk_pamp)
287 return;
288
289 gpio_direction_output(top_spk_pamp_gpio, 0);
290 gpio_free(top_spk_pamp_gpio);
291 msm_ext_top_spk_pamp = 0;
292
293 pr_debug("%s: sleeping 4 ms after turning off external Top"
294 " Spkaker Ampl\n", __func__);
295
296 usleep_range(4000, 4000);
297 } else {
298
299 pr_err("%s: ERROR : Invalid Ext Spk Ampl. spk = 0x%08x\n",
300 __func__, spk);
301 return;
302 }
303}
304
305static void msm_ext_control(struct snd_soc_codec *codec)
306{
307 struct snd_soc_dapm_context *dapm = &codec->dapm;
308
309 pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control);
310 if (msm_spk_control == MPQ8064_SPK_ON) {
311 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos");
312 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg");
313 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos");
314 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg");
315 } else {
316 snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Pos");
317 snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Neg");
318 snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Pos");
319 snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Neg");
320 }
321
322 snd_soc_dapm_sync(dapm);
323}
324
325static int msm_get_spk(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *ucontrol)
327{
328 pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control);
329 ucontrol->value.integer.value[0] = msm_spk_control;
330 return 0;
331}
332static int msm_set_spk(struct snd_kcontrol *kcontrol,
333 struct snd_ctl_elem_value *ucontrol)
334{
335 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
336
337 pr_debug("%s()\n", __func__);
338 if (msm_spk_control == ucontrol->value.integer.value[0])
339 return 0;
340
341 msm_spk_control = ucontrol->value.integer.value[0];
342 msm_ext_control(codec);
343 return 1;
344}
345static int msm_spkramp_event(struct snd_soc_dapm_widget *w,
346 struct snd_kcontrol *k, int event)
347{
348 pr_debug("%s() %x\n", __func__, SND_SOC_DAPM_EVENT_ON(event));
349
350 if (SND_SOC_DAPM_EVENT_ON(event)) {
351 if (!strncmp(w->name, "Ext Spk Bottom Pos", 18))
352 msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_POS);
353 else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18))
354 msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_NEG);
355 else if (!strncmp(w->name, "Ext Spk Top Pos", 15))
356 msm_ext_spk_power_amp_on(TOP_SPK_AMP_POS);
357 else if (!strncmp(w->name, "Ext Spk Top Neg", 15))
358 msm_ext_spk_power_amp_on(TOP_SPK_AMP_NEG);
359 else {
360 pr_err("%s() Invalid Speaker Widget = %s\n",
361 __func__, w->name);
362 return -EINVAL;
363 }
364
365 } else {
366 if (!strncmp(w->name, "Ext Spk Bottom Pos", 18))
367 msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_POS);
368 else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18))
369 msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_NEG);
370 else if (!strncmp(w->name, "Ext Spk Top Pos", 15))
371 msm_ext_spk_power_amp_off(TOP_SPK_AMP_POS);
372 else if (!strncmp(w->name, "Ext Spk Top Neg", 15))
373 msm_ext_spk_power_amp_off(TOP_SPK_AMP_NEG);
374 else {
375 pr_err("%s() Invalid Speaker Widget = %s\n",
376 __func__, w->name);
377 return -EINVAL;
378 }
379 }
380 return 0;
381}
382
383static int msm_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
384 bool dapm)
385{
386 pr_debug("%s: enable = %d\n", __func__, enable);
387 if (enable) {
388 clk_users++;
389 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
390 if (clk_users != 1)
391 return 0;
392
393 if (codec_clk) {
394 clk_set_rate(codec_clk, TABLA_EXT_CLK_RATE);
395 clk_enable(codec_clk);
396 tabla_mclk_enable(codec, 1, dapm);
397 } else {
398 pr_err("%s: Error setting Tabla MCLK\n", __func__);
399 clk_users--;
400 return -EINVAL;
401 }
402 } else {
403 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
404 if (clk_users == 0)
405 return 0;
406 clk_users--;
407 if (!clk_users) {
408 pr_debug("%s: disabling MCLK. clk_users = %d\n",
409 __func__, clk_users);
410 clk_disable(codec_clk);
411 tabla_mclk_enable(codec, 0, dapm);
412 }
413 }
414 return 0;
415}
416
417static int msm_mclk_event(struct snd_soc_dapm_widget *w,
418 struct snd_kcontrol *kcontrol, int event)
419{
420 pr_debug("%s: event = %d\n", __func__, event);
421
422 switch (event) {
423 case SND_SOC_DAPM_PRE_PMU:
424
425 clk_users++;
426 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
427
428 if (clk_users != 1)
429 return 0;
430
431 if (codec_clk) {
432 clk_set_rate(codec_clk, 12288000);
433 clk_enable(codec_clk);
434 tabla_mclk_enable(w->codec, 1, true);
435
436 } else {
437 pr_err("%s: Error setting Tabla MCLK\n", __func__);
438 clk_users--;
439 return -EINVAL;
440 }
441 break;
442 case SND_SOC_DAPM_POST_PMD:
443
444 pr_debug("%s: clk_users = %d\n", __func__, clk_users);
445
446 if (clk_users == 0)
447 return 0;
448
449 clk_users--;
450
451 if (!clk_users) {
452 pr_debug("%s: disabling MCLK. clk_users = %d\n",
453 __func__, clk_users);
454
455 clk_disable(codec_clk);
456 tabla_mclk_enable(w->codec, 0, true);
457 }
458 break;
459 }
460 return 0;
461}
462
463static const struct snd_soc_dapm_widget msm_dapm_widgets[] = {
464
465 SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0,
466 msm_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
467
468 SND_SOC_DAPM_SPK("Ext Spk Bottom Pos", msm_spkramp_event),
469 SND_SOC_DAPM_SPK("Ext Spk Bottom Neg", msm_spkramp_event),
470
471 SND_SOC_DAPM_SPK("Ext Spk Top Pos", msm_spkramp_event),
472 SND_SOC_DAPM_SPK("Ext Spk Top Neg", msm_spkramp_event),
473
474 SND_SOC_DAPM_MIC("Handset Mic", NULL),
475 SND_SOC_DAPM_MIC("Headset Mic", NULL),
476
477 SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
478 SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
479};
480
481static const struct snd_soc_dapm_route common_audio_map[] = {
482
483 {"RX_BIAS", NULL, "MCLK"},
484 {"LDO_H", NULL, "MCLK"},
485
486 /* Speaker path */
487 {"Ext Spk Bottom Pos", NULL, "LINEOUT1"},
488 {"Ext Spk Bottom Neg", NULL, "LINEOUT3"},
489
490 {"Ext Spk Top Pos", NULL, "LINEOUT2"},
491 {"Ext Spk Top Neg", NULL, "LINEOUT4"},
492
493 /* Microphone path */
494 {"AMIC1", NULL, "MIC BIAS1 Internal1"},
495 {"MIC BIAS1 Internal1", NULL, "Handset Mic"},
496
497 {"AMIC2", NULL, "MIC BIAS2 External"},
498 {"MIC BIAS2 External", NULL, "Headset Mic"},
499
500 /**
501 * AMIC3 and AMIC4 inputs are connected to ANC microphones
502 * These mics are biased differently on CDP and FLUID
503 * routing entries below are based on bias arrangement
504 * on FLUID.
505 */
506 {"AMIC3", NULL, "MIC BIAS3 Internal1"},
507 {"MIC BIAS3 Internal1", NULL, "ANCRight Headset Mic"},
508
509 {"AMIC4", NULL, "MIC BIAS1 Internal2"},
510 {"MIC BIAS1 Internal2", NULL, "ANCLeft Headset Mic"},
511
512 {"HEADPHONE", NULL, "LDO_H"},
513};
514
515static const char *spk_function[] = {"Off", "On"};
516static const char *slim0_rx_ch_text[] = {"One", "Two"};
517static const char *slim0_tx_ch_text[] = {"One", "Two", "Three", "Four"};
518
519static const struct soc_enum msm_enum[] = {
520 SOC_ENUM_SINGLE_EXT(2, spk_function),
521 SOC_ENUM_SINGLE_EXT(2, slim0_rx_ch_text),
522 SOC_ENUM_SINGLE_EXT(4, slim0_tx_ch_text),
523};
524
525static int msm_slim_0_rx_ch_get(struct snd_kcontrol *kcontrol,
526 struct snd_ctl_elem_value *ucontrol)
527{
528 pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__,
529 msm_slim_0_rx_ch);
530 ucontrol->value.integer.value[0] = msm_slim_0_rx_ch - 1;
531 return 0;
532}
533
534static int msm_slim_0_rx_ch_put(struct snd_kcontrol *kcontrol,
535 struct snd_ctl_elem_value *ucontrol)
536{
537 msm_slim_0_rx_ch = ucontrol->value.integer.value[0] + 1;
538
539 pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__,
540 msm_slim_0_rx_ch);
541 return 1;
542}
543
544static int msm_slim_0_tx_ch_get(struct snd_kcontrol *kcontrol,
545 struct snd_ctl_elem_value *ucontrol)
546{
547 pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__,
548 msm_slim_0_tx_ch);
549 ucontrol->value.integer.value[0] = msm_slim_0_tx_ch - 1;
550 return 0;
551}
552
553static int msm_slim_0_tx_ch_put(struct snd_kcontrol *kcontrol,
554 struct snd_ctl_elem_value *ucontrol)
555{
556 msm_slim_0_tx_ch = ucontrol->value.integer.value[0] + 1;
557
558 pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__,
559 msm_slim_0_tx_ch);
560 return 1;
561}
562
563static const struct snd_kcontrol_new tabla_msm_controls[] = {
564 SOC_ENUM_EXT("Speaker Function", msm_enum[0], msm_get_spk,
565 msm_set_spk),
566 SOC_ENUM_EXT("SLIM_0_RX Channels", msm_enum[1],
567 msm_slim_0_rx_ch_get, msm_slim_0_rx_ch_put),
568 SOC_ENUM_EXT("SLIM_0_TX Channels", msm_enum[2],
569 msm_slim_0_tx_ch_get, msm_slim_0_tx_ch_put),
570};
571
572static void *def_tabla_mbhc_cal(void)
573{
574 void *tabla_cal;
575 struct tabla_mbhc_btn_detect_cfg *btn_cfg;
576 u16 *btn_low, *btn_high;
577 u8 *n_ready, *n_cic, *gain;
578
579 tabla_cal = kzalloc(TABLA_MBHC_CAL_SIZE(TABLA_MBHC_DEF_BUTTONS,
580 TABLA_MBHC_DEF_RLOADS),
581 GFP_KERNEL);
582 if (!tabla_cal) {
583 pr_err("%s: out of memory\n", __func__);
584 return NULL;
585 }
586
587#define S(X, Y) ((TABLA_MBHC_CAL_GENERAL_PTR(tabla_cal)->X) = (Y))
588 S(t_ldoh, 100);
589 S(t_bg_fast_settle, 100);
590 S(t_shutdown_plug_rem, 255);
591 S(mbhc_nsa, 4);
592 S(mbhc_navg, 4);
593#undef S
594#define S(X, Y) ((TABLA_MBHC_CAL_PLUG_DET_PTR(tabla_cal)->X) = (Y))
595 S(mic_current, TABLA_PID_MIC_5_UA);
596 S(hph_current, TABLA_PID_MIC_5_UA);
597 S(t_mic_pid, 100);
598 S(t_ins_complete, 250);
599 S(t_ins_retry, 200);
600#undef S
601#define S(X, Y) ((TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla_cal)->X) = (Y))
602 S(v_no_mic, 30);
603 S(v_hs_max, 1550);
604#undef S
605#define S(X, Y) ((TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal)->X) = (Y))
606 S(c[0], 62);
607 S(c[1], 124);
608 S(nc, 1);
609 S(n_meas, 3);
610 S(mbhc_nsc, 11);
611 S(n_btn_meas, 1);
612 S(n_btn_con, 2);
613 S(num_btn, TABLA_MBHC_DEF_BUTTONS);
614 S(v_btn_press_delta_sta, 100);
615 S(v_btn_press_delta_cic, 50);
616#undef S
617 btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal);
618 btn_low = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_LOW);
619 btn_high = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_HIGH);
620 btn_low[0] = -50;
621 btn_high[0] = 10;
622 btn_low[1] = 11;
623 btn_high[1] = 38;
624 btn_low[2] = 39;
625 btn_high[2] = 64;
626 btn_low[3] = 65;
627 btn_high[3] = 91;
628 btn_low[4] = 92;
629 btn_high[4] = 115;
630 btn_low[5] = 116;
631 btn_high[5] = 141;
632 btn_low[6] = 142;
633 btn_high[6] = 163;
634 btn_low[7] = 164;
635 btn_high[7] = 250;
636 n_ready = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_READY);
637 n_ready[0] = 48;
638 n_ready[1] = 38;
639 n_cic = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_CIC);
640 n_cic[0] = 60;
641 n_cic[1] = 47;
642 gain = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_GAIN);
643 gain[0] = 11;
644 gain[1] = 9;
645
646 return tabla_cal;
647}
648
649static int msm_hw_params(struct snd_pcm_substream *substream,
650 struct snd_pcm_hw_params *params)
651{
652 struct snd_soc_pcm_runtime *rtd = substream->private_data;
653 struct snd_soc_dai *codec_dai = rtd->codec_dai;
654 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
655 int ret = 0;
656 unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
657 unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
658
659 pr_debug("%s: ch=%d\n", __func__,
660 msm_slim_0_rx_ch);
661 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
662 ret = snd_soc_dai_get_channel_map(codec_dai,
663 &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
664 if (ret < 0) {
665 pr_err("%s: failed to get codec chan map\n", __func__);
666 goto end;
667 }
668
669 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
670 msm_slim_0_rx_ch, rx_ch);
671 if (ret < 0) {
672 pr_err("%s: failed to set cpu chan map\n", __func__);
673 goto end;
674 }
675 ret = snd_soc_dai_set_channel_map(codec_dai, 0, 0,
676 msm_slim_0_rx_ch, rx_ch);
677 if (ret < 0) {
678 pr_err("%s: failed to set codec channel map\n",
679 __func__);
680 goto end;
681 }
682 } else {
683 ret = snd_soc_dai_get_channel_map(codec_dai,
684 &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
685 if (ret < 0) {
686 pr_err("%s: failed to get codec chan map\n", __func__);
687 goto end;
688 }
689 ret = snd_soc_dai_set_channel_map(cpu_dai,
690 msm_slim_0_tx_ch, tx_ch, 0 , 0);
691 if (ret < 0) {
692 pr_err("%s: failed to set cpu chan map\n", __func__);
693 goto end;
694 }
695 ret = snd_soc_dai_set_channel_map(codec_dai,
696 msm_slim_0_tx_ch, tx_ch, 0, 0);
697 if (ret < 0) {
698 pr_err("%s: failed to set codec channel map\n",
699 __func__);
700 goto end;
701 }
702
703
704 }
705end:
706 return ret;
707}
708
709static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
710{
711 int err;
712 struct snd_soc_codec *codec = rtd->codec;
713 struct snd_soc_dapm_context *dapm = &codec->dapm;
714 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
715
716 pr_debug("%s(), dev_name%s\n", __func__, dev_name(cpu_dai->dev));
717
718 /*if (machine_is_msm_liquid()) {
719 top_spk_pamp_gpio = (PM8921_GPIO_PM_TO_SYS(19));
720 bottom_spk_pamp_gpio = (PM8921_GPIO_PM_TO_SYS(18));
721 }*/
722
723 rtd->pmdown_time = 0;
724
725 err = snd_soc_add_controls(codec, tabla_msm_controls,
726 ARRAY_SIZE(tabla_msm_controls));
727 if (err < 0)
728 return err;
729
730 snd_soc_dapm_new_controls(dapm, msm_dapm_widgets,
731 ARRAY_SIZE(msm_dapm_widgets));
732
733 snd_soc_dapm_add_routes(dapm, common_audio_map,
734 ARRAY_SIZE(common_audio_map));
735
736 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos");
737 snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg");
738 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos");
739 snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg");
740
741 snd_soc_dapm_sync(dapm);
742
743 err = snd_soc_jack_new(codec, "Headset Jack",
744 (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR),
745 &hs_jack);
746 if (err) {
747 pr_err("failed to create new jack\n");
748 return err;
749 }
750
751 err = snd_soc_jack_new(codec, "Button Jack",
752 TABLA_JACK_BUTTON_MASK, &button_jack);
753 if (err) {
754 pr_err("failed to create new jack\n");
755 return err;
756 }
757
758 codec_clk = clk_get(cpu_dai->dev, "osr_clk");
759
760 err = tabla_hs_detect(codec, &mbhc_cfg);
761
762 return err;
763}
764
765static struct snd_soc_dsp_link lpa_fe_media = {
766 .playback = true,
767 .trigger = {
768 SND_SOC_DSP_TRIGGER_POST,
769 SND_SOC_DSP_TRIGGER_POST
770 },
771};
772
773static struct snd_soc_dsp_link fe_media = {
774 .playback = true,
775 .capture = true,
776 .trigger = {
777 SND_SOC_DSP_TRIGGER_POST,
778 SND_SOC_DSP_TRIGGER_POST
779 },
780};
781
Kuirong Wang12f0aea2012-04-23 10:54:51 -0700782static struct snd_soc_dsp_link bidir_hl_media = {
Santosh Mardi603fbb92012-03-22 03:45:46 +0530783 .playback = true,
784 .capture = true,
785 .trigger = {
786 SND_SOC_DSP_TRIGGER_POST,
787 SND_SOC_DSP_TRIGGER_POST
788 },
789};
790
Kuirong Wang12f0aea2012-04-23 10:54:51 -0700791static struct snd_soc_dsp_link tx_hl_media = {
Santosh Mardi603fbb92012-03-22 03:45:46 +0530792 .capture = true,
793 .trigger = {
794 SND_SOC_DSP_TRIGGER_POST,
795 SND_SOC_DSP_TRIGGER_POST
796 },
797};
798
Kuirong Wang12f0aea2012-04-23 10:54:51 -0700799
800static struct snd_soc_dsp_link rx_hl_media = {
801 .playback = true,
802 .trigger = {
803 SND_SOC_DSP_TRIGGER_POST,
804 SND_SOC_DSP_TRIGGER_POST
805 },
806};
Santosh Mardi603fbb92012-03-22 03:45:46 +0530807static int msm_slim_0_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
808 struct snd_pcm_hw_params *params)
809{
810 struct snd_interval *rate = hw_param_interval(params,
811 SNDRV_PCM_HW_PARAM_RATE);
812
813 struct snd_interval *channels = hw_param_interval(params,
814 SNDRV_PCM_HW_PARAM_CHANNELS);
815
816 pr_debug("%s()\n", __func__);
817 rate->min = rate->max = 48000;
818 channels->min = channels->max = msm_slim_0_rx_ch;
819
820 return 0;
821}
822
823static int msm_slim_0_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
824 struct snd_pcm_hw_params *params)
825{
826 struct snd_interval *rate = hw_param_interval(params,
827 SNDRV_PCM_HW_PARAM_RATE);
828
829 struct snd_interval *channels = hw_param_interval(params,
830 SNDRV_PCM_HW_PARAM_CHANNELS);
831
832 pr_debug("%s()\n", __func__);
833 rate->min = rate->max = 48000;
834 channels->min = channels->max = msm_slim_0_tx_ch;
835
836 return 0;
837}
838
839static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
840 struct snd_pcm_hw_params *params)
841{
842 struct snd_interval *rate = hw_param_interval(params,
843 SNDRV_PCM_HW_PARAM_RATE);
844
845 pr_debug("%s()\n", __func__);
846 rate->min = rate->max = 48000;
847
848 return 0;
849}
850
851static int msm_hdmi_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
852 struct snd_pcm_hw_params *params)
853{
854 struct snd_interval *rate = hw_param_interval(params,
855 SNDRV_PCM_HW_PARAM_RATE);
856
857 struct snd_interval *channels = hw_param_interval(params,
858 SNDRV_PCM_HW_PARAM_CHANNELS);
859
860 pr_debug("%s channels->min %u channels->max %u ()\n", __func__,
861 channels->min, channels->max);
862
863 rate->min = rate->max = 48000;
864
865 return 0;
866}
867
Kuirong Wang9ddff202012-03-31 14:49:39 -0700868static int msm_mi2s_free_gpios(void)
869{
870 int i;
871 for (i = 0; i < ARRAY_SIZE(mi2s_gpio); i++)
872 gpio_free(mi2s_gpio[i].gpio_no);
873 return 0;
874}
875
876static void msm_mi2s_shutdown(struct snd_pcm_substream *substream)
877{
878 if (mi2s_bit_clk) {
879 clk_disable(mi2s_bit_clk);
880 clk_put(mi2s_bit_clk);
881 mi2s_bit_clk = NULL;
882 }
883 msm_mi2s_free_gpios();
884}
885
886static int configure_mi2s_gpio(void)
887{
888 int rtn;
889 int i;
890 int j;
891 for (i = 0; i < ARRAY_SIZE(mi2s_gpio); i++) {
892 rtn = gpio_request(mi2s_gpio[i].gpio_no,
893 mi2s_gpio[i].gpio_name);
894 pr_debug("%s: gpio = %d, gpio name = %s, rtn = %d\n",
895 __func__,
896 mi2s_gpio[i].gpio_no,
897 mi2s_gpio[i].gpio_name,
898 rtn);
899 if (rtn) {
900 pr_err("%s: Failed to request gpio %d\n",
901 __func__,
902 mi2s_gpio[i].gpio_no);
903 for (j = i; j >= 0; j--)
904 gpio_free(mi2s_gpio[j].gpio_no);
905 goto err;
906 }
907 }
908err:
909 return rtn;
910}
911static int msm_mi2s_startup(struct snd_pcm_substream *substream)
912{
913 int ret = 0;
914 struct snd_soc_pcm_runtime *rtd = substream->private_data;
915 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
916 configure_mi2s_gpio();
917 mi2s_bit_clk = clk_get(cpu_dai->dev, "bit_clk");
918 if (IS_ERR(mi2s_bit_clk))
919 return PTR_ERR(mi2s_bit_clk);
920 clk_set_rate(mi2s_bit_clk, 0);
921 ret = clk_enable(mi2s_bit_clk);
922 if (IS_ERR_VALUE(ret)) {
923 pr_err("Unable to enable mi2s_bit_clk\n");
924 clk_put(mi2s_bit_clk);
925 return ret;
926 }
927 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM);
928 if (IS_ERR_VALUE(ret))
929 pr_err("set format for CPU dai failed\n");
930 return ret;
931}
932
Santosh Mardi603fbb92012-03-22 03:45:46 +0530933static int msm_startup(struct snd_pcm_substream *substream)
934{
935 pr_debug("%s(): substream = %s stream = %d\n", __func__,
936 substream->name, substream->stream);
937 return 0;
938}
939
940static void msm_shutdown(struct snd_pcm_substream *substream)
941{
942 pr_debug("%s(): substream = %s stream = %d\n", __func__,
943 substream->name, substream->stream);
944}
945
946static struct snd_soc_ops msm_be_ops = {
947 .startup = msm_startup,
948 .hw_params = msm_hw_params,
949 .shutdown = msm_shutdown,
950};
951
952static int mpq8064_sec_i2s_rx_free_gpios(void)
953{
954 int i;
955 for (i = 0; i < ARRAY_SIZE(sec_i2s_rx_gpio); i++)
956 gpio_free(sec_i2s_rx_gpio[i].gpio_no);
957 return 0;
958}
959
960static int mpq8064_sec_i2s_rx_hw_params(struct snd_pcm_substream *substream,
961 struct snd_pcm_hw_params *params)
962{
963
964 int rate = params_rate(params);
965 int bit_clk_set = 0;
966 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
967 switch (params_format(params)) {
968 case SNDRV_PCM_FORMAT_S16_LE:
969 bit_clk_set = I2S_MCLK_RATE/(rate * 2 * 16);
970 clk_set_rate(sec_i2s_rx_bit_clk, bit_clk_set);
971 break;
972 case SNDRV_PCM_FORMAT_S24_LE:
973 bit_clk_set = I2S_MCLK_RATE/(rate * 2 * 24);
974 clk_set_rate(sec_i2s_rx_bit_clk, bit_clk_set);
975 break;
976 default:
977 pr_err("wrong format\n");
978 break;
979 }
980 }
981 return 0;
982}
983
984static void mpq8064_sec_i2s_rx_shutdown(struct snd_pcm_substream *substream)
985{
986 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
987 if (sec_i2s_rx_bit_clk) {
988 clk_disable(sec_i2s_rx_bit_clk);
989 clk_put(sec_i2s_rx_bit_clk);
990 sec_i2s_rx_bit_clk = NULL;
991 }
992 if (sec_i2s_rx_osr_clk) {
993 clk_disable(sec_i2s_rx_osr_clk);
994 clk_put(sec_i2s_rx_osr_clk);
995 sec_i2s_rx_osr_clk = NULL;
996 }
997 mpq8064_sec_i2s_rx_free_gpios();
998 }
999 pr_info("%s(): substream = %s stream = %d\n", __func__,
1000 substream->name, substream->stream);
1001}
1002
1003static int configure_sec_i2s_rx_gpio(void)
1004{
1005 int rtn;
1006 int i;
1007 int j;
1008 for (i = 0; i < ARRAY_SIZE(sec_i2s_rx_gpio); i++) {
1009 rtn = gpio_request(sec_i2s_rx_gpio[i].gpio_no,
1010 sec_i2s_rx_gpio[i].gpio_name);
1011 pr_debug("%s: gpio = %d, gpio name = %s, rtn = %d\n",
1012 __func__,
1013 sec_i2s_rx_gpio[i].gpio_no,
1014 sec_i2s_rx_gpio[i].gpio_name,
1015 rtn);
1016 if (rtn) {
1017 pr_err("%s: Failed to request gpio %d\n",
1018 __func__,
1019 sec_i2s_rx_gpio[i].gpio_no);
1020 for (j = i; j >= 0; j--)
1021 gpio_free(sec_i2s_rx_gpio[j].gpio_no);
1022
1023 goto err;
1024 }
1025 }
1026err:
1027 return rtn;
1028}
1029
1030static int mpq8064_sec_i2s_rx_startup(struct snd_pcm_substream *substream)
1031{
1032 int ret = 0;
1033 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1034 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1035 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1036 configure_sec_i2s_rx_gpio();
1037 sec_i2s_rx_osr_clk = clk_get(cpu_dai->dev, "osr_clk");
1038 if (IS_ERR(sec_i2s_rx_osr_clk)) {
1039 pr_err("Failed to get sec_i2s_rx_osr_clk\n");
1040 return PTR_ERR(sec_i2s_rx_osr_clk);
1041 }
1042 clk_set_rate(sec_i2s_rx_osr_clk, I2S_MCLK_RATE);
1043 clk_enable(sec_i2s_rx_osr_clk);
1044 sec_i2s_rx_bit_clk = clk_get(cpu_dai->dev, "bit_clk");
1045 if (IS_ERR(sec_i2s_rx_bit_clk)) {
1046 pr_err("Failed to get sec i2s osr_clk\n");
1047 clk_disable(sec_i2s_rx_osr_clk);
1048 clk_put(sec_i2s_rx_osr_clk);
1049 return PTR_ERR(sec_i2s_rx_bit_clk);
1050 }
1051 clk_set_rate(sec_i2s_rx_bit_clk, 1);
1052 ret = clk_enable(sec_i2s_rx_bit_clk);
1053 if (ret != 0) {
1054 pr_err("Unable to enable sec i2s rx_bit_clk\n");
1055 clk_put(sec_i2s_rx_bit_clk);
1056 clk_disable(sec_i2s_rx_osr_clk);
1057 clk_put(sec_i2s_rx_osr_clk);
1058 return ret;
1059 }
1060 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBS_CFS);
1061 if (ret < 0)
1062 pr_err("set format for codec dai failed\n");
1063 }
1064 pr_debug("%s: ret = %d\n", __func__, ret);
1065 pr_info("%s(): substream = %s stream = %d\n", __func__,
1066 substream->name, substream->stream);
1067 return ret;
1068}
1069
1070static struct snd_soc_ops mpq8064_sec_i2s_rx_be_ops = {
1071 .startup = mpq8064_sec_i2s_rx_startup,
1072 .shutdown = mpq8064_sec_i2s_rx_shutdown,
1073 .hw_params = mpq8064_sec_i2s_rx_hw_params,
1074};
1075
Kuirong Wang9ddff202012-03-31 14:49:39 -07001076static struct snd_soc_ops msm_mi2s_tx_be_ops = {
1077 .startup = msm_mi2s_startup,
1078 .shutdown = msm_mi2s_shutdown,
1079};
1080
1081
Santosh Mardi603fbb92012-03-22 03:45:46 +05301082/* Digital audio interface glue - connects codec <---> CPU */
1083static struct snd_soc_dai_link msm_dai[] = {
1084 /* FrontEnd DAI Links */
1085 {
1086 .name = "MSM8960 Media1",
1087 .stream_name = "MultiMedia1",
1088 .cpu_dai_name = "MultiMedia1",
1089 .platform_name = "msm-pcm-dsp",
1090 .dynamic = 1,
1091 .dsp_link = &fe_media,
1092 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA1
1093 },
1094 {
1095 .name = "MSM8960 Media2",
1096 .stream_name = "MultiMedia2",
1097 .cpu_dai_name = "MultiMedia2",
1098 .platform_name = "msm-pcm-dsp",
1099 .dynamic = 1,
1100 .dsp_link = &fe_media,
1101 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA2,
1102 },
1103 {
1104 .name = "Circuit-Switch Voice",
1105 .stream_name = "CS-Voice",
1106 .cpu_dai_name = "CS-VOICE",
1107 .platform_name = "msm-pcm-voice",
1108 .dynamic = 1,
1109 .dsp_link = &fe_media,
1110 .be_id = MSM_FRONTEND_DAI_CS_VOICE,
1111 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1112 .ignore_suspend = 1,
1113 },
1114 {
1115 .name = "MSM VoIP",
1116 .stream_name = "VoIP",
1117 .cpu_dai_name = "VoIP",
1118 .platform_name = "msm-voip-dsp",
1119 .dynamic = 1,
1120 .dsp_link = &fe_media,
1121 .be_id = MSM_FRONTEND_DAI_VOIP,
1122 },
1123 {
1124 .name = "MSM8960 LPA",
1125 .stream_name = "LPA",
1126 .cpu_dai_name = "MultiMedia3",
1127 .platform_name = "msm-pcm-lpa",
1128 .dynamic = 1,
1129 .dsp_link = &lpa_fe_media,
1130 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA3,
1131 },
1132 /* Hostless PMC purpose */
1133 {
1134 .name = "SLIMBUS_0 Hostless",
1135 .stream_name = "SLIMBUS_0 Hostless",
1136 .cpu_dai_name = "SLIMBUS0_HOSTLESS",
1137 .platform_name = "msm-pcm-hostless",
1138 .dynamic = 1,
Kuirong Wang12f0aea2012-04-23 10:54:51 -07001139 .dsp_link = &bidir_hl_media,
Santosh Mardi603fbb92012-03-22 03:45:46 +05301140 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1141 .ignore_suspend = 1,
1142 /* .be_id = do not care */
1143 },
1144 {
1145 .name = "INT_FM Hostless",
1146 .stream_name = "INT_FM Hostless",
1147 .cpu_dai_name = "INT_FM_HOSTLESS",
1148 .platform_name = "msm-pcm-hostless",
1149 .dynamic = 1,
Kuirong Wang12f0aea2012-04-23 10:54:51 -07001150 .dsp_link = &bidir_hl_media,
Santosh Mardi603fbb92012-03-22 03:45:46 +05301151 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1152 .ignore_suspend = 1,
1153 /* .be_id = do not care */
1154 },
1155 {
1156 .name = "MSM AFE-PCM RX",
1157 .stream_name = "AFE-PROXY RX",
1158 .cpu_dai_name = "msm-dai-q6.241",
1159 .codec_name = "msm-stub-codec.1",
1160 .codec_dai_name = "msm-stub-rx",
1161 .platform_name = "msm-pcm-afe",
1162 .ignore_suspend = 1,
1163 },
1164 {
1165 .name = "MSM AFE-PCM TX",
1166 .stream_name = "AFE-PROXY TX",
1167 .cpu_dai_name = "msm-dai-q6.240",
1168 .codec_name = "msm-stub-codec.1",
1169 .codec_dai_name = "msm-stub-tx",
1170 .platform_name = "msm-pcm-afe",
1171 .ignore_suspend = 1,
1172 },
1173 {
1174 .name = "MSM8960 Compr",
1175 .stream_name = "COMPR",
1176 .cpu_dai_name = "MultiMedia4",
1177 .platform_name = "msm-compr-dsp",
1178 .dynamic = 1,
1179 .dsp_link = &lpa_fe_media,
1180 .be_id = MSM_FRONTEND_DAI_MULTIMEDIA4,
1181 },
1182 {
1183 .name = "Voice Stub",
1184 .stream_name = "Voice Stub",
1185 .cpu_dai_name = "VOICE_STUB",
1186 .platform_name = "msm-pcm-hostless",
1187 .dynamic = 1,
Kuirong Wang12f0aea2012-04-23 10:54:51 -07001188 .dsp_link = &bidir_hl_media,
Santosh Mardi603fbb92012-03-22 03:45:46 +05301189 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1190 .ignore_suspend = 1,
1191 /* .be_id = do not care */
1192 },
Kuirong Wang12f0aea2012-04-23 10:54:51 -07001193 /* MI2S TX Hostless */
1194 {
1195 .name = "MI2S_TX Hostless",
1196 .stream_name = "MI2S_TX Hostless",
1197 .cpu_dai_name = "MI2S_TX_HOSTLESS",
1198 .platform_name = "msm-pcm-hostless",
1199 .dynamic = 1,
1200 .dsp_link = &tx_hl_media,
1201 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1202 .no_codec = 1,
1203 .ignore_suspend = 1,
1204 },
1205 /* HDMI Hostless */
1206 {
1207 .name = "HDMI_RX_HOSTLESS",
1208 .stream_name = "HDMI_RX_HOSTLESS",
1209 .cpu_dai_name = "HDMI_HOSTLESS",
1210 .platform_name = "msm-pcm-hostless",
1211 .dynamic = 1,
1212 .dsp_link = &rx_hl_media,
1213 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1214 .no_codec = 1,
1215 .ignore_suspend = 1,
1216 },
1217 /* Secondary I2S RX Hostless */
1218 {
1219 .name = "SEC_I2S_RX Hostless",
1220 .stream_name = "SEC_I2S_RX Hostless",
1221 .cpu_dai_name = "SEC_I2S_RX_HOSTLESS",
1222 .platform_name = "msm-pcm-hostless",
1223 .dynamic = 1,
1224 .dsp_link = &rx_hl_media,
1225 .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
1226 .no_codec = 1,
1227 .ignore_suspend = 1,
1228 },
Santosh Mardi603fbb92012-03-22 03:45:46 +05301229 /* Backend DAI Links */
1230 {
1231 .name = LPASS_BE_SLIMBUS_0_RX,
1232 .stream_name = "Slimbus Playback",
1233 .cpu_dai_name = "msm-dai-q6.16384",
1234 .platform_name = "msm-pcm-routing",
1235 .codec_name = "tabla_codec",
1236 .codec_dai_name = "tabla_rx1",
1237 .no_pcm = 1,
1238 .be_id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
1239 .init = &msm_audrx_init,
1240 .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
1241 .ops = &msm_be_ops,
1242 },
1243 {
1244 .name = LPASS_BE_SLIMBUS_0_TX,
1245 .stream_name = "Slimbus Capture",
1246 .cpu_dai_name = "msm-dai-q6.16385",
1247 .platform_name = "msm-pcm-routing",
1248 .codec_name = "tabla_codec",
1249 .codec_dai_name = "tabla_tx1",
1250 .no_pcm = 1,
1251 .be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
1252 .be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
1253 .ops = &msm_be_ops,
1254 },
1255 {
1256 .name = LPASS_BE_SEC_I2S_RX,
1257 .stream_name = "Secondary I2S Playback",
1258 .cpu_dai_name = "msm-dai-q6.4",
1259 .platform_name = "msm-pcm-routing",
1260 .codec_name = "cs8427-spdif.5-0014",
1261 .codec_dai_name = "spdif_rx",
1262 .no_pcm = 1,
1263 .be_id = MSM_BACKEND_DAI_SEC_I2S_RX,
1264 .be_hw_params_fixup = msm_be_hw_params_fixup,
1265 .ops = &mpq8064_sec_i2s_rx_be_ops,
1266 },
1267 {
1268 .name = LPASS_BE_INT_FM_RX,
1269 .stream_name = "Internal FM Playback",
1270 .cpu_dai_name = "msm-dai-q6.12292",
1271 .platform_name = "msm-pcm-routing",
1272 .codec_name = "msm-stub-codec.1",
1273 .codec_dai_name = "msm-stub-rx",
1274 .no_pcm = 1,
1275 .be_id = MSM_BACKEND_DAI_INT_FM_RX,
1276 .be_hw_params_fixup = msm_be_hw_params_fixup,
1277 },
1278 {
1279 .name = LPASS_BE_INT_FM_TX,
1280 .stream_name = "Internal FM Capture",
1281 .cpu_dai_name = "msm-dai-q6.12293",
1282 .platform_name = "msm-pcm-routing",
1283 .codec_name = "msm-stub-codec.1",
1284 .codec_dai_name = "msm-stub-tx",
1285 .no_pcm = 1,
1286 .be_id = MSM_BACKEND_DAI_INT_FM_TX,
1287 .be_hw_params_fixup = msm_be_hw_params_fixup,
1288 },
1289 /* HDMI BACK END DAI Link */
1290 {
1291 .name = LPASS_BE_HDMI,
1292 .stream_name = "HDMI Playback",
1293 .cpu_dai_name = "msm-dai-q6-hdmi.8",
1294 .platform_name = "msm-pcm-routing",
1295 .codec_name = "msm-stub-codec.1",
1296 .codec_dai_name = "msm-stub-rx",
1297 .no_pcm = 1,
1298 .no_codec = 1,
1299 .be_id = MSM_BACKEND_DAI_HDMI_RX,
1300 .be_hw_params_fixup = msm_hdmi_be_hw_params_fixup,
1301 },
Kuirong Wang9ddff202012-03-31 14:49:39 -07001302 {
1303 .name = LPASS_BE_MI2S_TX,
1304 .stream_name = "MI2S Capture",
1305 .cpu_dai_name = "msm-dai-q6.7",
1306 .platform_name = "msm-pcm-routing",
1307 .codec_name = "msm-stub-codec.1",
1308 .codec_dai_name = "msm-stub-tx",
1309 .no_pcm = 1,
1310 .no_codec = 1,
1311 .be_id = MSM_BACKEND_DAI_MI2S_TX,
1312 .be_hw_params_fixup = msm_be_hw_params_fixup,
1313 .ops = &msm_mi2s_tx_be_ops,
1314 },
Santosh Mardi603fbb92012-03-22 03:45:46 +05301315 /* Backend AFE DAI Links */
1316 {
1317 .name = LPASS_BE_AFE_PCM_RX,
1318 .stream_name = "AFE Playback",
1319 .cpu_dai_name = "msm-dai-q6.224",
1320 .platform_name = "msm-pcm-routing",
1321 .codec_name = "msm-stub-codec.1",
1322 .codec_dai_name = "msm-stub-rx",
1323 .no_codec = 1,
1324 .no_pcm = 1,
1325 .be_id = MSM_BACKEND_DAI_AFE_PCM_RX,
1326 },
1327 {
1328 .name = LPASS_BE_AFE_PCM_TX,
1329 .stream_name = "AFE Capture",
1330 .cpu_dai_name = "msm-dai-q6.225",
1331 .platform_name = "msm-pcm-routing",
1332 .codec_name = "msm-stub-codec.1",
1333 .codec_dai_name = "msm-stub-tx",
1334 .no_codec = 1,
1335 .no_pcm = 1,
1336 .be_id = MSM_BACKEND_DAI_AFE_PCM_TX,
1337 },
1338};
1339
1340
1341static struct snd_soc_card snd_soc_card_msm = {
1342 .name = "mpq8064-tabla-snd-card",
1343 .dai_link = msm_dai,
1344 .num_links = ARRAY_SIZE(msm_dai),
1345};
1346
1347static struct platform_device *msm_snd_device;
1348
1349static int msm_configure_headset_mic_gpios(void)
1350{
1351 int ret;
1352 struct pm_gpio param = {
1353 .direction = PM_GPIO_DIR_OUT,
1354 .output_buffer = PM_GPIO_OUT_BUF_CMOS,
1355 .output_value = 1,
1356 .pull = PM_GPIO_PULL_NO,
1357 .vin_sel = PM_GPIO_VIN_S4,
1358 .out_strength = PM_GPIO_STRENGTH_MED,
1359 .function = PM_GPIO_FUNC_NORMAL,
1360 };
1361
1362 ret = gpio_request(PM8921_GPIO_PM_TO_SYS(23), "AV_SWITCH");
1363 if (ret) {
1364 pr_err("%s: Failed to request gpio %d\n", __func__,
1365 PM8921_GPIO_PM_TO_SYS(23));
1366 return ret;
1367 }
1368
1369 ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(23), &param);
1370 if (ret)
1371 pr_err("%s: Failed to configure gpio %d\n", __func__,
1372 PM8921_GPIO_PM_TO_SYS(23));
1373 else
1374 gpio_direction_output(PM8921_GPIO_PM_TO_SYS(23), 0);
1375
1376 ret = gpio_request(PM8921_GPIO_PM_TO_SYS(35), "US_EURO_SWITCH");
1377 if (ret) {
1378 pr_err("%s: Failed to request gpio %d\n", __func__,
1379 PM8921_GPIO_PM_TO_SYS(35));
1380 gpio_free(PM8921_GPIO_PM_TO_SYS(23));
1381 return ret;
1382 }
1383 ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(35), &param);
1384 if (ret)
1385 pr_err("%s: Failed to configure gpio %d\n", __func__,
1386 PM8921_GPIO_PM_TO_SYS(35));
1387 else
1388 gpio_direction_output(PM8921_GPIO_PM_TO_SYS(35), 0);
1389
1390 return 0;
1391}
1392static void msm_free_headset_mic_gpios(void)
1393{
1394 if (msm_headset_gpios_configured) {
1395 gpio_free(PM8921_GPIO_PM_TO_SYS(23));
1396 gpio_free(PM8921_GPIO_PM_TO_SYS(35));
1397 }
1398}
1399
1400static int __init msm_audio_init(void)
1401{
1402 int ret;
1403
1404 if (socinfo_get_id() != 130) {
1405 pr_err("%s: Not the right machine type\n", __func__);
1406 return -ENODEV;
1407 }
1408
1409 mbhc_cfg.calibration = def_tabla_mbhc_cal();
1410 if (!mbhc_cfg.calibration) {
1411 pr_err("Calibration data allocation failed\n");
1412 return -ENOMEM;
1413 }
1414
1415 msm_snd_device = platform_device_alloc("soc-audio", 0);
1416 if (!msm_snd_device) {
1417 pr_err("Platform device allocation failed\n");
1418 kfree(mbhc_cfg.calibration);
1419 return -ENOMEM;
1420 }
1421
1422 platform_set_drvdata(msm_snd_device, &snd_soc_card_msm);
1423 ret = platform_device_add(msm_snd_device);
1424 if (ret) {
1425 platform_device_put(msm_snd_device);
1426 kfree(mbhc_cfg.calibration);
1427 return ret;
1428 }
1429
1430 if (msm_configure_headset_mic_gpios()) {
1431 pr_err("%s Fail to configure headset mic gpios\n", __func__);
1432 msm_headset_gpios_configured = 0;
1433 } else
1434 msm_headset_gpios_configured = 1;
1435
1436 return ret;
1437
1438}
1439module_init(msm_audio_init);
1440
1441static void __exit msm_audio_exit(void)
1442{
1443 if (socinfo_get_id() != 130) {
1444 pr_err("%s: Not the right machine type\n", __func__);
1445 return ;
1446 }
1447 msm_free_headset_mic_gpios();
1448 platform_device_unregister(msm_snd_device);
1449 kfree(mbhc_cfg.calibration);
1450}
1451module_exit(msm_audio_exit);
1452
1453MODULE_DESCRIPTION("ALSA SoC mpq8064");
1454MODULE_LICENSE("GPL v2");