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> |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 24 | #include <sound/pcm.h> |
| 25 | #include <sound/jack.h> |
| 26 | #include <sound/pcm_params.h> |
| 27 | #include <asm/mach-types.h> |
| 28 | #include <mach/socinfo.h> |
| 29 | #include "msm-pcm-routing.h" |
| 30 | #include "../codecs/wcd9310.h" |
| 31 | |
| 32 | /* 8064 machine driver */ |
| 33 | |
| 34 | #define PM8921_GPIO_BASE NR_GPIO_IRQS |
| 35 | #define PM8921_GPIO_PM_TO_SYS(pm_gpio) (pm_gpio - 1 + PM8921_GPIO_BASE) |
| 36 | |
| 37 | #define MPQ8064_SPK_ON 1 |
| 38 | #define MPQ8064_SPK_OFF 0 |
| 39 | |
| 40 | #define MSM_SLIM_0_RX_MAX_CHANNELS 2 |
| 41 | #define MSM_SLIM_0_TX_MAX_CHANNELS 4 |
| 42 | |
| 43 | #define BOTTOM_SPK_AMP_POS 0x1 |
| 44 | #define BOTTOM_SPK_AMP_NEG 0x2 |
| 45 | #define TOP_SPK_AMP_POS 0x4 |
| 46 | #define TOP_SPK_AMP_NEG 0x8 |
| 47 | |
| 48 | #define TABLA_EXT_CLK_RATE 12288000 |
| 49 | |
| 50 | #define TABLA_MBHC_DEF_BUTTONS 8 |
| 51 | #define TABLA_MBHC_DEF_RLOADS 5 |
| 52 | |
| 53 | #define GPIO_SEC_I2S_RX_SCK 47 |
| 54 | #define GPIO_SEC_I2S_RX_WS 48 |
| 55 | #define GPIO_SEC_I2S_RX_DOUT 49 |
| 56 | #define GPIO_SEC_I2S_RX_MCLK 50 |
| 57 | #define I2S_MCLK_RATE 1536000 |
| 58 | |
Kuirong Wang | 9ddff20 | 2012-03-31 14:49:39 -0700 | [diff] [blame] | 59 | #define GPIO_MI2S_WS 27 |
| 60 | #define GPIO_MI2S_SCLK 28 |
| 61 | #define GPIO_MI2S_DOUT3 29 |
| 62 | #define GPIO_MI2S_DOUT2 30 |
| 63 | #define GPIO_MI2S_DOUT1 31 |
| 64 | #define GPIO_MI2S_DOUT0 32 |
| 65 | #define GPIO_MI2S_MCLK 33 |
| 66 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 67 | static struct clk *sec_i2s_rx_osr_clk; |
| 68 | static struct clk *sec_i2s_rx_bit_clk; |
| 69 | |
| 70 | struct request_gpio { |
| 71 | unsigned gpio_no; |
| 72 | char *gpio_name; |
| 73 | }; |
| 74 | |
| 75 | static struct request_gpio sec_i2s_rx_gpio[] = { |
| 76 | { |
| 77 | .gpio_no = GPIO_SEC_I2S_RX_MCLK, |
| 78 | .gpio_name = "SEC_I2S_RX_MCLK", |
| 79 | }, |
| 80 | { |
| 81 | .gpio_no = GPIO_SEC_I2S_RX_SCK, |
| 82 | .gpio_name = "SEC_I2S_RX_SCK", |
| 83 | }, |
| 84 | { |
| 85 | .gpio_no = GPIO_SEC_I2S_RX_WS, |
| 86 | .gpio_name = "SEC_I2S_RX_WS", |
| 87 | }, |
| 88 | { |
| 89 | .gpio_no = GPIO_SEC_I2S_RX_DOUT, |
| 90 | .gpio_name = "SEC_I2S_RX_DOUT", |
| 91 | }, |
| 92 | }; |
| 93 | |
Kuirong Wang | 9ddff20 | 2012-03-31 14:49:39 -0700 | [diff] [blame] | 94 | static struct request_gpio mi2s_gpio[] = { |
| 95 | { |
| 96 | .gpio_no = GPIO_MI2S_WS, |
| 97 | .gpio_name = "MI2S_WS", |
| 98 | }, |
| 99 | { |
| 100 | .gpio_no = GPIO_MI2S_SCLK, |
| 101 | .gpio_name = "MI2S_SCLK", |
| 102 | }, |
| 103 | { |
| 104 | .gpio_no = GPIO_MI2S_DOUT3, |
| 105 | .gpio_name = "MI2S_DOUT3", |
| 106 | }, |
| 107 | { |
| 108 | .gpio_no = GPIO_MI2S_DOUT2, |
| 109 | .gpio_name = "MI2S_DOUT2", |
| 110 | }, |
| 111 | { |
| 112 | .gpio_no = GPIO_MI2S_DOUT1, |
| 113 | .gpio_name = "MI2S_DOUT1", |
| 114 | }, |
| 115 | { |
| 116 | .gpio_no = GPIO_MI2S_DOUT0, |
| 117 | .gpio_name = "MI2S_DOUT0", |
| 118 | }, |
| 119 | { |
| 120 | .gpio_no = GPIO_MI2S_MCLK, |
| 121 | .gpio_name = "MI2S_MCLK", |
| 122 | }, |
| 123 | }; |
| 124 | |
| 125 | static struct clk *mi2s_bit_clk; |
| 126 | |
| 127 | |
| 128 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 129 | static u32 top_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(18); |
| 130 | static u32 bottom_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(19); |
| 131 | static int msm_spk_control; |
| 132 | static int msm_ext_bottom_spk_pamp; |
| 133 | static int msm_ext_top_spk_pamp; |
| 134 | static int msm_slim_0_rx_ch = 1; |
| 135 | static int msm_slim_0_tx_ch = 1; |
Krishnankutty Kolathappilly | 543c2af | 2012-05-04 14:16:08 -0700 | [diff] [blame] | 136 | static int msm_hdmi_rx_ch = 2; |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 137 | |
| 138 | static struct clk *codec_clk; |
| 139 | static int clk_users; |
| 140 | |
| 141 | static int msm_headset_gpios_configured; |
| 142 | |
| 143 | static struct snd_soc_jack hs_jack; |
| 144 | static struct snd_soc_jack button_jack; |
| 145 | |
| 146 | static int msm_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable, |
| 147 | bool dapm); |
| 148 | |
| 149 | static 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 | |
| 162 | static 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, ¶m); |
| 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, ¶m); |
| 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 | |
| 217 | static 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 | |
| 268 | static 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 | |
| 305 | static 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 | |
| 325 | static 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 | } |
| 332 | static 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 | } |
| 345 | static 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 | |
| 383 | static 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); |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 395 | clk_prepare_enable(codec_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 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); |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 410 | clk_disable_unprepare(codec_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 411 | tabla_mclk_enable(codec, 0, dapm); |
| 412 | } |
| 413 | } |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | static 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); |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 433 | clk_prepare_enable(codec_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 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 | |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 455 | clk_disable_unprepare(codec_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 456 | tabla_mclk_enable(w->codec, 0, true); |
| 457 | } |
| 458 | break; |
| 459 | } |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static 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 | |
| 481 | static 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 | |
| 515 | static const char *spk_function[] = {"Off", "On"}; |
| 516 | static const char *slim0_rx_ch_text[] = {"One", "Two"}; |
| 517 | static const char *slim0_tx_ch_text[] = {"One", "Two", "Three", "Four"}; |
Krishnankutty Kolathappilly | 543c2af | 2012-05-04 14:16:08 -0700 | [diff] [blame] | 518 | static const char *hdmi_rx_ch_text[] = {"Two", "Three", "Four", "Five", "Six"}; |
| 519 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 520 | |
| 521 | static const struct soc_enum msm_enum[] = { |
| 522 | SOC_ENUM_SINGLE_EXT(2, spk_function), |
| 523 | SOC_ENUM_SINGLE_EXT(2, slim0_rx_ch_text), |
| 524 | SOC_ENUM_SINGLE_EXT(4, slim0_tx_ch_text), |
Krishnankutty Kolathappilly | 543c2af | 2012-05-04 14:16:08 -0700 | [diff] [blame] | 525 | SOC_ENUM_SINGLE_EXT(5, hdmi_rx_ch_text), |
| 526 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 527 | }; |
| 528 | |
| 529 | static int msm_slim_0_rx_ch_get(struct snd_kcontrol *kcontrol, |
| 530 | struct snd_ctl_elem_value *ucontrol) |
| 531 | { |
| 532 | pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__, |
| 533 | msm_slim_0_rx_ch); |
| 534 | ucontrol->value.integer.value[0] = msm_slim_0_rx_ch - 1; |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | static int msm_slim_0_rx_ch_put(struct snd_kcontrol *kcontrol, |
| 539 | struct snd_ctl_elem_value *ucontrol) |
| 540 | { |
| 541 | msm_slim_0_rx_ch = ucontrol->value.integer.value[0] + 1; |
| 542 | |
| 543 | pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__, |
| 544 | msm_slim_0_rx_ch); |
| 545 | return 1; |
| 546 | } |
| 547 | |
| 548 | static int msm_slim_0_tx_ch_get(struct snd_kcontrol *kcontrol, |
| 549 | struct snd_ctl_elem_value *ucontrol) |
| 550 | { |
| 551 | pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__, |
| 552 | msm_slim_0_tx_ch); |
| 553 | ucontrol->value.integer.value[0] = msm_slim_0_tx_ch - 1; |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static int msm_slim_0_tx_ch_put(struct snd_kcontrol *kcontrol, |
| 558 | struct snd_ctl_elem_value *ucontrol) |
| 559 | { |
| 560 | msm_slim_0_tx_ch = ucontrol->value.integer.value[0] + 1; |
| 561 | |
| 562 | pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__, |
| 563 | msm_slim_0_tx_ch); |
| 564 | return 1; |
| 565 | } |
| 566 | |
Krishnankutty Kolathappilly | 543c2af | 2012-05-04 14:16:08 -0700 | [diff] [blame] | 567 | static int msm_hdmi_rx_ch_get(struct snd_kcontrol *kcontrol, |
| 568 | struct snd_ctl_elem_value *ucontrol) |
| 569 | { |
| 570 | pr_debug("%s: msm_hdmi_rx_ch = %d\n", __func__, |
| 571 | msm_hdmi_rx_ch); |
| 572 | ucontrol->value.integer.value[0] = msm_hdmi_rx_ch - 2; |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | static int msm_hdmi_rx_ch_put(struct snd_kcontrol *kcontrol, |
| 577 | struct snd_ctl_elem_value *ucontrol) |
| 578 | { |
| 579 | msm_hdmi_rx_ch = ucontrol->value.integer.value[0] + 2; |
| 580 | |
| 581 | pr_debug("%s: msm_hdmi_rx_ch = %d\n", __func__, |
| 582 | msm_hdmi_rx_ch); |
| 583 | return 1; |
| 584 | } |
| 585 | |
| 586 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 587 | static const struct snd_kcontrol_new tabla_msm_controls[] = { |
| 588 | SOC_ENUM_EXT("Speaker Function", msm_enum[0], msm_get_spk, |
| 589 | msm_set_spk), |
| 590 | SOC_ENUM_EXT("SLIM_0_RX Channels", msm_enum[1], |
| 591 | msm_slim_0_rx_ch_get, msm_slim_0_rx_ch_put), |
| 592 | SOC_ENUM_EXT("SLIM_0_TX Channels", msm_enum[2], |
| 593 | msm_slim_0_tx_ch_get, msm_slim_0_tx_ch_put), |
Krishnankutty Kolathappilly | 543c2af | 2012-05-04 14:16:08 -0700 | [diff] [blame] | 594 | SOC_ENUM_EXT("HDMI_RX Channels", msm_enum[3], |
| 595 | msm_hdmi_rx_ch_get, msm_hdmi_rx_ch_put), |
| 596 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 597 | }; |
| 598 | |
| 599 | static void *def_tabla_mbhc_cal(void) |
| 600 | { |
| 601 | void *tabla_cal; |
| 602 | struct tabla_mbhc_btn_detect_cfg *btn_cfg; |
| 603 | u16 *btn_low, *btn_high; |
| 604 | u8 *n_ready, *n_cic, *gain; |
| 605 | |
| 606 | tabla_cal = kzalloc(TABLA_MBHC_CAL_SIZE(TABLA_MBHC_DEF_BUTTONS, |
| 607 | TABLA_MBHC_DEF_RLOADS), |
| 608 | GFP_KERNEL); |
| 609 | if (!tabla_cal) { |
| 610 | pr_err("%s: out of memory\n", __func__); |
| 611 | return NULL; |
| 612 | } |
| 613 | |
| 614 | #define S(X, Y) ((TABLA_MBHC_CAL_GENERAL_PTR(tabla_cal)->X) = (Y)) |
| 615 | S(t_ldoh, 100); |
| 616 | S(t_bg_fast_settle, 100); |
| 617 | S(t_shutdown_plug_rem, 255); |
| 618 | S(mbhc_nsa, 4); |
| 619 | S(mbhc_navg, 4); |
| 620 | #undef S |
| 621 | #define S(X, Y) ((TABLA_MBHC_CAL_PLUG_DET_PTR(tabla_cal)->X) = (Y)) |
| 622 | S(mic_current, TABLA_PID_MIC_5_UA); |
| 623 | S(hph_current, TABLA_PID_MIC_5_UA); |
| 624 | S(t_mic_pid, 100); |
| 625 | S(t_ins_complete, 250); |
| 626 | S(t_ins_retry, 200); |
| 627 | #undef S |
| 628 | #define S(X, Y) ((TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla_cal)->X) = (Y)) |
| 629 | S(v_no_mic, 30); |
| 630 | S(v_hs_max, 1550); |
| 631 | #undef S |
| 632 | #define S(X, Y) ((TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal)->X) = (Y)) |
| 633 | S(c[0], 62); |
| 634 | S(c[1], 124); |
| 635 | S(nc, 1); |
| 636 | S(n_meas, 3); |
| 637 | S(mbhc_nsc, 11); |
| 638 | S(n_btn_meas, 1); |
| 639 | S(n_btn_con, 2); |
| 640 | S(num_btn, TABLA_MBHC_DEF_BUTTONS); |
| 641 | S(v_btn_press_delta_sta, 100); |
| 642 | S(v_btn_press_delta_cic, 50); |
| 643 | #undef S |
| 644 | btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal); |
| 645 | btn_low = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_LOW); |
| 646 | btn_high = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_HIGH); |
| 647 | btn_low[0] = -50; |
| 648 | btn_high[0] = 10; |
| 649 | btn_low[1] = 11; |
| 650 | btn_high[1] = 38; |
| 651 | btn_low[2] = 39; |
| 652 | btn_high[2] = 64; |
| 653 | btn_low[3] = 65; |
| 654 | btn_high[3] = 91; |
| 655 | btn_low[4] = 92; |
| 656 | btn_high[4] = 115; |
| 657 | btn_low[5] = 116; |
| 658 | btn_high[5] = 141; |
| 659 | btn_low[6] = 142; |
| 660 | btn_high[6] = 163; |
| 661 | btn_low[7] = 164; |
| 662 | btn_high[7] = 250; |
| 663 | n_ready = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_READY); |
| 664 | n_ready[0] = 48; |
| 665 | n_ready[1] = 38; |
| 666 | n_cic = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_CIC); |
| 667 | n_cic[0] = 60; |
| 668 | n_cic[1] = 47; |
| 669 | gain = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_GAIN); |
| 670 | gain[0] = 11; |
| 671 | gain[1] = 9; |
| 672 | |
| 673 | return tabla_cal; |
| 674 | } |
| 675 | |
| 676 | static int msm_hw_params(struct snd_pcm_substream *substream, |
| 677 | struct snd_pcm_hw_params *params) |
| 678 | { |
| 679 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 680 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 681 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 682 | int ret = 0; |
| 683 | unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS]; |
| 684 | unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0; |
| 685 | |
| 686 | pr_debug("%s: ch=%d\n", __func__, |
| 687 | msm_slim_0_rx_ch); |
| 688 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 689 | ret = snd_soc_dai_get_channel_map(codec_dai, |
| 690 | &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch); |
| 691 | if (ret < 0) { |
| 692 | pr_err("%s: failed to get codec chan map\n", __func__); |
| 693 | goto end; |
| 694 | } |
| 695 | |
| 696 | ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0, |
| 697 | msm_slim_0_rx_ch, rx_ch); |
| 698 | if (ret < 0) { |
| 699 | pr_err("%s: failed to set cpu chan map\n", __func__); |
| 700 | goto end; |
| 701 | } |
| 702 | ret = snd_soc_dai_set_channel_map(codec_dai, 0, 0, |
| 703 | msm_slim_0_rx_ch, rx_ch); |
| 704 | if (ret < 0) { |
| 705 | pr_err("%s: failed to set codec channel map\n", |
| 706 | __func__); |
| 707 | goto end; |
| 708 | } |
| 709 | } else { |
| 710 | ret = snd_soc_dai_get_channel_map(codec_dai, |
| 711 | &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch); |
| 712 | if (ret < 0) { |
| 713 | pr_err("%s: failed to get codec chan map\n", __func__); |
| 714 | goto end; |
| 715 | } |
| 716 | ret = snd_soc_dai_set_channel_map(cpu_dai, |
| 717 | msm_slim_0_tx_ch, tx_ch, 0 , 0); |
| 718 | if (ret < 0) { |
| 719 | pr_err("%s: failed to set cpu chan map\n", __func__); |
| 720 | goto end; |
| 721 | } |
| 722 | ret = snd_soc_dai_set_channel_map(codec_dai, |
| 723 | msm_slim_0_tx_ch, tx_ch, 0, 0); |
| 724 | if (ret < 0) { |
| 725 | pr_err("%s: failed to set codec channel map\n", |
| 726 | __func__); |
| 727 | goto end; |
| 728 | } |
| 729 | |
| 730 | |
| 731 | } |
| 732 | end: |
| 733 | return ret; |
| 734 | } |
| 735 | |
| 736 | static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd) |
| 737 | { |
| 738 | int err; |
| 739 | struct snd_soc_codec *codec = rtd->codec; |
| 740 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 741 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 742 | |
| 743 | pr_debug("%s(), dev_name%s\n", __func__, dev_name(cpu_dai->dev)); |
| 744 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 745 | snd_soc_dapm_new_controls(dapm, msm_dapm_widgets, |
| 746 | ARRAY_SIZE(msm_dapm_widgets)); |
| 747 | |
| 748 | snd_soc_dapm_add_routes(dapm, common_audio_map, |
| 749 | ARRAY_SIZE(common_audio_map)); |
| 750 | |
| 751 | snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos"); |
| 752 | snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg"); |
| 753 | snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos"); |
| 754 | snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg"); |
| 755 | |
| 756 | snd_soc_dapm_sync(dapm); |
| 757 | |
| 758 | err = snd_soc_jack_new(codec, "Headset Jack", |
| 759 | (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR), |
| 760 | &hs_jack); |
| 761 | if (err) { |
| 762 | pr_err("failed to create new jack\n"); |
| 763 | return err; |
| 764 | } |
| 765 | |
| 766 | err = snd_soc_jack_new(codec, "Button Jack", |
| 767 | TABLA_JACK_BUTTON_MASK, &button_jack); |
| 768 | if (err) { |
| 769 | pr_err("failed to create new jack\n"); |
| 770 | return err; |
| 771 | } |
| 772 | |
| 773 | codec_clk = clk_get(cpu_dai->dev, "osr_clk"); |
| 774 | |
| 775 | err = tabla_hs_detect(codec, &mbhc_cfg); |
| 776 | |
| 777 | return err; |
| 778 | } |
| 779 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 780 | static int msm_slim_0_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
| 781 | struct snd_pcm_hw_params *params) |
| 782 | { |
| 783 | struct snd_interval *rate = hw_param_interval(params, |
| 784 | SNDRV_PCM_HW_PARAM_RATE); |
| 785 | |
| 786 | struct snd_interval *channels = hw_param_interval(params, |
| 787 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 788 | |
| 789 | pr_debug("%s()\n", __func__); |
| 790 | rate->min = rate->max = 48000; |
| 791 | channels->min = channels->max = msm_slim_0_rx_ch; |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static int msm_slim_0_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
| 797 | struct snd_pcm_hw_params *params) |
| 798 | { |
| 799 | struct snd_interval *rate = hw_param_interval(params, |
| 800 | SNDRV_PCM_HW_PARAM_RATE); |
| 801 | |
| 802 | struct snd_interval *channels = hw_param_interval(params, |
| 803 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 804 | |
| 805 | pr_debug("%s()\n", __func__); |
| 806 | rate->min = rate->max = 48000; |
| 807 | channels->min = channels->max = msm_slim_0_tx_ch; |
| 808 | |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
| 813 | struct snd_pcm_hw_params *params) |
| 814 | { |
| 815 | struct snd_interval *rate = hw_param_interval(params, |
| 816 | SNDRV_PCM_HW_PARAM_RATE); |
| 817 | |
| 818 | pr_debug("%s()\n", __func__); |
| 819 | rate->min = rate->max = 48000; |
| 820 | |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | static int msm_hdmi_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
| 825 | struct snd_pcm_hw_params *params) |
| 826 | { |
| 827 | struct snd_interval *rate = hw_param_interval(params, |
| 828 | SNDRV_PCM_HW_PARAM_RATE); |
| 829 | |
| 830 | struct snd_interval *channels = hw_param_interval(params, |
| 831 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 832 | |
| 833 | pr_debug("%s channels->min %u channels->max %u ()\n", __func__, |
| 834 | channels->min, channels->max); |
| 835 | |
| 836 | rate->min = rate->max = 48000; |
Krishnankutty Kolathappilly | 543c2af | 2012-05-04 14:16:08 -0700 | [diff] [blame] | 837 | channels->min = channels->max = msm_hdmi_rx_ch; |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
Kuirong Wang | 9ddff20 | 2012-03-31 14:49:39 -0700 | [diff] [blame] | 842 | static int msm_mi2s_free_gpios(void) |
| 843 | { |
| 844 | int i; |
| 845 | for (i = 0; i < ARRAY_SIZE(mi2s_gpio); i++) |
| 846 | gpio_free(mi2s_gpio[i].gpio_no); |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | static void msm_mi2s_shutdown(struct snd_pcm_substream *substream) |
| 851 | { |
| 852 | if (mi2s_bit_clk) { |
| 853 | clk_disable(mi2s_bit_clk); |
| 854 | clk_put(mi2s_bit_clk); |
| 855 | mi2s_bit_clk = NULL; |
| 856 | } |
| 857 | msm_mi2s_free_gpios(); |
| 858 | } |
| 859 | |
| 860 | static int configure_mi2s_gpio(void) |
| 861 | { |
| 862 | int rtn; |
| 863 | int i; |
| 864 | int j; |
| 865 | for (i = 0; i < ARRAY_SIZE(mi2s_gpio); i++) { |
| 866 | rtn = gpio_request(mi2s_gpio[i].gpio_no, |
| 867 | mi2s_gpio[i].gpio_name); |
| 868 | pr_debug("%s: gpio = %d, gpio name = %s, rtn = %d\n", |
| 869 | __func__, |
| 870 | mi2s_gpio[i].gpio_no, |
| 871 | mi2s_gpio[i].gpio_name, |
| 872 | rtn); |
| 873 | if (rtn) { |
| 874 | pr_err("%s: Failed to request gpio %d\n", |
| 875 | __func__, |
| 876 | mi2s_gpio[i].gpio_no); |
| 877 | for (j = i; j >= 0; j--) |
| 878 | gpio_free(mi2s_gpio[j].gpio_no); |
| 879 | goto err; |
| 880 | } |
| 881 | } |
| 882 | err: |
| 883 | return rtn; |
| 884 | } |
| 885 | static int msm_mi2s_startup(struct snd_pcm_substream *substream) |
| 886 | { |
| 887 | int ret = 0; |
| 888 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 889 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 890 | configure_mi2s_gpio(); |
| 891 | mi2s_bit_clk = clk_get(cpu_dai->dev, "bit_clk"); |
| 892 | if (IS_ERR(mi2s_bit_clk)) |
| 893 | return PTR_ERR(mi2s_bit_clk); |
| 894 | clk_set_rate(mi2s_bit_clk, 0); |
| 895 | ret = clk_enable(mi2s_bit_clk); |
| 896 | if (IS_ERR_VALUE(ret)) { |
| 897 | pr_err("Unable to enable mi2s_bit_clk\n"); |
| 898 | clk_put(mi2s_bit_clk); |
| 899 | return ret; |
| 900 | } |
| 901 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM); |
| 902 | if (IS_ERR_VALUE(ret)) |
| 903 | pr_err("set format for CPU dai failed\n"); |
| 904 | return ret; |
| 905 | } |
| 906 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 907 | static int msm_startup(struct snd_pcm_substream *substream) |
| 908 | { |
| 909 | pr_debug("%s(): substream = %s stream = %d\n", __func__, |
| 910 | substream->name, substream->stream); |
| 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | static void msm_shutdown(struct snd_pcm_substream *substream) |
| 915 | { |
| 916 | pr_debug("%s(): substream = %s stream = %d\n", __func__, |
| 917 | substream->name, substream->stream); |
| 918 | } |
| 919 | |
| 920 | static struct snd_soc_ops msm_be_ops = { |
| 921 | .startup = msm_startup, |
| 922 | .hw_params = msm_hw_params, |
| 923 | .shutdown = msm_shutdown, |
| 924 | }; |
| 925 | |
| 926 | static int mpq8064_sec_i2s_rx_free_gpios(void) |
| 927 | { |
| 928 | int i; |
| 929 | for (i = 0; i < ARRAY_SIZE(sec_i2s_rx_gpio); i++) |
| 930 | gpio_free(sec_i2s_rx_gpio[i].gpio_no); |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static int mpq8064_sec_i2s_rx_hw_params(struct snd_pcm_substream *substream, |
| 935 | struct snd_pcm_hw_params *params) |
| 936 | { |
| 937 | |
| 938 | int rate = params_rate(params); |
| 939 | int bit_clk_set = 0; |
| 940 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 941 | switch (params_format(params)) { |
| 942 | case SNDRV_PCM_FORMAT_S16_LE: |
| 943 | bit_clk_set = I2S_MCLK_RATE/(rate * 2 * 16); |
| 944 | clk_set_rate(sec_i2s_rx_bit_clk, bit_clk_set); |
| 945 | break; |
| 946 | case SNDRV_PCM_FORMAT_S24_LE: |
| 947 | bit_clk_set = I2S_MCLK_RATE/(rate * 2 * 24); |
| 948 | clk_set_rate(sec_i2s_rx_bit_clk, bit_clk_set); |
| 949 | break; |
| 950 | default: |
| 951 | pr_err("wrong format\n"); |
| 952 | break; |
| 953 | } |
| 954 | } |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | static void mpq8064_sec_i2s_rx_shutdown(struct snd_pcm_substream *substream) |
| 959 | { |
| 960 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 961 | if (sec_i2s_rx_bit_clk) { |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 962 | clk_disable_unprepare(sec_i2s_rx_bit_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 963 | clk_put(sec_i2s_rx_bit_clk); |
| 964 | sec_i2s_rx_bit_clk = NULL; |
| 965 | } |
| 966 | if (sec_i2s_rx_osr_clk) { |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 967 | clk_disable_unprepare(sec_i2s_rx_osr_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 968 | clk_put(sec_i2s_rx_osr_clk); |
| 969 | sec_i2s_rx_osr_clk = NULL; |
| 970 | } |
| 971 | mpq8064_sec_i2s_rx_free_gpios(); |
| 972 | } |
| 973 | pr_info("%s(): substream = %s stream = %d\n", __func__, |
| 974 | substream->name, substream->stream); |
| 975 | } |
| 976 | |
| 977 | static int configure_sec_i2s_rx_gpio(void) |
| 978 | { |
| 979 | int rtn; |
| 980 | int i; |
| 981 | int j; |
| 982 | for (i = 0; i < ARRAY_SIZE(sec_i2s_rx_gpio); i++) { |
| 983 | rtn = gpio_request(sec_i2s_rx_gpio[i].gpio_no, |
| 984 | sec_i2s_rx_gpio[i].gpio_name); |
| 985 | pr_debug("%s: gpio = %d, gpio name = %s, rtn = %d\n", |
| 986 | __func__, |
| 987 | sec_i2s_rx_gpio[i].gpio_no, |
| 988 | sec_i2s_rx_gpio[i].gpio_name, |
| 989 | rtn); |
| 990 | if (rtn) { |
| 991 | pr_err("%s: Failed to request gpio %d\n", |
| 992 | __func__, |
| 993 | sec_i2s_rx_gpio[i].gpio_no); |
| 994 | for (j = i; j >= 0; j--) |
| 995 | gpio_free(sec_i2s_rx_gpio[j].gpio_no); |
| 996 | |
| 997 | goto err; |
| 998 | } |
| 999 | } |
| 1000 | err: |
| 1001 | return rtn; |
| 1002 | } |
| 1003 | |
| 1004 | static int mpq8064_sec_i2s_rx_startup(struct snd_pcm_substream *substream) |
| 1005 | { |
| 1006 | int ret = 0; |
| 1007 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 1008 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1009 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 1010 | configure_sec_i2s_rx_gpio(); |
| 1011 | sec_i2s_rx_osr_clk = clk_get(cpu_dai->dev, "osr_clk"); |
| 1012 | if (IS_ERR(sec_i2s_rx_osr_clk)) { |
| 1013 | pr_err("Failed to get sec_i2s_rx_osr_clk\n"); |
| 1014 | return PTR_ERR(sec_i2s_rx_osr_clk); |
| 1015 | } |
| 1016 | clk_set_rate(sec_i2s_rx_osr_clk, I2S_MCLK_RATE); |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 1017 | clk_prepare_enable(sec_i2s_rx_osr_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1018 | sec_i2s_rx_bit_clk = clk_get(cpu_dai->dev, "bit_clk"); |
| 1019 | if (IS_ERR(sec_i2s_rx_bit_clk)) { |
| 1020 | pr_err("Failed to get sec i2s osr_clk\n"); |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 1021 | clk_disable_unprepare(sec_i2s_rx_osr_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1022 | clk_put(sec_i2s_rx_osr_clk); |
| 1023 | return PTR_ERR(sec_i2s_rx_bit_clk); |
| 1024 | } |
| 1025 | clk_set_rate(sec_i2s_rx_bit_clk, 1); |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 1026 | ret = clk_prepare_enable(sec_i2s_rx_bit_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1027 | if (ret != 0) { |
| 1028 | pr_err("Unable to enable sec i2s rx_bit_clk\n"); |
| 1029 | clk_put(sec_i2s_rx_bit_clk); |
Asish Bhattacharya | 4776d96 | 2012-04-25 12:08:09 +0530 | [diff] [blame] | 1030 | clk_disable_unprepare(sec_i2s_rx_osr_clk); |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1031 | clk_put(sec_i2s_rx_osr_clk); |
| 1032 | return ret; |
| 1033 | } |
| 1034 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBS_CFS); |
| 1035 | if (ret < 0) |
| 1036 | pr_err("set format for codec dai failed\n"); |
| 1037 | } |
| 1038 | pr_debug("%s: ret = %d\n", __func__, ret); |
| 1039 | pr_info("%s(): substream = %s stream = %d\n", __func__, |
| 1040 | substream->name, substream->stream); |
| 1041 | return ret; |
| 1042 | } |
| 1043 | |
| 1044 | static struct snd_soc_ops mpq8064_sec_i2s_rx_be_ops = { |
| 1045 | .startup = mpq8064_sec_i2s_rx_startup, |
| 1046 | .shutdown = mpq8064_sec_i2s_rx_shutdown, |
| 1047 | .hw_params = mpq8064_sec_i2s_rx_hw_params, |
| 1048 | }; |
| 1049 | |
Kuirong Wang | 9ddff20 | 2012-03-31 14:49:39 -0700 | [diff] [blame] | 1050 | static struct snd_soc_ops msm_mi2s_tx_be_ops = { |
| 1051 | .startup = msm_mi2s_startup, |
| 1052 | .shutdown = msm_mi2s_shutdown, |
| 1053 | }; |
| 1054 | |
| 1055 | |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1056 | /* Digital audio interface glue - connects codec <---> CPU */ |
| 1057 | static struct snd_soc_dai_link msm_dai[] = { |
| 1058 | /* FrontEnd DAI Links */ |
| 1059 | { |
| 1060 | .name = "MSM8960 Media1", |
| 1061 | .stream_name = "MultiMedia1", |
| 1062 | .cpu_dai_name = "MultiMedia1", |
| 1063 | .platform_name = "msm-pcm-dsp", |
| 1064 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1065 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
| 1066 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1067 | .codec_name = "snd-soc-dummy", |
| 1068 | .ignore_suspend = 1, |
| 1069 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1070 | .be_id = MSM_FRONTEND_DAI_MULTIMEDIA1 |
| 1071 | }, |
| 1072 | { |
| 1073 | .name = "MSM8960 Media2", |
| 1074 | .stream_name = "MultiMedia2", |
| 1075 | .cpu_dai_name = "MultiMedia2", |
Subhash Chandra Bose Naripeddy | ca9ce42 | 2012-04-16 15:35:44 -0700 | [diff] [blame] | 1076 | .platform_name = "msm-multi-ch-pcm-dsp", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1077 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1078 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
| 1079 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1080 | .codec_name = "snd-soc-dummy", |
| 1081 | .ignore_suspend = 1, |
| 1082 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1083 | .be_id = MSM_FRONTEND_DAI_MULTIMEDIA2, |
| 1084 | }, |
| 1085 | { |
| 1086 | .name = "Circuit-Switch Voice", |
| 1087 | .stream_name = "CS-Voice", |
| 1088 | .cpu_dai_name = "CS-VOICE", |
| 1089 | .platform_name = "msm-pcm-voice", |
| 1090 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1091 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1092 | .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, |
| 1093 | .ignore_suspend = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1094 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
| 1095 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1096 | .codec_name = "snd-soc-dummy", |
| 1097 | .be_id = MSM_FRONTEND_DAI_CS_VOICE, |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1098 | }, |
| 1099 | { |
| 1100 | .name = "MSM VoIP", |
| 1101 | .stream_name = "VoIP", |
| 1102 | .cpu_dai_name = "VoIP", |
| 1103 | .platform_name = "msm-voip-dsp", |
| 1104 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1105 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
| 1106 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1107 | .codec_name = "snd-soc-dummy", |
| 1108 | .ignore_suspend = 1, |
| 1109 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1110 | .be_id = MSM_FRONTEND_DAI_VOIP, |
| 1111 | }, |
| 1112 | { |
Santosh Mardi | 2b7d467 | 2012-05-18 14:42:06 +0530 | [diff] [blame^] | 1113 | .name = "MSM8960 Media3", |
| 1114 | .stream_name = "MultiMedia3", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1115 | .cpu_dai_name = "MultiMedia3", |
Santosh Mardi | 2b7d467 | 2012-05-18 14:42:06 +0530 | [diff] [blame^] | 1116 | .platform_name = "msm-pcm-dsp", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1117 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1118 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
| 1119 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1120 | .codec_name = "snd-soc-dummy", |
| 1121 | .ignore_suspend = 1, |
| 1122 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1123 | .be_id = MSM_FRONTEND_DAI_MULTIMEDIA3, |
| 1124 | }, |
| 1125 | /* Hostless PMC purpose */ |
| 1126 | { |
| 1127 | .name = "SLIMBUS_0 Hostless", |
| 1128 | .stream_name = "SLIMBUS_0 Hostless", |
| 1129 | .cpu_dai_name = "SLIMBUS0_HOSTLESS", |
| 1130 | .platform_name = "msm-pcm-hostless", |
| 1131 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1132 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1133 | .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, |
| 1134 | .ignore_suspend = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1135 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
| 1136 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1137 | .codec_name = "snd-soc-dummy", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1138 | }, |
| 1139 | { |
| 1140 | .name = "INT_FM Hostless", |
| 1141 | .stream_name = "INT_FM Hostless", |
| 1142 | .cpu_dai_name = "INT_FM_HOSTLESS", |
| 1143 | .platform_name = "msm-pcm-hostless", |
| 1144 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1145 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1146 | .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, |
| 1147 | .ignore_suspend = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1148 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
| 1149 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1150 | .codec_name = "snd-soc-dummy", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1151 | }, |
| 1152 | { |
| 1153 | .name = "MSM AFE-PCM RX", |
| 1154 | .stream_name = "AFE-PROXY RX", |
| 1155 | .cpu_dai_name = "msm-dai-q6.241", |
| 1156 | .codec_name = "msm-stub-codec.1", |
| 1157 | .codec_dai_name = "msm-stub-rx", |
| 1158 | .platform_name = "msm-pcm-afe", |
| 1159 | .ignore_suspend = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1160 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
| 1161 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1162 | .codec_name = "snd-soc-dummy", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 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, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1172 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1173 | .codec_name = "snd-soc-dummy", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1174 | }, |
| 1175 | { |
Santosh Mardi | 2b7d467 | 2012-05-18 14:42:06 +0530 | [diff] [blame^] | 1176 | .name = "MSM8960 Compr1", |
| 1177 | .stream_name = "COMPR1", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1178 | .cpu_dai_name = "MultiMedia4", |
| 1179 | .platform_name = "msm-compr-dsp", |
| 1180 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1181 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
| 1182 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1183 | .codec_name = "snd-soc-dummy", |
| 1184 | .ignore_suspend = 1, |
| 1185 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1186 | .be_id = MSM_FRONTEND_DAI_MULTIMEDIA4, |
| 1187 | }, |
| 1188 | { |
| 1189 | .name = "Voice Stub", |
| 1190 | .stream_name = "Voice Stub", |
| 1191 | .cpu_dai_name = "VOICE_STUB", |
| 1192 | .platform_name = "msm-pcm-hostless", |
| 1193 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1194 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1195 | .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, |
| 1196 | .ignore_suspend = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1197 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
| 1198 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1199 | .codec_name = "snd-soc-dummy", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1200 | }, |
Kuirong Wang | 12f0aea | 2012-04-23 10:54:51 -0700 | [diff] [blame] | 1201 | /* HDMI Hostless */ |
| 1202 | { |
| 1203 | .name = "HDMI_RX_HOSTLESS", |
| 1204 | .stream_name = "HDMI_RX_HOSTLESS", |
| 1205 | .cpu_dai_name = "HDMI_HOSTLESS", |
| 1206 | .platform_name = "msm-pcm-hostless", |
| 1207 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1208 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
Kuirong Wang | 12f0aea | 2012-04-23 10:54:51 -0700 | [diff] [blame] | 1209 | .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, |
Kuirong Wang | 12f0aea | 2012-04-23 10:54:51 -0700 | [diff] [blame] | 1210 | .ignore_suspend = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1211 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
| 1212 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1213 | .codec_name = "snd-soc-dummy", |
Kuirong Wang | 12f0aea | 2012-04-23 10:54:51 -0700 | [diff] [blame] | 1214 | }, |
Kuirong Wang | c7fbcda | 2012-05-11 16:49:52 -0700 | [diff] [blame] | 1215 | /* MI2S TX Hostless */ |
| 1216 | { |
| 1217 | .name = "MI2S_TX Hostless", |
| 1218 | .stream_name = "MI2S_TX Hostless", |
| 1219 | .cpu_dai_name = "MI2S_TX_HOSTLESS", |
| 1220 | .platform_name = "msm-pcm-hostless", |
| 1221 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1222 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
Kuirong Wang | c7fbcda | 2012-05-11 16:49:52 -0700 | [diff] [blame] | 1223 | .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, |
Kuirong Wang | c7fbcda | 2012-05-11 16:49:52 -0700 | [diff] [blame] | 1224 | .ignore_suspend = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1225 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1226 | .codec_name = "snd-soc-dummy", |
Kuirong Wang | c7fbcda | 2012-05-11 16:49:52 -0700 | [diff] [blame] | 1227 | }, |
Kuirong Wang | 12f0aea | 2012-04-23 10:54:51 -0700 | [diff] [blame] | 1228 | /* Secondary I2S RX Hostless */ |
| 1229 | { |
| 1230 | .name = "SEC_I2S_RX Hostless", |
| 1231 | .stream_name = "SEC_I2S_RX Hostless", |
| 1232 | .cpu_dai_name = "SEC_I2S_RX_HOSTLESS", |
| 1233 | .platform_name = "msm-pcm-hostless", |
| 1234 | .dynamic = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1235 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, SND_SOC_DPCM_TRIGGER_BESPOKE}, |
Kuirong Wang | 12f0aea | 2012-04-23 10:54:51 -0700 | [diff] [blame] | 1236 | .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, |
Kuirong Wang | 12f0aea | 2012-04-23 10:54:51 -0700 | [diff] [blame] | 1237 | .ignore_suspend = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1238 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
| 1239 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1240 | .codec_name = "snd-soc-dummy", |
Kuirong Wang | 12f0aea | 2012-04-23 10:54:51 -0700 | [diff] [blame] | 1241 | }, |
Santosh Mardi | 2b7d467 | 2012-05-18 14:42:06 +0530 | [diff] [blame^] | 1242 | { |
| 1243 | .name = "MSM8960 Media5", |
| 1244 | .stream_name = "MultiMedia5", |
| 1245 | .cpu_dai_name = "MultiMedia5", |
| 1246 | .platform_name = "msm-multi-ch-pcm-dsp", |
| 1247 | .dynamic = 1, |
| 1248 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, |
| 1249 | SND_SOC_DPCM_TRIGGER_BESPOKE}, |
| 1250 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1251 | .codec_name = "snd-soc-dummy", |
| 1252 | .ignore_suspend = 1, |
| 1253 | .ignore_pmdown_time = 1, /* this dailink has playback support */ |
| 1254 | .be_id = MSM_FRONTEND_DAI_MULTIMEDIA5 |
| 1255 | }, |
| 1256 | { |
| 1257 | .name = "MSM8960 Media6", |
| 1258 | .stream_name = "MultiMedia6", |
| 1259 | .cpu_dai_name = "MultiMedia6", |
| 1260 | .platform_name = "msm-multi-ch-pcm-dsp", |
| 1261 | .dynamic = 1, |
| 1262 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, |
| 1263 | SND_SOC_DPCM_TRIGGER_BESPOKE}, |
| 1264 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1265 | .codec_name = "snd-soc-dummy", |
| 1266 | .ignore_suspend = 1, |
| 1267 | .ignore_pmdown_time = 1, /* this dailink has playback support */ |
| 1268 | .be_id = MSM_FRONTEND_DAI_MULTIMEDIA6 |
| 1269 | }, |
| 1270 | { |
| 1271 | .name = "MSM8960 Compr2", |
| 1272 | .stream_name = "COMPR2", |
| 1273 | .cpu_dai_name = "MultiMedia7", |
| 1274 | .platform_name = "msm-compr-dsp", |
| 1275 | .dynamic = 1, |
| 1276 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, |
| 1277 | SND_SOC_DPCM_TRIGGER_BESPOKE}, |
| 1278 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1279 | .codec_name = "snd-soc-dummy", |
| 1280 | .ignore_suspend = 1, |
| 1281 | .ignore_pmdown_time = 1, /* this dailink has playback support */ |
| 1282 | .be_id = MSM_FRONTEND_DAI_MULTIMEDIA7, |
| 1283 | }, |
| 1284 | { |
| 1285 | .name = "MSM8960 Compr3", |
| 1286 | .stream_name = "COMPR3", |
| 1287 | .cpu_dai_name = "MultiMedia8", |
| 1288 | .platform_name = "msm-compr-dsp", |
| 1289 | .dynamic = 1, |
| 1290 | .trigger = {SND_SOC_DPCM_TRIGGER_BESPOKE, |
| 1291 | SND_SOC_DPCM_TRIGGER_BESPOKE}, |
| 1292 | .codec_dai_name = "snd-soc-dummy-dai", |
| 1293 | .codec_name = "snd-soc-dummy", |
| 1294 | .ignore_suspend = 1, |
| 1295 | .ignore_pmdown_time = 1, /* this dailink has playback support */ |
| 1296 | .be_id = MSM_FRONTEND_DAI_MULTIMEDIA8, |
| 1297 | }, |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1298 | /* Backend DAI Links */ |
| 1299 | { |
| 1300 | .name = LPASS_BE_SLIMBUS_0_RX, |
| 1301 | .stream_name = "Slimbus Playback", |
| 1302 | .cpu_dai_name = "msm-dai-q6.16384", |
| 1303 | .platform_name = "msm-pcm-routing", |
| 1304 | .codec_name = "tabla_codec", |
| 1305 | .codec_dai_name = "tabla_rx1", |
| 1306 | .no_pcm = 1, |
| 1307 | .be_id = MSM_BACKEND_DAI_SLIMBUS_0_RX, |
| 1308 | .init = &msm_audrx_init, |
| 1309 | .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup, |
| 1310 | .ops = &msm_be_ops, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1311 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1312 | }, |
| 1313 | { |
| 1314 | .name = LPASS_BE_SLIMBUS_0_TX, |
| 1315 | .stream_name = "Slimbus Capture", |
| 1316 | .cpu_dai_name = "msm-dai-q6.16385", |
| 1317 | .platform_name = "msm-pcm-routing", |
| 1318 | .codec_name = "tabla_codec", |
| 1319 | .codec_dai_name = "tabla_tx1", |
| 1320 | .no_pcm = 1, |
| 1321 | .be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX, |
| 1322 | .be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup, |
| 1323 | .ops = &msm_be_ops, |
| 1324 | }, |
| 1325 | { |
| 1326 | .name = LPASS_BE_SEC_I2S_RX, |
| 1327 | .stream_name = "Secondary I2S Playback", |
| 1328 | .cpu_dai_name = "msm-dai-q6.4", |
| 1329 | .platform_name = "msm-pcm-routing", |
| 1330 | .codec_name = "cs8427-spdif.5-0014", |
| 1331 | .codec_dai_name = "spdif_rx", |
| 1332 | .no_pcm = 1, |
| 1333 | .be_id = MSM_BACKEND_DAI_SEC_I2S_RX, |
| 1334 | .be_hw_params_fixup = msm_be_hw_params_fixup, |
| 1335 | .ops = &mpq8064_sec_i2s_rx_be_ops, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1336 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1337 | }, |
| 1338 | { |
| 1339 | .name = LPASS_BE_INT_FM_RX, |
| 1340 | .stream_name = "Internal FM Playback", |
| 1341 | .cpu_dai_name = "msm-dai-q6.12292", |
| 1342 | .platform_name = "msm-pcm-routing", |
| 1343 | .codec_name = "msm-stub-codec.1", |
| 1344 | .codec_dai_name = "msm-stub-rx", |
| 1345 | .no_pcm = 1, |
| 1346 | .be_id = MSM_BACKEND_DAI_INT_FM_RX, |
| 1347 | .be_hw_params_fixup = msm_be_hw_params_fixup, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1348 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1349 | }, |
| 1350 | { |
| 1351 | .name = LPASS_BE_INT_FM_TX, |
| 1352 | .stream_name = "Internal FM Capture", |
| 1353 | .cpu_dai_name = "msm-dai-q6.12293", |
| 1354 | .platform_name = "msm-pcm-routing", |
| 1355 | .codec_name = "msm-stub-codec.1", |
| 1356 | .codec_dai_name = "msm-stub-tx", |
| 1357 | .no_pcm = 1, |
| 1358 | .be_id = MSM_BACKEND_DAI_INT_FM_TX, |
| 1359 | .be_hw_params_fixup = msm_be_hw_params_fixup, |
| 1360 | }, |
| 1361 | /* HDMI BACK END DAI Link */ |
| 1362 | { |
| 1363 | .name = LPASS_BE_HDMI, |
| 1364 | .stream_name = "HDMI Playback", |
| 1365 | .cpu_dai_name = "msm-dai-q6-hdmi.8", |
| 1366 | .platform_name = "msm-pcm-routing", |
| 1367 | .codec_name = "msm-stub-codec.1", |
| 1368 | .codec_dai_name = "msm-stub-rx", |
| 1369 | .no_pcm = 1, |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1370 | .be_id = MSM_BACKEND_DAI_HDMI_RX, |
| 1371 | .be_hw_params_fixup = msm_hdmi_be_hw_params_fixup, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1372 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1373 | }, |
Kuirong Wang | 9ddff20 | 2012-03-31 14:49:39 -0700 | [diff] [blame] | 1374 | { |
| 1375 | .name = LPASS_BE_MI2S_TX, |
| 1376 | .stream_name = "MI2S Capture", |
Patrick Lai | 04baee94 | 2012-05-01 14:38:47 -0700 | [diff] [blame] | 1377 | .cpu_dai_name = "msm-dai-q6-mi2s", |
Kuirong Wang | 9ddff20 | 2012-03-31 14:49:39 -0700 | [diff] [blame] | 1378 | .platform_name = "msm-pcm-routing", |
| 1379 | .codec_name = "msm-stub-codec.1", |
| 1380 | .codec_dai_name = "msm-stub-tx", |
| 1381 | .no_pcm = 1, |
Kuirong Wang | 9ddff20 | 2012-03-31 14:49:39 -0700 | [diff] [blame] | 1382 | .be_id = MSM_BACKEND_DAI_MI2S_TX, |
| 1383 | .be_hw_params_fixup = msm_be_hw_params_fixup, |
| 1384 | .ops = &msm_mi2s_tx_be_ops, |
| 1385 | }, |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1386 | /* Backend AFE DAI Links */ |
| 1387 | { |
| 1388 | .name = LPASS_BE_AFE_PCM_RX, |
| 1389 | .stream_name = "AFE Playback", |
| 1390 | .cpu_dai_name = "msm-dai-q6.224", |
| 1391 | .platform_name = "msm-pcm-routing", |
| 1392 | .codec_name = "msm-stub-codec.1", |
| 1393 | .codec_dai_name = "msm-stub-rx", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1394 | .no_pcm = 1, |
| 1395 | .be_id = MSM_BACKEND_DAI_AFE_PCM_RX, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1396 | .ignore_pmdown_time = 1, /* this dainlink has playback support */ |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1397 | }, |
| 1398 | { |
| 1399 | .name = LPASS_BE_AFE_PCM_TX, |
| 1400 | .stream_name = "AFE Capture", |
| 1401 | .cpu_dai_name = "msm-dai-q6.225", |
| 1402 | .platform_name = "msm-pcm-routing", |
| 1403 | .codec_name = "msm-stub-codec.1", |
| 1404 | .codec_dai_name = "msm-stub-tx", |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1405 | .no_pcm = 1, |
| 1406 | .be_id = MSM_BACKEND_DAI_AFE_PCM_TX, |
| 1407 | }, |
| 1408 | }; |
| 1409 | |
| 1410 | |
| 1411 | static struct snd_soc_card snd_soc_card_msm = { |
| 1412 | .name = "mpq8064-tabla-snd-card", |
| 1413 | .dai_link = msm_dai, |
| 1414 | .num_links = ARRAY_SIZE(msm_dai), |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1415 | .controls = tabla_msm_controls, |
| 1416 | .num_controls = ARRAY_SIZE(tabla_msm_controls), |
Santosh Mardi | 603fbb9 | 2012-03-22 03:45:46 +0530 | [diff] [blame] | 1417 | }; |
| 1418 | |
| 1419 | static struct platform_device *msm_snd_device; |
| 1420 | |
| 1421 | static int msm_configure_headset_mic_gpios(void) |
| 1422 | { |
| 1423 | int ret; |
| 1424 | struct pm_gpio param = { |
| 1425 | .direction = PM_GPIO_DIR_OUT, |
| 1426 | .output_buffer = PM_GPIO_OUT_BUF_CMOS, |
| 1427 | .output_value = 1, |
| 1428 | .pull = PM_GPIO_PULL_NO, |
| 1429 | .vin_sel = PM_GPIO_VIN_S4, |
| 1430 | .out_strength = PM_GPIO_STRENGTH_MED, |
| 1431 | .function = PM_GPIO_FUNC_NORMAL, |
| 1432 | }; |
| 1433 | |
| 1434 | ret = gpio_request(PM8921_GPIO_PM_TO_SYS(23), "AV_SWITCH"); |
| 1435 | if (ret) { |
| 1436 | pr_err("%s: Failed to request gpio %d\n", __func__, |
| 1437 | PM8921_GPIO_PM_TO_SYS(23)); |
| 1438 | return ret; |
| 1439 | } |
| 1440 | |
| 1441 | ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(23), ¶m); |
| 1442 | if (ret) |
| 1443 | pr_err("%s: Failed to configure gpio %d\n", __func__, |
| 1444 | PM8921_GPIO_PM_TO_SYS(23)); |
| 1445 | else |
| 1446 | gpio_direction_output(PM8921_GPIO_PM_TO_SYS(23), 0); |
| 1447 | |
| 1448 | ret = gpio_request(PM8921_GPIO_PM_TO_SYS(35), "US_EURO_SWITCH"); |
| 1449 | if (ret) { |
| 1450 | pr_err("%s: Failed to request gpio %d\n", __func__, |
| 1451 | PM8921_GPIO_PM_TO_SYS(35)); |
| 1452 | gpio_free(PM8921_GPIO_PM_TO_SYS(23)); |
| 1453 | return ret; |
| 1454 | } |
| 1455 | ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(35), ¶m); |
| 1456 | if (ret) |
| 1457 | pr_err("%s: Failed to configure gpio %d\n", __func__, |
| 1458 | PM8921_GPIO_PM_TO_SYS(35)); |
| 1459 | else |
| 1460 | gpio_direction_output(PM8921_GPIO_PM_TO_SYS(35), 0); |
| 1461 | |
| 1462 | return 0; |
| 1463 | } |
| 1464 | static void msm_free_headset_mic_gpios(void) |
| 1465 | { |
| 1466 | if (msm_headset_gpios_configured) { |
| 1467 | gpio_free(PM8921_GPIO_PM_TO_SYS(23)); |
| 1468 | gpio_free(PM8921_GPIO_PM_TO_SYS(35)); |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | static int __init msm_audio_init(void) |
| 1473 | { |
| 1474 | int ret; |
| 1475 | |
| 1476 | if (socinfo_get_id() != 130) { |
| 1477 | pr_err("%s: Not the right machine type\n", __func__); |
| 1478 | return -ENODEV; |
| 1479 | } |
| 1480 | |
| 1481 | mbhc_cfg.calibration = def_tabla_mbhc_cal(); |
| 1482 | if (!mbhc_cfg.calibration) { |
| 1483 | pr_err("Calibration data allocation failed\n"); |
| 1484 | return -ENOMEM; |
| 1485 | } |
| 1486 | |
| 1487 | msm_snd_device = platform_device_alloc("soc-audio", 0); |
| 1488 | if (!msm_snd_device) { |
| 1489 | pr_err("Platform device allocation failed\n"); |
| 1490 | kfree(mbhc_cfg.calibration); |
| 1491 | return -ENOMEM; |
| 1492 | } |
| 1493 | |
| 1494 | platform_set_drvdata(msm_snd_device, &snd_soc_card_msm); |
| 1495 | ret = platform_device_add(msm_snd_device); |
| 1496 | if (ret) { |
| 1497 | platform_device_put(msm_snd_device); |
| 1498 | kfree(mbhc_cfg.calibration); |
| 1499 | return ret; |
| 1500 | } |
| 1501 | |
| 1502 | if (msm_configure_headset_mic_gpios()) { |
| 1503 | pr_err("%s Fail to configure headset mic gpios\n", __func__); |
| 1504 | msm_headset_gpios_configured = 0; |
| 1505 | } else |
| 1506 | msm_headset_gpios_configured = 1; |
| 1507 | |
| 1508 | return ret; |
| 1509 | |
| 1510 | } |
| 1511 | module_init(msm_audio_init); |
| 1512 | |
| 1513 | static void __exit msm_audio_exit(void) |
| 1514 | { |
| 1515 | if (socinfo_get_id() != 130) { |
| 1516 | pr_err("%s: Not the right machine type\n", __func__); |
| 1517 | return ; |
| 1518 | } |
| 1519 | msm_free_headset_mic_gpios(); |
| 1520 | platform_device_unregister(msm_snd_device); |
| 1521 | kfree(mbhc_cfg.calibration); |
| 1522 | } |
| 1523 | module_exit(msm_audio_exit); |
| 1524 | |
| 1525 | MODULE_DESCRIPTION("ALSA SoC mpq8064"); |
| 1526 | MODULE_LICENSE("GPL v2"); |