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