Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. 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/delay.h> |
| 14 | #include <linux/of_gpio.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <sound/soc.h> |
| 18 | #include <sound/pcm.h> |
| 19 | #include <sound/pcm_params.h> |
| 20 | #include <sound/q6core.h> |
| 21 | #include <linux/qdsp6v2/audio_notifier.h> |
| 22 | #include "qdsp6v2/msm-pcm-routing-v2.h" |
| 23 | #include "msm-audio-pinctrl.h" |
| 24 | #include "msmfalcon-common.h" |
| 25 | #include "msmfalcon-external.h" |
| 26 | #include "../codecs/wcd9335.h" |
| 27 | #include "../codecs/wcd934x/wcd934x.h" |
| 28 | #include "../codecs/wcd934x/wcd934x-mbhc.h" |
| 29 | |
| 30 | #define MSMFALCON_SPK_ON 1 |
| 31 | #define MSMFALCON_SPK_OFF 0 |
| 32 | |
| 33 | #define WCD9XXX_MBHC_DEF_BUTTONS 8 |
| 34 | #define WCD9XXX_MBHC_DEF_RLOADS 5 |
| 35 | #define CODEC_EXT_CLK_RATE 9600000 |
| 36 | #define ADSP_STATE_READY_TIMEOUT_MS 3000 |
| 37 | |
Laxminath Kasam | fb36dc1 | 2016-11-28 23:04:47 +0530 | [diff] [blame^] | 38 | #define TLMM_CENTER_MPM_WAKEUP_INT_EN_0 0x03596000 |
| 39 | #define LPI_GPIO_22_WAKEUP_VAL 0x00000002 |
| 40 | |
| 41 | #define TLMM_LPI_DIR_CONN_INTR1_CFG_APPS 0x0359D004 |
| 42 | #define LPI_GPIO_22_INTR1_CFG_VAL 0x01 |
| 43 | #define LPI_GPIO_22_INTR1_CFG_MASK 0x03 |
| 44 | |
| 45 | #define TLMM_LPI_GPIO_INTR_CFG1 0x0359B004 |
| 46 | #define LPI_GPIO_INTR_CFG1_VAL 0x00000113 |
| 47 | |
| 48 | #define TLMM_LPI_GPIO22_CFG 0x15078040 |
| 49 | #define LPI_GPIO22_CFG_VAL 0x0000009 |
| 50 | |
| 51 | #define TLMM_LPI_GPIO22_INOUT 0x15078044 |
| 52 | #define LPI_GPIO22_INOUT_VAL 0x00000000 |
| 53 | |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 54 | #define WSA8810_NAME_1 "wsa881x.20170211" |
| 55 | #define WSA8810_NAME_2 "wsa881x.20170212" |
| 56 | |
| 57 | static int msm_ext_spk_control = 1; |
| 58 | static struct wcd_mbhc_config *wcd_mbhc_cfg_ptr; |
| 59 | |
| 60 | struct msm_asoc_wcd93xx_codec { |
| 61 | void* (*get_afe_config_fn)(struct snd_soc_codec *codec, |
| 62 | enum afe_config_type config_type); |
| 63 | void (*mbhc_hs_detect_exit)(struct snd_soc_codec *codec); |
| 64 | }; |
| 65 | |
| 66 | static struct msm_asoc_wcd93xx_codec msm_codec_fn; |
| 67 | static struct platform_device *spdev; |
| 68 | |
Laxminath Kasam | fb36dc1 | 2016-11-28 23:04:47 +0530 | [diff] [blame^] | 69 | struct msm_snd_interrupt { |
| 70 | void __iomem *mpm_wakeup; |
| 71 | void __iomem *intr1_cfg_apps; |
| 72 | void __iomem *lpi_gpio_intr_cfg; |
| 73 | void __iomem *lpi_gpio_cfg; |
| 74 | void __iomem *lpi_gpio_inout; |
| 75 | }; |
| 76 | |
| 77 | static struct msm_snd_interrupt msm_snd_intr_lpi; |
| 78 | |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 79 | static bool is_initial_boot; |
| 80 | |
| 81 | static void *def_ext_mbhc_cal(void); |
| 82 | |
| 83 | enum { |
| 84 | SLIM_RX_0 = 0, |
| 85 | SLIM_RX_1, |
| 86 | SLIM_RX_2, |
| 87 | SLIM_RX_3, |
| 88 | SLIM_RX_4, |
| 89 | SLIM_RX_5, |
| 90 | SLIM_RX_6, |
| 91 | SLIM_RX_7, |
| 92 | SLIM_RX_MAX, |
| 93 | }; |
| 94 | |
| 95 | enum { |
| 96 | SLIM_TX_0 = 0, |
| 97 | SLIM_TX_1, |
| 98 | SLIM_TX_2, |
| 99 | SLIM_TX_3, |
| 100 | SLIM_TX_4, |
| 101 | SLIM_TX_5, |
| 102 | SLIM_TX_6, |
| 103 | SLIM_TX_7, |
| 104 | SLIM_TX_8, |
| 105 | SLIM_TX_MAX, |
| 106 | }; |
| 107 | |
| 108 | struct dev_config { |
| 109 | u32 sample_rate; |
| 110 | u32 bit_format; |
| 111 | u32 channels; |
| 112 | }; |
| 113 | |
| 114 | /* Default configuration of slimbus channels */ |
| 115 | static struct dev_config slim_rx_cfg[] = { |
| 116 | [SLIM_RX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 117 | [SLIM_RX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 118 | [SLIM_RX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 119 | [SLIM_RX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 120 | [SLIM_RX_4] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 121 | [SLIM_RX_5] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 122 | [SLIM_RX_6] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 123 | [SLIM_RX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 124 | }; |
| 125 | |
| 126 | static struct dev_config slim_tx_cfg[] = { |
| 127 | [SLIM_TX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 128 | [SLIM_TX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 129 | [SLIM_TX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 130 | [SLIM_TX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 131 | [SLIM_TX_4] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 132 | [SLIM_TX_5] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 133 | [SLIM_TX_6] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 134 | [SLIM_TX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, |
| 135 | [SLIM_TX_8] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2}, |
| 136 | }; |
| 137 | |
| 138 | static int msm_vi_feed_tx_ch = 2; |
| 139 | static const char *const slim_rx_ch_text[] = {"One", "Two"}; |
| 140 | static const char *const slim_tx_ch_text[] = {"One", "Two", "Three", "Four", |
| 141 | "Five", "Six", "Seven", |
| 142 | "Eight"}; |
| 143 | static const char *const vi_feed_ch_text[] = {"One", "Two"}; |
| 144 | static char const *bit_format_text[] = {"S16_LE", "S24_LE", "S24_3LE", |
| 145 | "S32_LE"}; |
| 146 | static char const *slim_sample_rate_text[] = {"KHZ_8", "KHZ_16", |
| 147 | "KHZ_32", "KHZ_44P1", "KHZ_48", |
| 148 | "KHZ_88P2", "KHZ_96", "KHZ_176P4", |
| 149 | "KHZ_192", "KHZ_352P8", "KHZ_384"}; |
| 150 | static const char *const spk_function_text[] = {"Off", "On"}; |
| 151 | static char const *bt_sample_rate_text[] = {"KHZ_8", "KHZ_16", "KHZ_48"}; |
| 152 | |
| 153 | static SOC_ENUM_SINGLE_EXT_DECL(spk_func_en, spk_function_text); |
| 154 | static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_chs, slim_rx_ch_text); |
| 155 | static SOC_ENUM_SINGLE_EXT_DECL(slim_2_rx_chs, slim_rx_ch_text); |
| 156 | static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_chs, slim_tx_ch_text); |
| 157 | static SOC_ENUM_SINGLE_EXT_DECL(slim_1_tx_chs, slim_tx_ch_text); |
| 158 | static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_chs, slim_rx_ch_text); |
| 159 | static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_chs, slim_rx_ch_text); |
| 160 | static SOC_ENUM_SINGLE_EXT_DECL(vi_feed_tx_chs, vi_feed_ch_text); |
| 161 | static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_format, bit_format_text); |
| 162 | static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_format, bit_format_text); |
| 163 | static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_format, bit_format_text); |
| 164 | static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_format, bit_format_text); |
| 165 | static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_sample_rate, slim_sample_rate_text); |
| 166 | static SOC_ENUM_SINGLE_EXT_DECL(slim_2_rx_sample_rate, slim_sample_rate_text); |
| 167 | static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_sample_rate, slim_sample_rate_text); |
| 168 | static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_sample_rate, slim_sample_rate_text); |
| 169 | static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_sample_rate, slim_sample_rate_text); |
| 170 | static SOC_ENUM_SINGLE_EXT_DECL(bt_sample_rate, bt_sample_rate_text); |
| 171 | |
| 172 | static int slim_get_sample_rate_val(int sample_rate) |
| 173 | { |
| 174 | int sample_rate_val = 0; |
| 175 | |
| 176 | switch (sample_rate) { |
| 177 | case SAMPLING_RATE_8KHZ: |
| 178 | sample_rate_val = 0; |
| 179 | break; |
| 180 | case SAMPLING_RATE_16KHZ: |
| 181 | sample_rate_val = 1; |
| 182 | break; |
| 183 | case SAMPLING_RATE_32KHZ: |
| 184 | sample_rate_val = 2; |
| 185 | break; |
| 186 | case SAMPLING_RATE_44P1KHZ: |
| 187 | sample_rate_val = 3; |
| 188 | break; |
| 189 | case SAMPLING_RATE_48KHZ: |
| 190 | sample_rate_val = 4; |
| 191 | break; |
| 192 | case SAMPLING_RATE_88P2KHZ: |
| 193 | sample_rate_val = 5; |
| 194 | break; |
| 195 | case SAMPLING_RATE_96KHZ: |
| 196 | sample_rate_val = 6; |
| 197 | break; |
| 198 | case SAMPLING_RATE_176P4KHZ: |
| 199 | sample_rate_val = 7; |
| 200 | break; |
| 201 | case SAMPLING_RATE_192KHZ: |
| 202 | sample_rate_val = 8; |
| 203 | break; |
| 204 | case SAMPLING_RATE_352P8KHZ: |
| 205 | sample_rate_val = 9; |
| 206 | break; |
| 207 | case SAMPLING_RATE_384KHZ: |
| 208 | sample_rate_val = 10; |
| 209 | break; |
| 210 | default: |
| 211 | sample_rate_val = 4; |
| 212 | break; |
| 213 | } |
| 214 | return sample_rate_val; |
| 215 | } |
| 216 | |
| 217 | static int slim_get_sample_rate(int value) |
| 218 | { |
| 219 | int sample_rate = 0; |
| 220 | |
| 221 | switch (value) { |
| 222 | case 0: |
| 223 | sample_rate = SAMPLING_RATE_8KHZ; |
| 224 | break; |
| 225 | case 1: |
| 226 | sample_rate = SAMPLING_RATE_16KHZ; |
| 227 | break; |
| 228 | case 2: |
| 229 | sample_rate = SAMPLING_RATE_32KHZ; |
| 230 | break; |
| 231 | case 3: |
| 232 | sample_rate = SAMPLING_RATE_44P1KHZ; |
| 233 | break; |
| 234 | case 4: |
| 235 | sample_rate = SAMPLING_RATE_48KHZ; |
| 236 | break; |
| 237 | case 5: |
| 238 | sample_rate = SAMPLING_RATE_88P2KHZ; |
| 239 | break; |
| 240 | case 6: |
| 241 | sample_rate = SAMPLING_RATE_96KHZ; |
| 242 | break; |
| 243 | case 7: |
| 244 | sample_rate = SAMPLING_RATE_176P4KHZ; |
| 245 | break; |
| 246 | case 8: |
| 247 | sample_rate = SAMPLING_RATE_192KHZ; |
| 248 | break; |
| 249 | case 9: |
| 250 | sample_rate = SAMPLING_RATE_352P8KHZ; |
| 251 | break; |
| 252 | case 10: |
| 253 | sample_rate = SAMPLING_RATE_384KHZ; |
| 254 | break; |
| 255 | default: |
| 256 | sample_rate = SAMPLING_RATE_48KHZ; |
| 257 | break; |
| 258 | } |
| 259 | return sample_rate; |
| 260 | } |
| 261 | |
| 262 | static int slim_get_bit_format_val(int bit_format) |
| 263 | { |
| 264 | int val = 0; |
| 265 | |
| 266 | switch (bit_format) { |
| 267 | case SNDRV_PCM_FORMAT_S32_LE: |
| 268 | val = 3; |
| 269 | break; |
| 270 | case SNDRV_PCM_FORMAT_S24_3LE: |
| 271 | val = 2; |
| 272 | break; |
| 273 | case SNDRV_PCM_FORMAT_S24_LE: |
| 274 | val = 1; |
| 275 | break; |
| 276 | case SNDRV_PCM_FORMAT_S16_LE: |
| 277 | default: |
| 278 | val = 0; |
| 279 | break; |
| 280 | } |
| 281 | return val; |
| 282 | } |
| 283 | |
| 284 | static int slim_get_bit_format(int val) |
| 285 | { |
| 286 | int bit_fmt = SNDRV_PCM_FORMAT_S16_LE; |
| 287 | |
| 288 | switch (val) { |
| 289 | case 0: |
| 290 | bit_fmt = SNDRV_PCM_FORMAT_S16_LE; |
| 291 | break; |
| 292 | case 1: |
| 293 | bit_fmt = SNDRV_PCM_FORMAT_S24_LE; |
| 294 | break; |
| 295 | case 2: |
| 296 | bit_fmt = SNDRV_PCM_FORMAT_S24_3LE; |
| 297 | break; |
| 298 | case 3: |
| 299 | bit_fmt = SNDRV_PCM_FORMAT_S32_LE; |
| 300 | break; |
| 301 | default: |
| 302 | bit_fmt = SNDRV_PCM_FORMAT_S16_LE; |
| 303 | break; |
| 304 | } |
| 305 | return bit_fmt; |
| 306 | } |
| 307 | |
| 308 | static int slim_get_port_idx(struct snd_kcontrol *kcontrol) |
| 309 | { |
| 310 | int port_id = 0; |
| 311 | |
| 312 | if (strnstr(kcontrol->id.name, "SLIM_0_RX", sizeof("SLIM_0_RX"))) |
| 313 | port_id = SLIM_RX_0; |
| 314 | else if (strnstr(kcontrol->id.name, "SLIM_2_RX", sizeof("SLIM_2_RX"))) |
| 315 | port_id = SLIM_RX_2; |
| 316 | else if (strnstr(kcontrol->id.name, "SLIM_5_RX", sizeof("SLIM_5_RX"))) |
| 317 | port_id = SLIM_RX_5; |
| 318 | else if (strnstr(kcontrol->id.name, "SLIM_6_RX", sizeof("SLIM_6_RX"))) |
| 319 | port_id = SLIM_RX_6; |
| 320 | else if (strnstr(kcontrol->id.name, "SLIM_0_TX", sizeof("SLIM_0_TX"))) |
| 321 | port_id = SLIM_TX_0; |
| 322 | else if (strnstr(kcontrol->id.name, "SLIM_1_TX", sizeof("SLIM_1_TX"))) |
| 323 | port_id = SLIM_TX_1; |
| 324 | else { |
| 325 | pr_err("%s: unsupported channel: %s", |
| 326 | __func__, kcontrol->id.name); |
| 327 | return -EINVAL; |
| 328 | } |
| 329 | |
| 330 | return port_id; |
| 331 | } |
| 332 | |
| 333 | static int msm_bt_sample_rate_get(struct snd_kcontrol *kcontrol, |
| 334 | struct snd_ctl_elem_value *ucontrol) |
| 335 | { |
| 336 | /* |
| 337 | * Slimbus_7_Rx/Tx sample rate values should always be in sync (same) |
| 338 | * when used for BT_SCO use case. Return either Rx or Tx sample rate |
| 339 | * value. |
| 340 | */ |
| 341 | switch (slim_rx_cfg[SLIM_RX_7].sample_rate) { |
| 342 | case SAMPLING_RATE_48KHZ: |
| 343 | ucontrol->value.integer.value[0] = 2; |
| 344 | break; |
| 345 | case SAMPLING_RATE_16KHZ: |
| 346 | ucontrol->value.integer.value[0] = 1; |
| 347 | break; |
| 348 | case SAMPLING_RATE_8KHZ: |
| 349 | default: |
| 350 | ucontrol->value.integer.value[0] = 0; |
| 351 | break; |
| 352 | } |
| 353 | pr_debug("%s: sample rate = %d", __func__, |
| 354 | slim_rx_cfg[SLIM_RX_7].sample_rate); |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | static int msm_bt_sample_rate_put(struct snd_kcontrol *kcontrol, |
| 360 | struct snd_ctl_elem_value *ucontrol) |
| 361 | { |
| 362 | switch (ucontrol->value.integer.value[0]) { |
| 363 | case 1: |
| 364 | slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_16KHZ; |
| 365 | slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_16KHZ; |
| 366 | break; |
| 367 | case 2: |
| 368 | slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_48KHZ; |
| 369 | slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_48KHZ; |
| 370 | break; |
| 371 | case 0: |
| 372 | default: |
| 373 | slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_8KHZ; |
| 374 | slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_8KHZ; |
| 375 | break; |
| 376 | } |
| 377 | pr_debug("%s: sample rates: slim7_rx = %d, slim7_tx = %d, value = %d\n", |
| 378 | __func__, |
| 379 | slim_rx_cfg[SLIM_RX_7].sample_rate, |
| 380 | slim_tx_cfg[SLIM_TX_7].sample_rate, |
| 381 | ucontrol->value.enumerated.item[0]); |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static int slim_rx_sample_rate_get(struct snd_kcontrol *kcontrol, |
| 387 | struct snd_ctl_elem_value *ucontrol) |
| 388 | { |
| 389 | int ch_num = slim_get_port_idx(kcontrol); |
| 390 | |
| 391 | if (ch_num < 0) |
| 392 | return ch_num; |
| 393 | |
| 394 | ucontrol->value.enumerated.item[0] = |
| 395 | slim_get_sample_rate_val(slim_rx_cfg[ch_num].sample_rate); |
| 396 | |
| 397 | pr_debug("%s: slim[%d]_rx_sample_rate = %d, item = %d\n", __func__, |
| 398 | ch_num, slim_rx_cfg[ch_num].sample_rate, |
| 399 | ucontrol->value.enumerated.item[0]); |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static int slim_rx_sample_rate_put(struct snd_kcontrol *kcontrol, |
| 405 | struct snd_ctl_elem_value *ucontrol) |
| 406 | { |
| 407 | int ch_num = slim_get_port_idx(kcontrol); |
| 408 | |
| 409 | if (ch_num < 0) |
| 410 | return ch_num; |
| 411 | |
| 412 | slim_rx_cfg[ch_num].sample_rate = |
| 413 | slim_get_sample_rate(ucontrol->value.enumerated.item[0]); |
| 414 | |
| 415 | pr_debug("%s: slim[%d]_rx_sample_rate = %d, item = %d\n", __func__, |
| 416 | ch_num, slim_rx_cfg[ch_num].sample_rate, |
| 417 | ucontrol->value.enumerated.item[0]); |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static int slim_tx_sample_rate_get(struct snd_kcontrol *kcontrol, |
| 423 | struct snd_ctl_elem_value *ucontrol) |
| 424 | { |
| 425 | int ch_num = slim_get_port_idx(kcontrol); |
| 426 | |
| 427 | if (ch_num < 0) |
| 428 | return ch_num; |
| 429 | |
| 430 | ucontrol->value.enumerated.item[0] = |
| 431 | slim_get_sample_rate_val(slim_tx_cfg[ch_num].sample_rate); |
| 432 | |
| 433 | pr_debug("%s: slim[%d]_tx_sample_rate = %d, item = %d\n", __func__, |
| 434 | ch_num, slim_tx_cfg[ch_num].sample_rate, |
| 435 | ucontrol->value.enumerated.item[0]); |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static int slim_tx_sample_rate_put(struct snd_kcontrol *kcontrol, |
| 441 | struct snd_ctl_elem_value *ucontrol) |
| 442 | { |
| 443 | int sample_rate = 0; |
| 444 | int ch_num = slim_get_port_idx(kcontrol); |
| 445 | |
| 446 | if (ch_num < 0) |
| 447 | return ch_num; |
| 448 | |
| 449 | sample_rate = slim_get_sample_rate(ucontrol->value.enumerated.item[0]); |
| 450 | if (sample_rate == SAMPLING_RATE_44P1KHZ) { |
| 451 | pr_err("%s: Unsupported sample rate %d: for Tx path\n", |
| 452 | __func__, sample_rate); |
| 453 | return -EINVAL; |
| 454 | } |
| 455 | slim_tx_cfg[ch_num].sample_rate = sample_rate; |
| 456 | |
| 457 | pr_debug("%s: slim[%d]_tx_sample_rate = %d, value = %d\n", __func__, |
| 458 | ch_num, slim_tx_cfg[ch_num].sample_rate, |
| 459 | ucontrol->value.enumerated.item[0]); |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | static int slim_rx_bit_format_get(struct snd_kcontrol *kcontrol, |
| 465 | struct snd_ctl_elem_value *ucontrol) |
| 466 | { |
| 467 | int ch_num = slim_get_port_idx(kcontrol); |
| 468 | |
| 469 | if (ch_num < 0) |
| 470 | return ch_num; |
| 471 | |
| 472 | ucontrol->value.enumerated.item[0] = |
| 473 | slim_get_bit_format_val(slim_rx_cfg[ch_num].bit_format); |
| 474 | |
| 475 | pr_debug("%s: slim[%d]_rx_bit_format = %d, ucontrol value = %d\n", |
| 476 | __func__, ch_num, slim_rx_cfg[ch_num].bit_format, |
| 477 | ucontrol->value.enumerated.item[0]); |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static int slim_rx_bit_format_put(struct snd_kcontrol *kcontrol, |
| 483 | struct snd_ctl_elem_value *ucontrol) |
| 484 | { |
| 485 | int ch_num = slim_get_port_idx(kcontrol); |
| 486 | |
| 487 | if (ch_num < 0) |
| 488 | return ch_num; |
| 489 | |
| 490 | slim_rx_cfg[ch_num].bit_format = |
| 491 | slim_get_bit_format(ucontrol->value.enumerated.item[0]); |
| 492 | |
| 493 | pr_debug("%s: slim[%d]_rx_bit_format = %d, ucontrol value = %d\n", |
| 494 | __func__, ch_num, slim_rx_cfg[ch_num].bit_format, |
| 495 | ucontrol->value.enumerated.item[0]); |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int slim_tx_bit_format_get(struct snd_kcontrol *kcontrol, |
| 501 | struct snd_ctl_elem_value *ucontrol) |
| 502 | { |
| 503 | int ch_num = slim_get_port_idx(kcontrol); |
| 504 | |
| 505 | if (ch_num < 0) |
| 506 | return ch_num; |
| 507 | |
| 508 | ucontrol->value.enumerated.item[0] = |
| 509 | slim_get_bit_format_val(slim_tx_cfg[ch_num].bit_format); |
| 510 | |
| 511 | pr_debug("%s: slim[%d]_tx_bit_format = %d, ucontrol value = %d\n", |
| 512 | __func__, ch_num, slim_tx_cfg[ch_num].bit_format, |
| 513 | ucontrol->value.enumerated.item[0]); |
| 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static int slim_tx_bit_format_put(struct snd_kcontrol *kcontrol, |
| 519 | struct snd_ctl_elem_value *ucontrol) |
| 520 | { |
| 521 | int ch_num = slim_get_port_idx(kcontrol); |
| 522 | |
| 523 | if (ch_num < 0) |
| 524 | return ch_num; |
| 525 | |
| 526 | slim_tx_cfg[ch_num].bit_format = |
| 527 | slim_get_bit_format(ucontrol->value.enumerated.item[0]); |
| 528 | |
| 529 | pr_debug("%s: slim[%d]_tx_bit_format = %d, ucontrol value = %d\n", |
| 530 | __func__, ch_num, slim_tx_cfg[ch_num].bit_format, |
| 531 | ucontrol->value.enumerated.item[0]); |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static int msm_slim_rx_ch_get(struct snd_kcontrol *kcontrol, |
| 537 | struct snd_ctl_elem_value *ucontrol) |
| 538 | { |
| 539 | int ch_num = slim_get_port_idx(kcontrol); |
| 540 | |
| 541 | if (ch_num < 0) |
| 542 | return ch_num; |
| 543 | |
| 544 | pr_debug("%s: msm_slim_[%d]_rx_ch = %d\n", __func__, |
| 545 | ch_num, slim_rx_cfg[ch_num].channels); |
| 546 | ucontrol->value.enumerated.item[0] = slim_rx_cfg[ch_num].channels - 1; |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | static int msm_slim_rx_ch_put(struct snd_kcontrol *kcontrol, |
| 552 | struct snd_ctl_elem_value *ucontrol) |
| 553 | { |
| 554 | int ch_num = slim_get_port_idx(kcontrol); |
| 555 | |
| 556 | if (ch_num < 0) |
| 557 | return ch_num; |
| 558 | |
| 559 | slim_rx_cfg[ch_num].channels = ucontrol->value.enumerated.item[0] + 1; |
| 560 | pr_debug("%s: msm_slim_[%d]_rx_ch = %d\n", __func__, |
| 561 | ch_num, slim_rx_cfg[ch_num].channels); |
| 562 | |
| 563 | return 1; |
| 564 | } |
| 565 | |
| 566 | static int msm_slim_tx_ch_get(struct snd_kcontrol *kcontrol, |
| 567 | struct snd_ctl_elem_value *ucontrol) |
| 568 | { |
| 569 | int ch_num = slim_get_port_idx(kcontrol); |
| 570 | |
| 571 | if (ch_num < 0) |
| 572 | return ch_num; |
| 573 | |
| 574 | pr_debug("%s: msm_slim_[%d]_tx_ch = %d\n", __func__, |
| 575 | ch_num, slim_tx_cfg[ch_num].channels); |
| 576 | ucontrol->value.enumerated.item[0] = slim_tx_cfg[ch_num].channels - 1; |
| 577 | |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | static int msm_slim_tx_ch_put(struct snd_kcontrol *kcontrol, |
| 582 | struct snd_ctl_elem_value *ucontrol) |
| 583 | { |
| 584 | int ch_num = slim_get_port_idx(kcontrol); |
| 585 | |
| 586 | if (ch_num < 0) |
| 587 | return ch_num; |
| 588 | |
| 589 | slim_tx_cfg[ch_num].channels = ucontrol->value.enumerated.item[0] + 1; |
| 590 | pr_debug("%s: msm_slim_[%d]_tx_ch = %d\n", __func__, |
| 591 | ch_num, slim_tx_cfg[ch_num].channels); |
| 592 | |
| 593 | return 1; |
| 594 | } |
| 595 | |
| 596 | static int msm_vi_feed_tx_ch_get(struct snd_kcontrol *kcontrol, |
| 597 | struct snd_ctl_elem_value *ucontrol) |
| 598 | { |
| 599 | ucontrol->value.integer.value[0] = msm_vi_feed_tx_ch - 1; |
| 600 | pr_debug("%s: msm_vi_feed_tx_ch = %ld\n", __func__, |
| 601 | ucontrol->value.integer.value[0]); |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | static int msm_vi_feed_tx_ch_put(struct snd_kcontrol *kcontrol, |
| 606 | struct snd_ctl_elem_value *ucontrol) |
| 607 | { |
| 608 | msm_vi_feed_tx_ch = ucontrol->value.integer.value[0] + 1; |
| 609 | |
| 610 | pr_debug("%s: msm_vi_feed_tx_ch = %d\n", __func__, msm_vi_feed_tx_ch); |
| 611 | return 1; |
| 612 | } |
| 613 | |
| 614 | static void *def_ext_mbhc_cal(void) |
| 615 | { |
| 616 | void *tavil_wcd_cal; |
| 617 | struct wcd_mbhc_btn_detect_cfg *btn_cfg; |
| 618 | u16 *btn_high; |
| 619 | |
| 620 | tavil_wcd_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS, |
| 621 | WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL); |
| 622 | if (!tavil_wcd_cal) |
| 623 | return NULL; |
| 624 | |
| 625 | #define S(X, Y) ((WCD_MBHC_CAL_PLUG_TYPE_PTR(tavil_wcd_cal)->X) = (Y)) |
| 626 | S(v_hs_max, 1600); |
| 627 | #undef S |
| 628 | #define S(X, Y) ((WCD_MBHC_CAL_BTN_DET_PTR(tavil_wcd_cal)->X) = (Y)) |
| 629 | S(num_btn, WCD_MBHC_DEF_BUTTONS); |
| 630 | #undef S |
| 631 | |
| 632 | btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(tavil_wcd_cal); |
| 633 | btn_high = ((void *)&btn_cfg->_v_btn_low) + |
| 634 | (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn); |
| 635 | |
| 636 | btn_high[0] = 75; |
| 637 | btn_high[1] = 150; |
| 638 | btn_high[2] = 237; |
| 639 | btn_high[3] = 500; |
| 640 | btn_high[4] = 500; |
| 641 | btn_high[5] = 500; |
| 642 | btn_high[6] = 500; |
| 643 | btn_high[7] = 500; |
| 644 | |
| 645 | return tavil_wcd_cal; |
| 646 | } |
| 647 | |
| 648 | static inline int param_is_mask(int p) |
| 649 | { |
| 650 | return (p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) && |
| 651 | (p <= SNDRV_PCM_HW_PARAM_LAST_MASK); |
| 652 | } |
| 653 | |
| 654 | static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p, int n) |
| 655 | { |
| 656 | return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]); |
| 657 | } |
| 658 | |
| 659 | |
| 660 | static void msm_ext_control(struct snd_soc_codec *codec) |
| 661 | { |
| 662 | struct snd_soc_dapm_context *dapm = |
| 663 | snd_soc_codec_get_dapm(codec); |
| 664 | |
| 665 | pr_debug("%s: msm_ext_spk_control = %d", __func__, msm_ext_spk_control); |
| 666 | if (msm_ext_spk_control == MSMFALCON_SPK_ON) { |
| 667 | snd_soc_dapm_enable_pin(dapm, "Lineout_1 amp"); |
| 668 | snd_soc_dapm_enable_pin(dapm, "Lineout_3 amp"); |
| 669 | } else { |
| 670 | snd_soc_dapm_disable_pin(dapm, "Lineout_1 amp"); |
| 671 | snd_soc_dapm_disable_pin(dapm, "Lineout_3 amp"); |
| 672 | } |
| 673 | snd_soc_dapm_sync(dapm); |
| 674 | } |
| 675 | |
| 676 | static int msm_ext_get_spk(struct snd_kcontrol *kcontrol, |
| 677 | struct snd_ctl_elem_value *ucontrol) |
| 678 | { |
| 679 | pr_debug("%s: msm_ext_spk_control = %d\n", |
| 680 | __func__, msm_ext_spk_control); |
| 681 | ucontrol->value.integer.value[0] = msm_ext_spk_control; |
| 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | static int msm_ext_set_spk(struct snd_kcontrol *kcontrol, |
| 686 | struct snd_ctl_elem_value *ucontrol) |
| 687 | { |
| 688 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 689 | |
| 690 | pr_debug("%s()\n", __func__); |
| 691 | if (msm_ext_spk_control == ucontrol->value.integer.value[0]) |
| 692 | return 0; |
| 693 | |
| 694 | msm_ext_spk_control = ucontrol->value.integer.value[0]; |
| 695 | msm_ext_control(codec); |
| 696 | return 1; |
| 697 | } |
| 698 | |
| 699 | |
| 700 | int msm_ext_enable_codec_mclk(struct snd_soc_codec *codec, int enable, |
| 701 | bool dapm) |
| 702 | { |
| 703 | int ret; |
| 704 | |
| 705 | pr_debug("%s: enable = %d\n", __func__, enable); |
| 706 | |
| 707 | if (!strcmp(dev_name(codec->dev), "tasha_codec")) |
| 708 | ret = tasha_cdc_mclk_enable(codec, enable, dapm); |
| 709 | else if (!strcmp(dev_name(codec->dev), "tavil_codec")) |
| 710 | ret = tavil_cdc_mclk_enable(codec, enable); |
| 711 | else { |
| 712 | dev_err(codec->dev, "%s: unknown codec to enable ext clk\n", |
| 713 | __func__); |
| 714 | ret = -EINVAL; |
| 715 | } |
| 716 | return ret; |
| 717 | } |
| 718 | |
| 719 | static const struct snd_kcontrol_new msm_snd_controls[] = { |
| 720 | SOC_ENUM_EXT("Speaker Function", spk_func_en, msm_ext_get_spk, |
| 721 | msm_ext_set_spk), |
| 722 | SOC_ENUM_EXT("SLIM_0_RX Channels", slim_0_rx_chs, |
| 723 | msm_slim_rx_ch_get, msm_slim_rx_ch_put), |
| 724 | SOC_ENUM_EXT("SLIM_2_RX Channels", slim_2_rx_chs, |
| 725 | msm_slim_rx_ch_get, msm_slim_rx_ch_put), |
| 726 | SOC_ENUM_EXT("SLIM_0_TX Channels", slim_0_tx_chs, |
| 727 | msm_slim_tx_ch_get, msm_slim_tx_ch_put), |
| 728 | SOC_ENUM_EXT("SLIM_1_TX Channels", slim_1_tx_chs, |
| 729 | msm_slim_tx_ch_get, msm_slim_tx_ch_put), |
| 730 | SOC_ENUM_EXT("SLIM_5_RX Channels", slim_5_rx_chs, |
| 731 | msm_slim_rx_ch_get, msm_slim_rx_ch_put), |
| 732 | SOC_ENUM_EXT("SLIM_6_RX Channels", slim_6_rx_chs, |
| 733 | msm_slim_rx_ch_get, msm_slim_rx_ch_put), |
| 734 | SOC_ENUM_EXT("VI_FEED_TX Channels", vi_feed_tx_chs, |
| 735 | msm_vi_feed_tx_ch_get, msm_vi_feed_tx_ch_put), |
| 736 | SOC_ENUM_EXT("SLIM_0_RX Format", slim_0_rx_format, |
| 737 | slim_rx_bit_format_get, slim_rx_bit_format_put), |
| 738 | SOC_ENUM_EXT("SLIM_5_RX Format", slim_5_rx_format, |
| 739 | slim_rx_bit_format_get, slim_rx_bit_format_put), |
| 740 | SOC_ENUM_EXT("SLIM_6_RX Format", slim_6_rx_format, |
| 741 | slim_rx_bit_format_get, slim_rx_bit_format_put), |
| 742 | SOC_ENUM_EXT("SLIM_0_TX Format", slim_0_tx_format, |
| 743 | slim_tx_bit_format_get, slim_tx_bit_format_put), |
| 744 | SOC_ENUM_EXT("SLIM_0_RX SampleRate", slim_0_rx_sample_rate, |
| 745 | slim_rx_sample_rate_get, slim_rx_sample_rate_put), |
| 746 | SOC_ENUM_EXT("SLIM_2_RX SampleRate", slim_2_rx_sample_rate, |
| 747 | slim_rx_sample_rate_get, slim_rx_sample_rate_put), |
| 748 | SOC_ENUM_EXT("SLIM_0_TX SampleRate", slim_0_tx_sample_rate, |
| 749 | slim_tx_sample_rate_get, slim_tx_sample_rate_put), |
| 750 | SOC_ENUM_EXT("SLIM_5_RX SampleRate", slim_5_rx_sample_rate, |
| 751 | slim_rx_sample_rate_get, slim_rx_sample_rate_put), |
| 752 | SOC_ENUM_EXT("SLIM_6_RX SampleRate", slim_6_rx_sample_rate, |
| 753 | slim_rx_sample_rate_get, slim_rx_sample_rate_put), |
| 754 | SOC_ENUM_EXT("BT SampleRate", bt_sample_rate, |
| 755 | msm_bt_sample_rate_get, |
| 756 | msm_bt_sample_rate_put), |
| 757 | }; |
| 758 | |
| 759 | static int msm_slim_get_ch_from_beid(int32_t be_id) |
| 760 | { |
| 761 | int ch_id = 0; |
| 762 | |
| 763 | switch (be_id) { |
| 764 | case MSM_BACKEND_DAI_SLIMBUS_0_RX: |
| 765 | ch_id = SLIM_RX_0; |
| 766 | break; |
| 767 | case MSM_BACKEND_DAI_SLIMBUS_1_RX: |
| 768 | ch_id = SLIM_RX_1; |
| 769 | break; |
| 770 | case MSM_BACKEND_DAI_SLIMBUS_2_RX: |
| 771 | ch_id = SLIM_RX_2; |
| 772 | break; |
| 773 | case MSM_BACKEND_DAI_SLIMBUS_3_RX: |
| 774 | ch_id = SLIM_RX_3; |
| 775 | break; |
| 776 | case MSM_BACKEND_DAI_SLIMBUS_4_RX: |
| 777 | ch_id = SLIM_RX_4; |
| 778 | break; |
| 779 | case MSM_BACKEND_DAI_SLIMBUS_6_RX: |
| 780 | ch_id = SLIM_RX_6; |
| 781 | break; |
| 782 | case MSM_BACKEND_DAI_SLIMBUS_0_TX: |
| 783 | ch_id = SLIM_TX_0; |
| 784 | break; |
| 785 | case MSM_BACKEND_DAI_SLIMBUS_3_TX: |
| 786 | ch_id = SLIM_TX_3; |
| 787 | break; |
| 788 | default: |
| 789 | ch_id = SLIM_RX_0; |
| 790 | break; |
| 791 | } |
| 792 | |
| 793 | return ch_id; |
| 794 | } |
| 795 | |
| 796 | static void param_set_mask(struct snd_pcm_hw_params *p, int n, unsigned int bit) |
| 797 | { |
| 798 | if (bit >= SNDRV_MASK_MAX) |
| 799 | return; |
| 800 | if (param_is_mask(n)) { |
| 801 | struct snd_mask *m = param_to_mask(p, n); |
| 802 | |
| 803 | m->bits[0] = 0; |
| 804 | m->bits[1] = 0; |
| 805 | m->bits[bit >> 5] |= (1 << (bit & 31)); |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * msm_ext_be_hw_params_fixup - updates settings of ALSA BE hw params. |
| 811 | * |
| 812 | * @rtd: runtime dailink instance |
| 813 | * @params: HW params of associated backend dailink. |
| 814 | * |
| 815 | * Returns 0 on success or rc on failure. |
| 816 | */ |
| 817 | int msm_ext_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
| 818 | struct snd_pcm_hw_params *params) |
| 819 | { |
| 820 | struct snd_soc_dai_link *dai_link = rtd->dai_link; |
| 821 | struct snd_interval *rate = hw_param_interval(params, |
| 822 | SNDRV_PCM_HW_PARAM_RATE); |
| 823 | struct snd_interval *channels = hw_param_interval(params, |
| 824 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 825 | int rc = 0; |
| 826 | int idx; |
| 827 | void *config = NULL; |
| 828 | struct snd_soc_codec *codec = rtd->codec; |
| 829 | |
| 830 | pr_debug("%s: format = %d, rate = %d\n", |
| 831 | __func__, params_format(params), params_rate(params)); |
| 832 | |
| 833 | switch (dai_link->be_id) { |
| 834 | case MSM_BACKEND_DAI_SLIMBUS_0_RX: |
| 835 | case MSM_BACKEND_DAI_SLIMBUS_1_RX: |
| 836 | case MSM_BACKEND_DAI_SLIMBUS_2_RX: |
| 837 | case MSM_BACKEND_DAI_SLIMBUS_3_RX: |
| 838 | case MSM_BACKEND_DAI_SLIMBUS_4_RX: |
| 839 | case MSM_BACKEND_DAI_SLIMBUS_6_RX: |
| 840 | idx = msm_slim_get_ch_from_beid(dai_link->be_id); |
| 841 | param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, |
| 842 | slim_rx_cfg[idx].bit_format); |
| 843 | rate->min = rate->max = slim_rx_cfg[idx].sample_rate; |
| 844 | channels->min = channels->max = slim_rx_cfg[idx].channels; |
| 845 | break; |
| 846 | |
| 847 | case MSM_BACKEND_DAI_SLIMBUS_0_TX: |
| 848 | case MSM_BACKEND_DAI_SLIMBUS_3_TX: |
| 849 | idx = msm_slim_get_ch_from_beid(dai_link->be_id); |
| 850 | param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, |
| 851 | slim_tx_cfg[idx].bit_format); |
| 852 | rate->min = rate->max = slim_tx_cfg[idx].sample_rate; |
| 853 | channels->min = channels->max = slim_tx_cfg[idx].channels; |
| 854 | break; |
| 855 | |
| 856 | case MSM_BACKEND_DAI_SLIMBUS_1_TX: |
| 857 | param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, |
| 858 | slim_tx_cfg[1].bit_format); |
| 859 | rate->min = rate->max = slim_tx_cfg[1].sample_rate; |
| 860 | channels->min = channels->max = slim_tx_cfg[1].channels; |
| 861 | break; |
| 862 | |
| 863 | case MSM_BACKEND_DAI_SLIMBUS_4_TX: |
| 864 | param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, |
| 865 | SNDRV_PCM_FORMAT_S32_LE); |
| 866 | rate->min = rate->max = SAMPLING_RATE_8KHZ; |
| 867 | channels->min = channels->max = msm_vi_feed_tx_ch; |
| 868 | break; |
| 869 | |
| 870 | case MSM_BACKEND_DAI_SLIMBUS_5_RX: |
| 871 | param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, |
| 872 | slim_rx_cfg[5].bit_format); |
| 873 | rate->min = rate->max = slim_rx_cfg[5].sample_rate; |
| 874 | channels->min = channels->max = slim_rx_cfg[5].channels; |
| 875 | break; |
| 876 | |
| 877 | case MSM_BACKEND_DAI_SLIMBUS_5_TX: |
| 878 | rate->min = rate->max = SAMPLING_RATE_16KHZ; |
| 879 | channels->min = channels->max = 1; |
| 880 | |
| 881 | config = msm_codec_fn.get_afe_config_fn(codec, |
| 882 | AFE_SLIMBUS_SLAVE_PORT_CONFIG); |
| 883 | if (config) { |
| 884 | rc = afe_set_config(AFE_SLIMBUS_SLAVE_PORT_CONFIG, |
| 885 | config, SLIMBUS_5_TX); |
| 886 | if (rc) |
| 887 | pr_err("%s: Failed to set slimbus slave port config %d\n", |
| 888 | __func__, rc); |
| 889 | } |
| 890 | break; |
| 891 | |
| 892 | case MSM_BACKEND_DAI_SLIMBUS_7_RX: |
| 893 | param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, |
| 894 | slim_rx_cfg[SLIM_RX_7].bit_format); |
| 895 | rate->min = rate->max = slim_rx_cfg[SLIM_RX_7].sample_rate; |
| 896 | channels->min = channels->max = |
| 897 | slim_rx_cfg[SLIM_RX_7].channels; |
| 898 | break; |
| 899 | |
| 900 | case MSM_BACKEND_DAI_SLIMBUS_7_TX: |
| 901 | rate->min = rate->max = slim_tx_cfg[SLIM_TX_7].sample_rate; |
| 902 | channels->min = channels->max = |
| 903 | slim_tx_cfg[SLIM_TX_7].channels; |
| 904 | break; |
| 905 | |
| 906 | case MSM_BACKEND_DAI_SLIMBUS_8_TX: |
| 907 | rate->min = rate->max = slim_tx_cfg[SLIM_TX_8].sample_rate; |
| 908 | channels->min = channels->max = |
| 909 | slim_tx_cfg[SLIM_TX_8].channels; |
| 910 | break; |
| 911 | |
| 912 | default: |
| 913 | rate->min = rate->max = SAMPLING_RATE_48KHZ; |
| 914 | break; |
| 915 | } |
| 916 | return rc; |
| 917 | } |
| 918 | EXPORT_SYMBOL(msm_ext_be_hw_params_fixup); |
| 919 | |
| 920 | /** |
| 921 | * msm_snd_hw_params - hw params ops of backend dailink. |
| 922 | * |
| 923 | * @substream: PCM stream of associated backend dailink. |
| 924 | * @params: HW params of associated backend dailink. |
| 925 | * |
| 926 | * Returns 0 on success or ret on failure. |
| 927 | */ |
| 928 | int msm_snd_hw_params(struct snd_pcm_substream *substream, |
| 929 | struct snd_pcm_hw_params *params) |
| 930 | { |
| 931 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 932 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 933 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 934 | struct snd_soc_dai_link *dai_link = rtd->dai_link; |
| 935 | |
| 936 | int ret = 0; |
| 937 | u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS]; |
| 938 | u32 rx_ch_cnt = 0, tx_ch_cnt = 0; |
| 939 | u32 user_set_tx_ch = 0; |
| 940 | u32 rx_ch_count; |
| 941 | |
| 942 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 943 | ret = snd_soc_dai_get_channel_map(codec_dai, |
| 944 | &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch); |
| 945 | if (ret < 0) { |
| 946 | pr_err("%s: failed to get codec chan map, err:%d\n", |
| 947 | __func__, ret); |
| 948 | goto err_ch_map; |
| 949 | } |
| 950 | if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_5_RX) { |
| 951 | pr_debug("%s: rx_5_ch=%d\n", __func__, |
| 952 | slim_rx_cfg[5].channels); |
| 953 | rx_ch_count = slim_rx_cfg[5].channels; |
| 954 | } else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_2_RX) { |
| 955 | pr_debug("%s: rx_2_ch=%d\n", __func__, |
| 956 | slim_rx_cfg[2].channels); |
| 957 | rx_ch_count = slim_rx_cfg[2].channels; |
| 958 | } else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_6_RX) { |
| 959 | pr_debug("%s: rx_6_ch=%d\n", __func__, |
| 960 | slim_rx_cfg[6].channels); |
| 961 | rx_ch_count = slim_rx_cfg[6].channels; |
| 962 | } else { |
| 963 | pr_debug("%s: rx_0_ch=%d\n", __func__, |
| 964 | slim_rx_cfg[0].channels); |
| 965 | rx_ch_count = slim_rx_cfg[0].channels; |
| 966 | } |
| 967 | ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0, |
| 968 | rx_ch_count, rx_ch); |
| 969 | if (ret < 0) { |
| 970 | pr_err("%s: failed to set cpu chan map, err:%d\n", |
| 971 | __func__, ret); |
| 972 | goto err_ch_map; |
| 973 | } |
| 974 | } else { |
| 975 | pr_debug("%s: %s_tx_dai_id_%d_ch=%d\n", __func__, |
| 976 | codec_dai->name, codec_dai->id, user_set_tx_ch); |
| 977 | ret = snd_soc_dai_get_channel_map(codec_dai, |
| 978 | &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch); |
| 979 | if (ret < 0) { |
| 980 | pr_err("%s: failed to get codec chan map\n, err:%d\n", |
| 981 | __func__, ret); |
| 982 | goto err_ch_map; |
| 983 | } |
| 984 | /* For <codec>_tx1 case */ |
| 985 | if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_0_TX) |
| 986 | user_set_tx_ch = slim_tx_cfg[0].channels; |
| 987 | /* For <codec>_tx3 case */ |
| 988 | else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_1_TX) |
| 989 | user_set_tx_ch = slim_tx_cfg[1].channels; |
| 990 | else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_4_TX) |
| 991 | user_set_tx_ch = msm_vi_feed_tx_ch; |
| 992 | else |
| 993 | user_set_tx_ch = tx_ch_cnt; |
| 994 | |
| 995 | pr_debug("%s: msm_slim_0_tx_ch(%d) user_set_tx_ch(%d) tx_ch_cnt(%d), be_id (%d)\n", |
| 996 | __func__, slim_tx_cfg[0].channels, user_set_tx_ch, |
| 997 | tx_ch_cnt, dai_link->be_id); |
| 998 | |
| 999 | ret = snd_soc_dai_set_channel_map(cpu_dai, |
| 1000 | user_set_tx_ch, tx_ch, 0, 0); |
| 1001 | if (ret < 0) |
| 1002 | pr_err("%s: failed to set cpu chan map, err:%d\n", |
| 1003 | __func__, ret); |
| 1004 | } |
| 1005 | |
| 1006 | err_ch_map: |
| 1007 | return ret; |
| 1008 | } |
| 1009 | EXPORT_SYMBOL(msm_snd_hw_params); |
| 1010 | |
| 1011 | /** |
| 1012 | * msm_ext_slimbus_2_hw_params - hw params ops of slimbus_2 BE. |
| 1013 | * |
| 1014 | * @substream: PCM stream of associated backend dailink. |
| 1015 | * @params: HW params of associated backend dailink. |
| 1016 | * |
| 1017 | * Returns 0 on success or ret on failure. |
| 1018 | */ |
| 1019 | int msm_ext_slimbus_2_hw_params(struct snd_pcm_substream *substream, |
| 1020 | struct snd_pcm_hw_params *params) |
| 1021 | { |
| 1022 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 1023 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 1024 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1025 | int ret = 0; |
| 1026 | unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS]; |
| 1027 | unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0; |
| 1028 | unsigned int num_tx_ch = 0; |
| 1029 | unsigned int num_rx_ch = 0; |
| 1030 | |
| 1031 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 1032 | num_rx_ch = params_channels(params); |
| 1033 | pr_debug("%s: %s rx_dai_id = %d num_ch = %d\n", __func__, |
| 1034 | codec_dai->name, codec_dai->id, num_rx_ch); |
| 1035 | ret = snd_soc_dai_get_channel_map(codec_dai, |
| 1036 | &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch); |
| 1037 | if (ret < 0) { |
| 1038 | pr_err("%s: failed to get codec chan map, err:%d\n", |
| 1039 | __func__, ret); |
| 1040 | goto end; |
| 1041 | } |
| 1042 | ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0, |
| 1043 | num_rx_ch, rx_ch); |
| 1044 | if (ret < 0) { |
| 1045 | pr_err("%s: failed to set cpu chan map, err:%d\n", |
| 1046 | __func__, ret); |
| 1047 | goto end; |
| 1048 | } |
| 1049 | } else { |
| 1050 | num_tx_ch = params_channels(params); |
| 1051 | pr_debug("%s: %s tx_dai_id = %d num_ch = %d\n", __func__, |
| 1052 | codec_dai->name, codec_dai->id, num_tx_ch); |
| 1053 | ret = snd_soc_dai_get_channel_map(codec_dai, |
| 1054 | &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch); |
| 1055 | if (ret < 0) { |
| 1056 | pr_err("%s: failed to get codec chan map, err:%d\n", |
| 1057 | __func__, ret); |
| 1058 | goto end; |
| 1059 | } |
| 1060 | ret = snd_soc_dai_set_channel_map(cpu_dai, |
| 1061 | num_tx_ch, tx_ch, 0, 0); |
| 1062 | if (ret < 0) { |
| 1063 | pr_err("%s: failed to set cpu chan map, err:%d\n", |
| 1064 | __func__, ret); |
| 1065 | goto end; |
| 1066 | } |
| 1067 | } |
| 1068 | end: |
| 1069 | return ret; |
| 1070 | } |
| 1071 | EXPORT_SYMBOL(msm_ext_slimbus_2_hw_params); |
| 1072 | |
| 1073 | /** |
| 1074 | * msm_snd_cpe_hw_params - hw params ops of CPE backend. |
| 1075 | * |
| 1076 | * @substream: PCM stream of associated backend dailink. |
| 1077 | * @params: HW params of associated backend dailink. |
| 1078 | * |
| 1079 | * Returns 0 on success or ret on failure. |
| 1080 | */ |
| 1081 | int msm_snd_cpe_hw_params(struct snd_pcm_substream *substream, |
| 1082 | struct snd_pcm_hw_params *params) |
| 1083 | { |
| 1084 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 1085 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 1086 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1087 | struct snd_soc_dai_link *dai_link = rtd->dai_link; |
| 1088 | int ret = 0; |
| 1089 | u32 tx_ch[SLIM_MAX_TX_PORTS]; |
| 1090 | u32 tx_ch_cnt = 0; |
| 1091 | |
| 1092 | if (substream->stream != SNDRV_PCM_STREAM_CAPTURE) { |
| 1093 | pr_err("%s: Invalid stream type %d\n", |
| 1094 | __func__, substream->stream); |
| 1095 | ret = -EINVAL; |
| 1096 | goto end; |
| 1097 | } |
| 1098 | |
| 1099 | pr_debug("%s: %s_tx_dai_id_%d\n", __func__, |
| 1100 | codec_dai->name, codec_dai->id); |
| 1101 | ret = snd_soc_dai_get_channel_map(codec_dai, |
| 1102 | &tx_ch_cnt, tx_ch, NULL, NULL); |
| 1103 | if (ret < 0) { |
| 1104 | pr_err("%s: failed to get codec chan map\n, err:%d\n", |
| 1105 | __func__, ret); |
| 1106 | goto end; |
| 1107 | } |
| 1108 | |
| 1109 | pr_debug("%s: tx_ch_cnt(%d) be_id %d\n", |
| 1110 | __func__, tx_ch_cnt, dai_link->be_id); |
| 1111 | |
| 1112 | ret = snd_soc_dai_set_channel_map(cpu_dai, |
| 1113 | tx_ch_cnt, tx_ch, 0, 0); |
| 1114 | if (ret < 0) { |
| 1115 | pr_err("%s: failed to set cpu chan map, err:%d\n", |
| 1116 | __func__, ret); |
| 1117 | goto end; |
| 1118 | } |
| 1119 | end: |
| 1120 | return ret; |
| 1121 | } |
| 1122 | EXPORT_SYMBOL(msm_snd_cpe_hw_params); |
| 1123 | |
| 1124 | static int msm_afe_set_config(struct snd_soc_codec *codec) |
| 1125 | { |
| 1126 | int rc; |
| 1127 | void *config_data; |
| 1128 | |
| 1129 | pr_debug("%s: enter\n", __func__); |
| 1130 | |
| 1131 | if (!msm_codec_fn.get_afe_config_fn) { |
| 1132 | dev_err(codec->dev, "%s: codec get afe config not init'ed\n", |
| 1133 | __func__); |
| 1134 | return -EINVAL; |
| 1135 | } |
| 1136 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1137 | AFE_CDC_REGISTERS_CONFIG); |
| 1138 | if (config_data) { |
| 1139 | rc = afe_set_config(AFE_CDC_REGISTERS_CONFIG, config_data, 0); |
| 1140 | if (rc) { |
| 1141 | pr_err("%s: Failed to set codec registers config %d\n", |
| 1142 | __func__, rc); |
| 1143 | return rc; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1148 | AFE_CDC_REGISTER_PAGE_CONFIG); |
| 1149 | if (config_data) { |
| 1150 | rc = afe_set_config(AFE_CDC_REGISTER_PAGE_CONFIG, config_data, |
| 1151 | 0); |
| 1152 | if (rc) |
| 1153 | pr_err("%s: Failed to set cdc register page config\n", |
| 1154 | __func__); |
| 1155 | } |
| 1156 | |
| 1157 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1158 | AFE_SLIMBUS_SLAVE_CONFIG); |
| 1159 | if (config_data) { |
| 1160 | rc = afe_set_config(AFE_SLIMBUS_SLAVE_CONFIG, config_data, 0); |
| 1161 | if (rc) { |
| 1162 | pr_err("%s: Failed to set slimbus slave config %d\n", |
| 1163 | __func__, rc); |
| 1164 | return rc; |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1169 | AFE_AANC_VERSION); |
| 1170 | if (config_data) { |
| 1171 | rc = afe_set_config(AFE_AANC_VERSION, config_data, 0); |
| 1172 | if (rc) { |
| 1173 | pr_err("%s: Failed to set AANC version %d\n", |
| 1174 | __func__, rc); |
| 1175 | return rc; |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1180 | AFE_CDC_CLIP_REGISTERS_CONFIG); |
| 1181 | if (config_data) { |
| 1182 | rc = afe_set_config(AFE_CDC_CLIP_REGISTERS_CONFIG, |
| 1183 | config_data, 0); |
| 1184 | if (rc) { |
| 1185 | pr_err("%s: Failed to set clip registers %d\n", |
| 1186 | __func__, rc); |
| 1187 | return rc; |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1192 | AFE_CLIP_BANK_SEL); |
| 1193 | if (config_data) { |
| 1194 | rc = afe_set_config(AFE_CLIP_BANK_SEL, |
| 1195 | config_data, 0); |
| 1196 | if (rc) { |
| 1197 | pr_err("%s: Failed to set AFE bank selection %d\n", |
| 1198 | __func__, rc); |
| 1199 | return rc; |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1204 | AFE_CDC_REGISTER_PAGE_CONFIG); |
| 1205 | if (config_data) { |
| 1206 | rc = afe_set_config(AFE_CDC_REGISTER_PAGE_CONFIG, config_data, |
| 1207 | 0); |
| 1208 | if (rc) |
| 1209 | pr_err("%s: Failed to set cdc register page config\n", |
| 1210 | __func__); |
| 1211 | } |
| 1212 | |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
| 1216 | static void msm_afe_clear_config(void) |
| 1217 | { |
| 1218 | afe_clear_config(AFE_CDC_REGISTERS_CONFIG); |
| 1219 | afe_clear_config(AFE_SLIMBUS_SLAVE_CONFIG); |
| 1220 | } |
| 1221 | |
Laxminath Kasam | fb36dc1 | 2016-11-28 23:04:47 +0530 | [diff] [blame^] | 1222 | static void msm_snd_interrupt_config(void) |
| 1223 | { |
| 1224 | int val; |
| 1225 | |
| 1226 | val = ioread32(msm_snd_intr_lpi.mpm_wakeup); |
| 1227 | val |= LPI_GPIO_22_WAKEUP_VAL; |
| 1228 | iowrite32(val, msm_snd_intr_lpi.mpm_wakeup); |
| 1229 | |
| 1230 | val = ioread32(msm_snd_intr_lpi.intr1_cfg_apps); |
| 1231 | val &= ~(LPI_GPIO_22_INTR1_CFG_MASK); |
| 1232 | val |= LPI_GPIO_22_INTR1_CFG_VAL; |
| 1233 | iowrite32(val, msm_snd_intr_lpi.intr1_cfg_apps); |
| 1234 | |
| 1235 | iowrite32(LPI_GPIO_INTR_CFG1_VAL, |
| 1236 | msm_snd_intr_lpi.lpi_gpio_intr_cfg); |
| 1237 | iowrite32(LPI_GPIO22_CFG_VAL, |
| 1238 | msm_snd_intr_lpi.lpi_gpio_cfg); |
| 1239 | iowrite32(LPI_GPIO22_INOUT_VAL, |
| 1240 | msm_snd_intr_lpi.lpi_gpio_inout); |
| 1241 | } |
| 1242 | |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 1243 | static int msm_adsp_power_up_config(struct snd_soc_codec *codec) |
| 1244 | { |
| 1245 | int ret = 0; |
| 1246 | unsigned long timeout; |
| 1247 | int adsp_ready = 0; |
| 1248 | |
| 1249 | timeout = jiffies + |
| 1250 | msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS); |
| 1251 | |
| 1252 | do { |
| 1253 | if (q6core_is_adsp_ready()) { |
| 1254 | pr_debug("%s: ADSP Audio is ready\n", __func__); |
| 1255 | adsp_ready = 1; |
| 1256 | break; |
| 1257 | } |
| 1258 | /* |
| 1259 | * ADSP will be coming up after subsystem restart and |
| 1260 | * it might not be fully up when the control reaches |
| 1261 | * here. So, wait for 50msec before checking ADSP state |
| 1262 | */ |
| 1263 | msleep(50); |
| 1264 | } while (time_after(timeout, jiffies)); |
| 1265 | |
| 1266 | if (!adsp_ready) { |
| 1267 | pr_err("%s: timed out waiting for ADSP Audio\n", __func__); |
| 1268 | ret = -ETIMEDOUT; |
| 1269 | goto err_fail; |
| 1270 | } |
Laxminath Kasam | fb36dc1 | 2016-11-28 23:04:47 +0530 | [diff] [blame^] | 1271 | msm_snd_interrupt_config(); |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 1272 | |
| 1273 | ret = msm_afe_set_config(codec); |
| 1274 | if (ret) |
| 1275 | pr_err("%s: Failed to set AFE config. err %d\n", |
| 1276 | __func__, ret); |
| 1277 | |
| 1278 | return 0; |
| 1279 | |
| 1280 | err_fail: |
| 1281 | return ret; |
| 1282 | } |
| 1283 | |
| 1284 | static int msmfalcon_notifier_service_cb(struct notifier_block *this, |
| 1285 | unsigned long opcode, void *ptr) |
| 1286 | { |
| 1287 | int ret; |
| 1288 | struct snd_soc_card *card = NULL; |
| 1289 | const char *be_dl_name = LPASS_BE_SLIMBUS_0_RX; |
| 1290 | struct snd_soc_pcm_runtime *rtd; |
| 1291 | struct snd_soc_codec *codec; |
| 1292 | |
| 1293 | pr_debug("%s: Service opcode 0x%lx\n", __func__, opcode); |
| 1294 | |
| 1295 | switch (opcode) { |
| 1296 | case AUDIO_NOTIFIER_SERVICE_DOWN: |
| 1297 | /* |
| 1298 | * Use flag to ignore initial boot notifications |
| 1299 | * On initial boot msm_adsp_power_up_config is |
| 1300 | * called on init. There is no need to clear |
| 1301 | * and set the config again on initial boot. |
| 1302 | */ |
| 1303 | if (is_initial_boot) |
| 1304 | break; |
| 1305 | msm_afe_clear_config(); |
| 1306 | break; |
| 1307 | case AUDIO_NOTIFIER_SERVICE_UP: |
| 1308 | if (is_initial_boot) { |
| 1309 | is_initial_boot = false; |
| 1310 | break; |
| 1311 | } |
| 1312 | if (!spdev) |
| 1313 | return -EINVAL; |
| 1314 | |
| 1315 | card = platform_get_drvdata(spdev); |
| 1316 | rtd = snd_soc_get_pcm_runtime(card, be_dl_name); |
| 1317 | if (!rtd) { |
| 1318 | dev_err(card->dev, |
| 1319 | "%s: snd_soc_get_pcm_runtime for %s failed!\n", |
| 1320 | __func__, be_dl_name); |
| 1321 | ret = -EINVAL; |
| 1322 | goto done; |
| 1323 | } |
| 1324 | codec = rtd->codec; |
| 1325 | |
| 1326 | ret = msm_adsp_power_up_config(codec); |
| 1327 | if (ret < 0) { |
| 1328 | dev_err(card->dev, |
| 1329 | "%s: msm_adsp_power_up_config failed ret = %d!\n", |
| 1330 | __func__, ret); |
| 1331 | goto done; |
| 1332 | } |
| 1333 | break; |
| 1334 | default: |
| 1335 | break; |
| 1336 | } |
| 1337 | done: |
| 1338 | return NOTIFY_OK; |
| 1339 | } |
| 1340 | |
| 1341 | static struct notifier_block service_nb = { |
| 1342 | .notifier_call = msmfalcon_notifier_service_cb, |
| 1343 | .priority = -INT_MAX, |
| 1344 | }; |
| 1345 | |
| 1346 | static int msm_config_hph_en0_gpio(struct snd_soc_codec *codec, bool high) |
| 1347 | { |
| 1348 | struct snd_soc_card *card = codec->component.card; |
| 1349 | struct msm_asoc_mach_data *pdata; |
| 1350 | int val; |
| 1351 | |
| 1352 | if (!card) |
| 1353 | return 0; |
| 1354 | |
| 1355 | pdata = snd_soc_card_get_drvdata(card); |
| 1356 | if (!pdata || !gpio_is_valid(pdata->hph_en0_gpio)) |
| 1357 | return 0; |
| 1358 | |
| 1359 | val = gpio_get_value_cansleep(pdata->hph_en0_gpio); |
| 1360 | if ((!!val) == high) |
| 1361 | return 0; |
| 1362 | |
| 1363 | gpio_direction_output(pdata->hph_en0_gpio, (int)high); |
| 1364 | |
| 1365 | return 1; |
| 1366 | } |
| 1367 | |
| 1368 | static int msm_snd_enable_codec_ext_tx_clk(struct snd_soc_codec *codec, |
| 1369 | int enable, bool dapm) |
| 1370 | { |
| 1371 | int ret = 0; |
| 1372 | |
| 1373 | if (!strcmp(dev_name(codec->dev), "tasha_codec")) |
| 1374 | ret = tasha_cdc_mclk_tx_enable(codec, enable, dapm); |
| 1375 | else { |
| 1376 | dev_err(codec->dev, "%s: unknown codec to enable ext clk\n", |
| 1377 | __func__); |
| 1378 | ret = -EINVAL; |
| 1379 | } |
| 1380 | return ret; |
| 1381 | } |
| 1382 | |
| 1383 | static int msm_ext_mclk_tx_event(struct snd_soc_dapm_widget *w, |
| 1384 | struct snd_kcontrol *kcontrol, int event) |
| 1385 | { |
| 1386 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1387 | |
| 1388 | pr_debug("%s: event = %d\n", __func__, event); |
| 1389 | |
| 1390 | switch (event) { |
| 1391 | case SND_SOC_DAPM_PRE_PMU: |
| 1392 | return msm_snd_enable_codec_ext_tx_clk(codec, 1, true); |
| 1393 | case SND_SOC_DAPM_POST_PMD: |
| 1394 | return msm_snd_enable_codec_ext_tx_clk(codec, 0, true); |
| 1395 | } |
| 1396 | return 0; |
| 1397 | } |
| 1398 | |
| 1399 | static int msm_ext_mclk_event(struct snd_soc_dapm_widget *w, |
| 1400 | struct snd_kcontrol *kcontrol, int event) |
| 1401 | { |
| 1402 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1403 | |
| 1404 | pr_debug("%s: event = %d\n", __func__, event); |
| 1405 | |
| 1406 | switch (event) { |
| 1407 | case SND_SOC_DAPM_PRE_PMU: |
| 1408 | return msm_ext_enable_codec_mclk(codec, 1, true); |
| 1409 | case SND_SOC_DAPM_POST_PMD: |
| 1410 | return msm_ext_enable_codec_mclk(codec, 0, true); |
| 1411 | } |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | static int msm_ext_prepare_hifi(struct msm_asoc_mach_data *pdata) |
| 1416 | { |
| 1417 | int ret = 0; |
| 1418 | |
| 1419 | if (gpio_is_valid(pdata->hph_en1_gpio)) { |
| 1420 | pr_debug("%s: hph_en1_gpio request %d\n", __func__, |
| 1421 | pdata->hph_en1_gpio); |
| 1422 | ret = gpio_request(pdata->hph_en1_gpio, "hph_en1_gpio"); |
| 1423 | if (ret) { |
| 1424 | pr_err("%s: hph_en1_gpio request failed, ret:%d\n", |
| 1425 | __func__, ret); |
| 1426 | goto err; |
| 1427 | } |
| 1428 | } |
| 1429 | if (gpio_is_valid(pdata->hph_en0_gpio)) { |
| 1430 | pr_debug("%s: hph_en0_gpio request %d\n", __func__, |
| 1431 | pdata->hph_en0_gpio); |
| 1432 | ret = gpio_request(pdata->hph_en0_gpio, "hph_en0_gpio"); |
| 1433 | if (ret) |
| 1434 | pr_err("%s: hph_en0_gpio request failed, ret:%d\n", |
| 1435 | __func__, ret); |
| 1436 | } |
| 1437 | |
| 1438 | err: |
| 1439 | return ret; |
| 1440 | } |
| 1441 | |
| 1442 | static const struct snd_soc_dapm_widget msm_dapm_widgets[] = { |
| 1443 | |
| 1444 | SND_SOC_DAPM_SUPPLY_S("MCLK", -1, SND_SOC_NOPM, 0, 0, |
| 1445 | msm_ext_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1446 | |
| 1447 | SND_SOC_DAPM_SUPPLY_S("MCLK TX", -1, SND_SOC_NOPM, 0, 0, |
| 1448 | msm_ext_mclk_tx_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1449 | |
| 1450 | SND_SOC_DAPM_SPK("Lineout_1 amp", NULL), |
| 1451 | SND_SOC_DAPM_SPK("Lineout_3 amp", NULL), |
| 1452 | SND_SOC_DAPM_SPK("Lineout_2 amp", NULL), |
| 1453 | SND_SOC_DAPM_SPK("Lineout_4 amp", NULL), |
| 1454 | SND_SOC_DAPM_MIC("Handset Mic", NULL), |
| 1455 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 1456 | SND_SOC_DAPM_MIC("Secondary Mic", NULL), |
| 1457 | SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL), |
| 1458 | SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL), |
| 1459 | SND_SOC_DAPM_MIC("Analog Mic4", NULL), |
| 1460 | SND_SOC_DAPM_MIC("Analog Mic6", NULL), |
| 1461 | SND_SOC_DAPM_MIC("Analog Mic7", NULL), |
| 1462 | SND_SOC_DAPM_MIC("Analog Mic8", NULL), |
| 1463 | |
| 1464 | SND_SOC_DAPM_MIC("Digital Mic0", NULL), |
| 1465 | SND_SOC_DAPM_MIC("Digital Mic1", NULL), |
| 1466 | SND_SOC_DAPM_MIC("Digital Mic2", NULL), |
| 1467 | SND_SOC_DAPM_MIC("Digital Mic3", NULL), |
| 1468 | SND_SOC_DAPM_MIC("Digital Mic4", NULL), |
| 1469 | SND_SOC_DAPM_MIC("Digital Mic5", NULL), |
| 1470 | SND_SOC_DAPM_MIC("Digital Mic6", NULL), |
| 1471 | }; |
| 1472 | |
| 1473 | static struct snd_soc_dapm_route wcd_audio_paths_tasha[] = { |
| 1474 | {"MIC BIAS1", NULL, "MCLK TX"}, |
| 1475 | {"MIC BIAS2", NULL, "MCLK TX"}, |
| 1476 | {"MIC BIAS3", NULL, "MCLK TX"}, |
| 1477 | {"MIC BIAS4", NULL, "MCLK TX"}, |
| 1478 | }; |
| 1479 | |
| 1480 | static struct snd_soc_dapm_route wcd_audio_paths[] = { |
| 1481 | {"MIC BIAS1", NULL, "MCLK"}, |
| 1482 | {"MIC BIAS2", NULL, "MCLK"}, |
| 1483 | {"MIC BIAS3", NULL, "MCLK"}, |
| 1484 | {"MIC BIAS4", NULL, "MCLK"}, |
| 1485 | }; |
| 1486 | |
| 1487 | /** |
| 1488 | * msm_audrx_init - Audio init function of sound card instantiate. |
| 1489 | * |
| 1490 | * @rtd: runtime dailink instance |
| 1491 | * |
| 1492 | * Returns 0 on success or ret on failure. |
| 1493 | */ |
| 1494 | int msm_audrx_init(struct snd_soc_pcm_runtime *rtd) |
| 1495 | { |
| 1496 | int ret; |
| 1497 | void *config_data; |
| 1498 | struct snd_soc_codec *codec = rtd->codec; |
| 1499 | struct snd_soc_dapm_context *dapm = |
| 1500 | snd_soc_codec_get_dapm(codec); |
| 1501 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1502 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 1503 | struct snd_soc_pcm_runtime *rtd_aux = rtd->card->rtd_aux; |
| 1504 | struct snd_card *card; |
| 1505 | struct snd_info_entry *entry; |
| 1506 | struct msm_asoc_mach_data *pdata = |
| 1507 | snd_soc_card_get_drvdata(rtd->card); |
| 1508 | |
| 1509 | /* Codec SLIMBUS configuration |
| 1510 | * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8, RX9, RX10, RX11, RX12, RX13 |
| 1511 | * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13 |
| 1512 | * TX14, TX15, TX16 |
| 1513 | */ |
| 1514 | unsigned int rx_ch[TASHA_RX_MAX] = {144, 145, 146, 147, 148, 149, 150, |
| 1515 | 151, 152, 153, 154, 155, 156}; |
| 1516 | unsigned int tx_ch[TASHA_TX_MAX] = {128, 129, 130, 131, 132, 133, |
| 1517 | 134, 135, 136, 137, 138, 139, |
| 1518 | 140, 141, 142, 143}; |
| 1519 | |
| 1520 | pr_debug("%s: dev_name%s\n", __func__, dev_name(cpu_dai->dev)); |
| 1521 | |
| 1522 | rtd->pmdown_time = 0; |
| 1523 | |
| 1524 | ret = snd_soc_add_codec_controls(codec, msm_snd_controls, |
| 1525 | ARRAY_SIZE(msm_snd_controls)); |
| 1526 | if (ret < 0) { |
| 1527 | pr_err("%s: add_codec_controls failed: %d\n", |
| 1528 | __func__, ret); |
| 1529 | return ret; |
| 1530 | } |
| 1531 | |
| 1532 | snd_soc_dapm_new_controls(dapm, msm_dapm_widgets, |
| 1533 | ARRAY_SIZE(msm_dapm_widgets)); |
| 1534 | |
| 1535 | if (!strcmp(dev_name(codec_dai->dev), "tasha_codec")) |
| 1536 | snd_soc_dapm_add_routes(dapm, wcd_audio_paths_tasha, |
| 1537 | ARRAY_SIZE(wcd_audio_paths_tasha)); |
| 1538 | else |
| 1539 | snd_soc_dapm_add_routes(dapm, wcd_audio_paths, |
| 1540 | ARRAY_SIZE(wcd_audio_paths)); |
| 1541 | |
| 1542 | snd_soc_dapm_enable_pin(dapm, "Lineout_1 amp"); |
| 1543 | snd_soc_dapm_enable_pin(dapm, "Lineout_3 amp"); |
| 1544 | snd_soc_dapm_enable_pin(dapm, "Lineout_2 amp"); |
| 1545 | snd_soc_dapm_enable_pin(dapm, "Lineout_4 amp"); |
| 1546 | |
| 1547 | snd_soc_dapm_ignore_suspend(dapm, "MADINPUT"); |
| 1548 | snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_INPUT"); |
| 1549 | snd_soc_dapm_ignore_suspend(dapm, "Handset Mic"); |
| 1550 | snd_soc_dapm_ignore_suspend(dapm, "Headset Mic"); |
| 1551 | snd_soc_dapm_ignore_suspend(dapm, "Secondary Mic"); |
| 1552 | snd_soc_dapm_ignore_suspend(dapm, "Lineout_1 amp"); |
| 1553 | snd_soc_dapm_ignore_suspend(dapm, "Lineout_3 amp"); |
| 1554 | snd_soc_dapm_ignore_suspend(dapm, "Lineout_2 amp"); |
| 1555 | snd_soc_dapm_ignore_suspend(dapm, "Lineout_4 amp"); |
| 1556 | snd_soc_dapm_ignore_suspend(dapm, "ANCRight Headset Mic"); |
| 1557 | snd_soc_dapm_ignore_suspend(dapm, "ANCLeft Headset Mic"); |
| 1558 | snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0"); |
| 1559 | snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1"); |
| 1560 | snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2"); |
| 1561 | snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3"); |
| 1562 | snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4"); |
| 1563 | snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5"); |
| 1564 | snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4"); |
| 1565 | snd_soc_dapm_ignore_suspend(dapm, "Analog Mic6"); |
| 1566 | snd_soc_dapm_ignore_suspend(dapm, "Analog Mic7"); |
| 1567 | snd_soc_dapm_ignore_suspend(dapm, "Analog Mic8"); |
| 1568 | |
| 1569 | snd_soc_dapm_ignore_suspend(dapm, "EAR"); |
| 1570 | snd_soc_dapm_ignore_suspend(dapm, "LINEOUT1"); |
| 1571 | snd_soc_dapm_ignore_suspend(dapm, "LINEOUT2"); |
| 1572 | snd_soc_dapm_ignore_suspend(dapm, "LINEOUT3"); |
| 1573 | snd_soc_dapm_ignore_suspend(dapm, "LINEOUT4"); |
| 1574 | snd_soc_dapm_ignore_suspend(dapm, "AMIC1"); |
| 1575 | snd_soc_dapm_ignore_suspend(dapm, "AMIC2"); |
| 1576 | snd_soc_dapm_ignore_suspend(dapm, "AMIC3"); |
| 1577 | snd_soc_dapm_ignore_suspend(dapm, "AMIC4"); |
| 1578 | snd_soc_dapm_ignore_suspend(dapm, "AMIC5"); |
| 1579 | snd_soc_dapm_ignore_suspend(dapm, "AMIC6"); |
| 1580 | snd_soc_dapm_ignore_suspend(dapm, "DMIC0"); |
| 1581 | snd_soc_dapm_ignore_suspend(dapm, "DMIC1"); |
| 1582 | snd_soc_dapm_ignore_suspend(dapm, "DMIC2"); |
| 1583 | snd_soc_dapm_ignore_suspend(dapm, "DMIC3"); |
| 1584 | snd_soc_dapm_ignore_suspend(dapm, "DMIC4"); |
| 1585 | snd_soc_dapm_ignore_suspend(dapm, "DMIC5"); |
| 1586 | snd_soc_dapm_ignore_suspend(dapm, "ANC EAR"); |
| 1587 | snd_soc_dapm_ignore_suspend(dapm, "ANC HEADPHONE"); |
| 1588 | snd_soc_dapm_ignore_suspend(dapm, "SPK1 OUT"); |
| 1589 | snd_soc_dapm_ignore_suspend(dapm, "SPK2 OUT"); |
| 1590 | snd_soc_dapm_ignore_suspend(dapm, "HPHL"); |
| 1591 | snd_soc_dapm_ignore_suspend(dapm, "HPHR"); |
| 1592 | snd_soc_dapm_ignore_suspend(dapm, "ANC HPHL"); |
| 1593 | snd_soc_dapm_ignore_suspend(dapm, "ANC HPHR"); |
| 1594 | snd_soc_dapm_ignore_suspend(dapm, "ANC LINEOUT1"); |
| 1595 | snd_soc_dapm_ignore_suspend(dapm, "ANC LINEOUT2"); |
| 1596 | snd_soc_dapm_ignore_suspend(dapm, "AIF4 VI"); |
| 1597 | snd_soc_dapm_ignore_suspend(dapm, "VIINPUT"); |
| 1598 | |
| 1599 | snd_soc_dapm_sync(dapm); |
| 1600 | snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch), |
| 1601 | tx_ch, ARRAY_SIZE(rx_ch), rx_ch); |
| 1602 | |
| 1603 | if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) { |
| 1604 | msm_codec_fn.get_afe_config_fn = tavil_get_afe_config; |
| 1605 | } else { |
| 1606 | msm_codec_fn.get_afe_config_fn = tasha_get_afe_config; |
| 1607 | msm_codec_fn.mbhc_hs_detect_exit = tasha_mbhc_hs_detect_exit; |
| 1608 | } |
| 1609 | |
| 1610 | ret = msm_adsp_power_up_config(codec); |
| 1611 | if (ret) { |
| 1612 | pr_err("%s: Failed to set AFE config %d\n", __func__, ret); |
| 1613 | goto err_afe_cfg; |
| 1614 | } |
| 1615 | |
| 1616 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1617 | AFE_AANC_VERSION); |
| 1618 | if (config_data) { |
| 1619 | ret = afe_set_config(AFE_AANC_VERSION, config_data, 0); |
| 1620 | if (ret) { |
| 1621 | pr_err("%s: Failed to set aanc version %d\n", |
| 1622 | __func__, ret); |
| 1623 | goto err_afe_cfg; |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | if (!strcmp(dev_name(codec_dai->dev), "tasha_codec")) { |
| 1628 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1629 | AFE_CDC_CLIP_REGISTERS_CONFIG); |
| 1630 | if (config_data) { |
| 1631 | ret = afe_set_config(AFE_CDC_CLIP_REGISTERS_CONFIG, |
| 1632 | config_data, 0); |
| 1633 | if (ret) { |
| 1634 | pr_err("%s: Failed to set clip registers %d\n", |
| 1635 | __func__, ret); |
| 1636 | goto err_afe_cfg; |
| 1637 | } |
| 1638 | } |
| 1639 | config_data = msm_codec_fn.get_afe_config_fn(codec, |
| 1640 | AFE_CLIP_BANK_SEL); |
| 1641 | if (config_data) { |
| 1642 | ret = afe_set_config(AFE_CLIP_BANK_SEL, config_data, 0); |
| 1643 | if (ret) { |
| 1644 | pr_err("%s: Failed to set AFE bank selection %d\n", |
| 1645 | __func__, ret); |
| 1646 | goto err_afe_cfg; |
| 1647 | } |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | /* |
| 1652 | * Send speaker configuration only for WSA8810. |
| 1653 | * Defalut configuration is for WSA8815. |
| 1654 | */ |
| 1655 | if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) { |
| 1656 | if (rtd_aux && rtd_aux->component) |
| 1657 | if (!strcmp(rtd_aux->component->name, WSA8810_NAME_1) || |
| 1658 | !strcmp(rtd_aux->component->name, WSA8810_NAME_2)) { |
| 1659 | tavil_set_spkr_mode(rtd->codec, SPKR_MODE_1); |
| 1660 | tavil_set_spkr_gain_offset(rtd->codec, |
| 1661 | RX_GAIN_OFFSET_M1P5_DB); |
| 1662 | } |
| 1663 | card = rtd->card->snd_card; |
| 1664 | entry = snd_info_create_subdir(card->module, "codecs", |
| 1665 | card->proc_root); |
| 1666 | if (!entry) { |
| 1667 | pr_debug("%s: Cannot create codecs module entry\n", |
| 1668 | __func__); |
| 1669 | pdata->codec_root = NULL; |
| 1670 | goto done; |
| 1671 | } |
| 1672 | pdata->codec_root = entry; |
| 1673 | tavil_codec_info_create_codec_entry(pdata->codec_root, codec); |
| 1674 | } else { |
| 1675 | if (rtd_aux && rtd_aux->component) |
| 1676 | if (!strcmp(rtd_aux->component->name, WSA8810_NAME_1) || |
| 1677 | !strcmp(rtd_aux->component->name, WSA8810_NAME_2)) { |
| 1678 | tasha_set_spkr_mode(rtd->codec, SPKR_MODE_1); |
| 1679 | tasha_set_spkr_gain_offset(rtd->codec, |
| 1680 | RX_GAIN_OFFSET_M1P5_DB); |
| 1681 | } |
| 1682 | card = rtd->card->snd_card; |
| 1683 | entry = snd_info_create_subdir(card->module, "codecs", |
| 1684 | card->proc_root); |
| 1685 | if (!entry) { |
| 1686 | pr_debug("%s: Cannot create codecs module entry\n", |
| 1687 | __func__); |
| 1688 | ret = 0; |
| 1689 | goto err_snd_module; |
| 1690 | } |
| 1691 | pdata->codec_root = entry; |
| 1692 | tasha_codec_info_create_codec_entry(pdata->codec_root, codec); |
| 1693 | tasha_mbhc_zdet_gpio_ctrl(msm_config_hph_en0_gpio, rtd->codec); |
| 1694 | } |
| 1695 | |
| 1696 | wcd_mbhc_cfg_ptr->calibration = def_ext_mbhc_cal(); |
| 1697 | if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) { |
| 1698 | if (wcd_mbhc_cfg_ptr->calibration) { |
| 1699 | pdata->codec = codec; |
| 1700 | ret = tavil_mbhc_hs_detect(codec, wcd_mbhc_cfg_ptr); |
| 1701 | if (ret < 0) |
| 1702 | pr_err("%s: Failed to intialise mbhc %d\n", |
| 1703 | __func__, ret); |
| 1704 | } else { |
| 1705 | pr_err("%s: wcd_mbhc_cfg calibration is NULL\n", |
| 1706 | __func__); |
| 1707 | ret = -ENOMEM; |
| 1708 | goto err_mbhc_cal; |
| 1709 | } |
| 1710 | } else { |
| 1711 | if (wcd_mbhc_cfg_ptr->calibration) { |
| 1712 | pdata->codec = codec; |
| 1713 | ret = tasha_mbhc_hs_detect(codec, wcd_mbhc_cfg_ptr); |
| 1714 | if (ret < 0) |
| 1715 | pr_err("%s: Failed to intialise mbhc %d\n", |
| 1716 | __func__, ret); |
| 1717 | } else { |
| 1718 | pr_err("%s: wcd_mbhc_cfg calibration is NULL\n", |
| 1719 | __func__); |
| 1720 | ret = -ENOMEM; |
| 1721 | goto err_mbhc_cal; |
| 1722 | } |
| 1723 | |
| 1724 | } |
| 1725 | done: |
| 1726 | return 0; |
| 1727 | |
| 1728 | err_snd_module: |
| 1729 | err_afe_cfg: |
| 1730 | err_mbhc_cal: |
| 1731 | return ret; |
| 1732 | } |
| 1733 | EXPORT_SYMBOL(msm_audrx_init); |
| 1734 | |
| 1735 | /** |
| 1736 | * msm_ext_register_audio_notifier - register SSR notifier. |
| 1737 | */ |
| 1738 | void msm_ext_register_audio_notifier(void) |
| 1739 | { |
| 1740 | int ret; |
| 1741 | |
| 1742 | ret = audio_notifier_register("msmfalcon", AUDIO_NOTIFIER_ADSP_DOMAIN, |
| 1743 | &service_nb); |
| 1744 | if (ret < 0) |
| 1745 | pr_err("%s: Audio notifier register failed ret = %d\n", |
| 1746 | __func__, ret); |
| 1747 | } |
| 1748 | EXPORT_SYMBOL(msm_ext_register_audio_notifier); |
| 1749 | |
| 1750 | /** |
| 1751 | * msm_ext_cdc_init - external codec machine specific init. |
| 1752 | * |
| 1753 | * @pdev: platform device handle |
| 1754 | * @pdata: private data of machine driver |
| 1755 | * @card: sound card pointer reference |
| 1756 | * @mbhc_cfg: MBHC config reference |
| 1757 | * |
| 1758 | * Returns 0 on success or ret on failure. |
| 1759 | */ |
| 1760 | int msm_ext_cdc_init(struct platform_device *pdev, |
| 1761 | struct msm_asoc_mach_data *pdata, |
| 1762 | struct snd_soc_card **card, |
| 1763 | struct wcd_mbhc_config *wcd_mbhc_cfg_ptr1) |
| 1764 | { |
| 1765 | int ret = 0; |
| 1766 | |
| 1767 | wcd_mbhc_cfg_ptr = wcd_mbhc_cfg_ptr1; |
| 1768 | pdev->id = 0; |
| 1769 | wcd_mbhc_cfg_ptr->moisture_en = true; |
| 1770 | wcd_mbhc_cfg_ptr->mbhc_micbias = MIC_BIAS_2; |
| 1771 | wcd_mbhc_cfg_ptr->anc_micbias = MIC_BIAS_2; |
| 1772 | wcd_mbhc_cfg_ptr->enable_anc_mic_detect = false; |
| 1773 | |
| 1774 | *card = populate_snd_card_dailinks(&pdev->dev, pdata->snd_card_val); |
| 1775 | if (!(*card)) { |
| 1776 | dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__); |
| 1777 | ret = -EPROBE_DEFER; |
| 1778 | goto err; |
| 1779 | } |
| 1780 | spdev = pdev; |
| 1781 | platform_set_drvdata(pdev, *card); |
| 1782 | snd_soc_card_set_drvdata(*card, pdata); |
| 1783 | is_initial_boot = true; |
| 1784 | pdata->hph_en1_gpio = of_get_named_gpio(pdev->dev.of_node, |
| 1785 | "qcom,hph-en1-gpio", 0); |
| 1786 | if (!gpio_is_valid(pdata->hph_en1_gpio)) |
| 1787 | pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node, |
| 1788 | "qcom,hph-en1-gpio", 0); |
| 1789 | if (!gpio_is_valid(pdata->hph_en1_gpio) && (!pdata->hph_en1_gpio_p)) { |
| 1790 | dev_dbg(&pdev->dev, "property %s not detected in node %s", |
| 1791 | "qcom,hph-en1-gpio", pdev->dev.of_node->full_name); |
| 1792 | } |
| 1793 | |
| 1794 | pdata->hph_en0_gpio = of_get_named_gpio(pdev->dev.of_node, |
| 1795 | "qcom,hph-en0-gpio", 0); |
| 1796 | if (!gpio_is_valid(pdata->hph_en0_gpio)) |
| 1797 | pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node, |
| 1798 | "qcom,hph-en0-gpio", 0); |
| 1799 | if (!gpio_is_valid(pdata->hph_en0_gpio) && (!pdata->hph_en0_gpio_p)) { |
| 1800 | dev_dbg(&pdev->dev, "property %s not detected in node %s", |
| 1801 | "qcom,hph-en0-gpio", pdev->dev.of_node->full_name); |
| 1802 | } |
| 1803 | |
| 1804 | ret = msm_ext_prepare_hifi(pdata); |
| 1805 | if (ret) { |
| 1806 | dev_dbg(&pdev->dev, "msm_ext_prepare_hifi failed (%d)\n", |
| 1807 | ret); |
| 1808 | ret = 0; |
| 1809 | } |
Laxminath Kasam | fb36dc1 | 2016-11-28 23:04:47 +0530 | [diff] [blame^] | 1810 | msm_snd_intr_lpi.mpm_wakeup = |
| 1811 | ioremap(TLMM_CENTER_MPM_WAKEUP_INT_EN_0, 4); |
| 1812 | msm_snd_intr_lpi.intr1_cfg_apps = |
| 1813 | ioremap(TLMM_LPI_DIR_CONN_INTR1_CFG_APPS, 4); |
| 1814 | msm_snd_intr_lpi.lpi_gpio_intr_cfg = |
| 1815 | ioremap(TLMM_LPI_GPIO_INTR_CFG1, 4); |
| 1816 | msm_snd_intr_lpi.lpi_gpio_cfg = |
| 1817 | ioremap(TLMM_LPI_GPIO22_CFG, 4); |
| 1818 | msm_snd_intr_lpi.lpi_gpio_inout = |
| 1819 | ioremap(TLMM_LPI_GPIO22_INOUT, 4); |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 1820 | err: |
| 1821 | return ret; |
| 1822 | } |
| 1823 | EXPORT_SYMBOL(msm_ext_cdc_init); |
Laxminath Kasam | fb36dc1 | 2016-11-28 23:04:47 +0530 | [diff] [blame^] | 1824 | |
| 1825 | /** |
| 1826 | * msm_ext_cdc_deinit - external codec machine specific deinit. |
| 1827 | */ |
| 1828 | void msm_ext_cdc_deinit(void) |
| 1829 | { |
| 1830 | if (msm_snd_intr_lpi.mpm_wakeup) |
| 1831 | iounmap(msm_snd_intr_lpi.mpm_wakeup); |
| 1832 | if (msm_snd_intr_lpi.intr1_cfg_apps) |
| 1833 | iounmap(msm_snd_intr_lpi.intr1_cfg_apps); |
| 1834 | if (msm_snd_intr_lpi.lpi_gpio_intr_cfg) |
| 1835 | iounmap(msm_snd_intr_lpi.lpi_gpio_intr_cfg); |
| 1836 | if (msm_snd_intr_lpi.lpi_gpio_cfg) |
| 1837 | iounmap(msm_snd_intr_lpi.lpi_gpio_cfg); |
| 1838 | if (msm_snd_intr_lpi.lpi_gpio_inout) |
| 1839 | iounmap(msm_snd_intr_lpi.lpi_gpio_inout); |
| 1840 | } |
| 1841 | EXPORT_SYMBOL(msm_ext_cdc_deinit); |