Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1 | /* Copyright (c) 2013-2018, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 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/init.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/time.h> |
| 17 | #include <linux/wait.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/dma-mapping.h> |
| 21 | #include <sound/core.h> |
| 22 | #include <sound/soc.h> |
| 23 | #include <sound/soc-dapm.h> |
| 24 | #include <sound/pcm.h> |
| 25 | #include <sound/initval.h> |
| 26 | #include <sound/control.h> |
| 27 | #include <asm/dma.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 28 | #include <dsp/msm_audio_ion.h> |
| 29 | #include <dsp/q6voice.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 30 | |
| 31 | #define HPCM_MAX_Q_LEN 2 |
| 32 | #define HPCM_MIN_VOC_PKT_SIZE 320 |
| 33 | #define HPCM_MAX_VOC_PKT_SIZE 640 |
| 34 | #define VHPCM_BLOCK_SIZE 4096 |
| 35 | #define CACHE_ALIGNMENT_SIZE 128 |
| 36 | #define CACHE_ALIGNMENT_MASK 0xFFFFFF80 |
| 37 | |
| 38 | #define VOICE_TX_CAPTURE_DAI_ID "CS-VOICE HOST TX CAPTURE" |
| 39 | #define VOICE_TX_PLAYBACK_DAI_ID "CS-VOICE HOST TX PLAYBACK" |
| 40 | #define VOICE_RX_CAPTURE_DAI_ID "CS-VOICE HOST RX CAPTURE" |
| 41 | #define VOICE_RX_PLAYBACK_DAI_ID "CS-VOICE HOST RX PLAYBACK" |
| 42 | |
| 43 | #define VOLTE_TX_CAPTURE_DAI_ID "VOLTE HOST TX CAPTURE" |
| 44 | #define VOLTE_TX_PLAYBACK_DAI_ID "VOLTE HOST TX PLAYBACK" |
| 45 | #define VOLTE_RX_CAPTURE_DAI_ID "VOLTE HOST RX CAPTURE" |
| 46 | #define VOLTE_RX_PLAYBACK_DAI_ID "VOLTE HOST RX PLAYBACK" |
| 47 | |
| 48 | |
| 49 | #define VoMMode1_TX_CAPTURE_DAI_ID "VoiceMMode1 HOST TX CAPTURE" |
| 50 | #define VoMMode1_TX_PLAYBACK_DAI_ID "VoiceMMode1 HOST TX PLAYBACK" |
| 51 | #define VoMMode1_RX_CAPTURE_DAI_ID "VoiceMMode1 HOST RX CAPTURE" |
| 52 | #define VoMMode1_RX_PLAYBACK_DAI_ID "VoiceMMode1 HOST RX PLAYBACK" |
| 53 | |
| 54 | #define VoMMode2_TX_CAPTURE_DAI_ID "VoiceMMode2 HOST TX CAPTURE" |
| 55 | #define VoMMode2_TX_PLAYBACK_DAI_ID "VoiceMMode2 HOST TX PLAYBACK" |
| 56 | #define VoMMode2_RX_CAPTURE_DAI_ID "VoiceMMode2 HOST RX CAPTURE" |
| 57 | #define VoMMode2_RX_PLAYBACK_DAI_ID "VoiceMMode2 HOST RX PLAYBACK" |
| 58 | |
| 59 | enum { |
| 60 | RX = 1, |
| 61 | TX, |
| 62 | }; |
| 63 | |
| 64 | enum { |
| 65 | VOICE_INDEX = 0, |
| 66 | VOLTE_INDEX, |
| 67 | VOMMODE1_INDEX, |
| 68 | VOMMODE2_INDEX, |
| 69 | MAX_SESSION |
| 70 | }; |
| 71 | |
| 72 | enum hpcm_state { |
| 73 | HPCM_STOPPED = 1, |
| 74 | HPCM_CLOSED, |
| 75 | HPCM_PREPARED, |
| 76 | HPCM_STARTED, |
| 77 | }; |
| 78 | |
| 79 | struct hpcm_frame { |
| 80 | uint32_t len; |
| 81 | uint8_t voc_pkt[HPCM_MAX_VOC_PKT_SIZE]; |
| 82 | }; |
| 83 | |
| 84 | struct hpcm_buf_node { |
| 85 | struct list_head list; |
| 86 | struct hpcm_frame frame; |
| 87 | }; |
| 88 | |
| 89 | struct vocpcm_ion_buffer { |
| 90 | /* Physical address */ |
| 91 | phys_addr_t paddr; |
| 92 | /* Kernel virtual address */ |
| 93 | void *kvaddr; |
| 94 | }; |
| 95 | |
| 96 | struct dai_data { |
| 97 | enum hpcm_state state; |
| 98 | struct snd_pcm_substream *substream; |
| 99 | struct list_head filled_queue; |
| 100 | struct list_head free_queue; |
| 101 | wait_queue_head_t queue_wait; |
| 102 | spinlock_t dsp_lock; |
| 103 | uint32_t pcm_size; |
| 104 | uint32_t pcm_count; |
| 105 | /* IRQ position */ |
| 106 | uint32_t pcm_irq_pos; |
| 107 | /* Position in buffer */ |
| 108 | uint32_t pcm_buf_pos; |
| 109 | struct vocpcm_ion_buffer vocpcm_ion_buffer; |
| 110 | }; |
| 111 | |
| 112 | struct tap_point { |
| 113 | struct dai_data playback_dai_data; |
| 114 | struct dai_data capture_dai_data; |
| 115 | }; |
| 116 | |
| 117 | struct session { |
| 118 | struct tap_point tx_tap_point; |
| 119 | struct tap_point rx_tap_point; |
| 120 | phys_addr_t sess_paddr; |
| 121 | void *sess_kvaddr; |
| 122 | struct ion_handle *ion_handle; |
| 123 | struct mem_map_table tp_mem_table; |
| 124 | }; |
| 125 | |
| 126 | struct tappnt_mxr_data { |
| 127 | bool enable; |
| 128 | uint16_t direction; |
| 129 | uint16_t sample_rate; |
| 130 | }; |
| 131 | |
| 132 | /* Values from mixer ctl are cached in this structure */ |
| 133 | struct mixer_conf { |
| 134 | int8_t sess_indx; |
| 135 | struct tappnt_mxr_data rx; |
| 136 | struct tappnt_mxr_data tx; |
| 137 | }; |
| 138 | |
| 139 | struct start_cmd { |
| 140 | struct vss_ivpcm_tap_point tap_pnt[2]; |
| 141 | uint32_t no_of_tapoints; |
| 142 | }; |
| 143 | |
| 144 | struct hpcm_drv { |
| 145 | struct mutex lock; |
| 146 | struct session session[MAX_SESSION]; |
| 147 | struct mixer_conf mixer_conf; |
| 148 | struct ion_client *ion_client; |
| 149 | struct start_cmd start_cmd; |
| 150 | }; |
| 151 | |
| 152 | static struct hpcm_drv hpcm_drv; |
| 153 | |
| 154 | static struct snd_pcm_hardware msm_pcm_hardware = { |
| 155 | .info = (SNDRV_PCM_INFO_MMAP | |
| 156 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 157 | SNDRV_PCM_INFO_MMAP_VALID | |
| 158 | SNDRV_PCM_INFO_INTERLEAVED), |
| 159 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 160 | SNDRV_PCM_FMTBIT_SPECIAL, |
| 161 | .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000, |
| 162 | .rate_min = 8000, |
| 163 | .rate_max = 16000, |
| 164 | .channels_min = 1, |
| 165 | .channels_max = 1, |
| 166 | .buffer_bytes_max = sizeof(struct hpcm_buf_node) * HPCM_MAX_Q_LEN, |
| 167 | .period_bytes_min = HPCM_MIN_VOC_PKT_SIZE, |
| 168 | .period_bytes_max = HPCM_MAX_VOC_PKT_SIZE, |
| 169 | .periods_min = HPCM_MAX_Q_LEN, |
| 170 | .periods_max = HPCM_MAX_Q_LEN, |
| 171 | .fifo_size = 0, |
| 172 | }; |
| 173 | |
| 174 | static char *hpcm_get_sess_name(int sess_indx) |
| 175 | { |
| 176 | char *sess_name = NULL; |
| 177 | |
| 178 | if (sess_indx == VOICE_INDEX) |
| 179 | sess_name = VOICE_SESSION_NAME; |
| 180 | else if (sess_indx == VOLTE_INDEX) |
| 181 | sess_name = VOLTE_SESSION_NAME; |
| 182 | else if (sess_indx == VOMMODE1_INDEX) |
| 183 | sess_name = VOICEMMODE1_NAME; |
| 184 | else if (sess_indx == VOMMODE2_INDEX) |
| 185 | sess_name = VOICEMMODE2_NAME; |
| 186 | else |
| 187 | pr_err("%s:, Invalid sess_index\n", __func__); |
| 188 | |
| 189 | return sess_name; |
| 190 | } |
| 191 | |
| 192 | static void hpcm_reset_mixer_config(struct hpcm_drv *prtd) |
| 193 | { |
| 194 | prtd->mixer_conf.sess_indx = -1; |
| 195 | prtd->mixer_conf.rx.enable = false; |
| 196 | prtd->mixer_conf.rx.direction = -1; |
| 197 | prtd->mixer_conf.rx.sample_rate = 0; |
| 198 | |
| 199 | prtd->mixer_conf.tx.enable = false; |
| 200 | prtd->mixer_conf.tx.direction = -1; |
| 201 | prtd->mixer_conf.tx.sample_rate = 0; |
| 202 | } |
| 203 | |
| 204 | /* Check for valid mixer control values */ |
| 205 | static bool hpcm_is_valid_config(int sess_indx, int tap_point, |
| 206 | uint16_t direction, uint16_t samplerate) |
| 207 | { |
| 208 | if (sess_indx < VOICE_INDEX || sess_indx > VOMMODE2_INDEX) { |
| 209 | pr_err("%s: invalid sess_indx :%d\n", __func__, sess_indx); |
| 210 | goto error; |
| 211 | } |
| 212 | |
| 213 | if (samplerate != VSS_IVPCM_SAMPLING_RATE_8K && |
| 214 | samplerate != VSS_IVPCM_SAMPLING_RATE_16K) { |
| 215 | pr_err("%s: invalid sample rate :%d\n", __func__, samplerate); |
| 216 | goto error; |
| 217 | } |
| 218 | |
| 219 | if ((tap_point != RX) && (tap_point != TX)) { |
| 220 | pr_err("%s: invalid tappoint :%d\n", __func__, tap_point); |
| 221 | goto error; |
| 222 | } |
| 223 | |
| 224 | if ((direction != VSS_IVPCM_TAP_POINT_DIR_IN) && |
| 225 | (direction != VSS_IVPCM_TAP_POINT_DIR_OUT) && |
| 226 | (direction != VSS_IVPCM_TAP_POINT_DIR_OUT_IN)) { |
| 227 | pr_err("%s: invalid direction :%d\n", __func__, direction); |
| 228 | goto error; |
| 229 | } |
| 230 | |
| 231 | return true; |
| 232 | |
| 233 | error: |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | |
| 238 | static struct dai_data *hpcm_get_dai_data(char *pcm_id, struct hpcm_drv *prtd) |
| 239 | { |
| 240 | struct dai_data *dai_data = NULL; |
| 241 | size_t size = 0; |
| 242 | |
| 243 | if (pcm_id) { |
| 244 | size = strlen(pcm_id); |
| 245 | /* Check for Voice DAI */ |
| 246 | if (strnstr(pcm_id, VOICE_TX_CAPTURE_DAI_ID, size)) { |
| 247 | dai_data = |
| 248 | &prtd->session[VOICE_INDEX].tx_tap_point.capture_dai_data; |
| 249 | } else if (strnstr(pcm_id, VOICE_TX_PLAYBACK_DAI_ID, size)) { |
| 250 | dai_data = |
| 251 | &prtd->session[VOICE_INDEX].tx_tap_point.playback_dai_data; |
| 252 | } else if (strnstr(pcm_id, VOICE_RX_CAPTURE_DAI_ID, size)) { |
| 253 | dai_data = |
| 254 | &prtd->session[VOICE_INDEX].rx_tap_point.capture_dai_data; |
| 255 | } else if (strnstr(pcm_id, VOICE_RX_PLAYBACK_DAI_ID, size)) { |
| 256 | dai_data = |
| 257 | &prtd->session[VOICE_INDEX].rx_tap_point.playback_dai_data; |
| 258 | /* Check for VoLTE DAI */ |
| 259 | } else if (strnstr(pcm_id, VOLTE_TX_CAPTURE_DAI_ID, size)) { |
| 260 | dai_data = |
| 261 | &prtd->session[VOLTE_INDEX].tx_tap_point.capture_dai_data; |
| 262 | } else if (strnstr(pcm_id, VOLTE_TX_PLAYBACK_DAI_ID, size)) { |
| 263 | dai_data = |
| 264 | &prtd->session[VOLTE_INDEX].tx_tap_point.playback_dai_data; |
| 265 | } else if (strnstr(pcm_id, VOLTE_RX_CAPTURE_DAI_ID, size)) { |
| 266 | dai_data = |
| 267 | &prtd->session[VOLTE_INDEX].rx_tap_point.capture_dai_data; |
| 268 | } else if (strnstr(pcm_id, VOLTE_RX_PLAYBACK_DAI_ID, size)) { |
| 269 | dai_data = |
| 270 | &prtd->session[VOLTE_INDEX].rx_tap_point.playback_dai_data; |
| 271 | /* check for VoiceMMode1 DAI */ |
| 272 | } else if (strnstr(pcm_id, VoMMode1_TX_CAPTURE_DAI_ID, size)) { |
| 273 | dai_data = |
| 274 | &prtd->session[VOMMODE1_INDEX].tx_tap_point.capture_dai_data; |
| 275 | } else if (strnstr(pcm_id, VoMMode1_TX_PLAYBACK_DAI_ID, size)) { |
| 276 | dai_data = |
| 277 | &prtd->session[VOMMODE1_INDEX].tx_tap_point.playback_dai_data; |
| 278 | } else if (strnstr(pcm_id, VoMMode1_RX_CAPTURE_DAI_ID, size)) { |
| 279 | dai_data = |
| 280 | &prtd->session[VOMMODE1_INDEX].rx_tap_point.capture_dai_data; |
| 281 | } else if (strnstr(pcm_id, VoMMode1_RX_PLAYBACK_DAI_ID, size)) { |
| 282 | dai_data = |
| 283 | &prtd->session[VOMMODE1_INDEX].rx_tap_point.playback_dai_data; |
| 284 | /* check for VOiceMMode2 DAI */ |
| 285 | } else if (strnstr(pcm_id, VoMMode2_TX_CAPTURE_DAI_ID, size)) { |
| 286 | dai_data = |
| 287 | &prtd->session[VOMMODE2_INDEX].tx_tap_point.capture_dai_data; |
| 288 | } else if (strnstr(pcm_id, VoMMode2_TX_PLAYBACK_DAI_ID, size)) { |
| 289 | dai_data = |
| 290 | &prtd->session[VOMMODE2_INDEX].tx_tap_point.playback_dai_data; |
| 291 | } else if (strnstr(pcm_id, VoMMode2_RX_CAPTURE_DAI_ID, size)) { |
| 292 | dai_data = |
| 293 | &prtd->session[VOMMODE2_INDEX].rx_tap_point.capture_dai_data; |
| 294 | } else if (strnstr(pcm_id, VoMMode2_RX_PLAYBACK_DAI_ID, size)) { |
| 295 | dai_data = |
| 296 | &prtd->session[VOMMODE2_INDEX].rx_tap_point.playback_dai_data; |
| 297 | |
| 298 | } else { |
| 299 | pr_err("%s: Wrong dai id\n", __func__); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | return dai_data; |
| 304 | } |
| 305 | |
| 306 | static struct tap_point *hpcm_get_tappoint_data(char *pcm_id, |
| 307 | struct hpcm_drv *prtd) |
| 308 | { |
| 309 | struct tap_point *tp = NULL; |
| 310 | size_t size = 0; |
| 311 | |
| 312 | if (pcm_id) { |
| 313 | size = strlen(pcm_id); |
| 314 | /* Check for Voice DAI */ |
| 315 | if (strnstr(pcm_id, VOICE_TX_CAPTURE_DAI_ID, size)) { |
| 316 | tp = &prtd->session[VOICE_INDEX].tx_tap_point; |
| 317 | } else if (strnstr(pcm_id, VOICE_TX_PLAYBACK_DAI_ID, size)) { |
| 318 | tp = &prtd->session[VOICE_INDEX].tx_tap_point; |
| 319 | } else if (strnstr(pcm_id, VOICE_RX_CAPTURE_DAI_ID, size)) { |
| 320 | tp = &prtd->session[VOICE_INDEX].rx_tap_point; |
| 321 | } else if (strnstr(pcm_id, VOICE_RX_PLAYBACK_DAI_ID, size)) { |
| 322 | tp = &prtd->session[VOICE_INDEX].rx_tap_point; |
| 323 | /* Check for VoLTE DAI */ |
| 324 | } else if (strnstr(pcm_id, VOLTE_TX_CAPTURE_DAI_ID, size)) { |
| 325 | tp = &prtd->session[VOLTE_INDEX].tx_tap_point; |
| 326 | } else if (strnstr(pcm_id, VOLTE_TX_PLAYBACK_DAI_ID, size)) { |
| 327 | tp = &prtd->session[VOLTE_INDEX].tx_tap_point; |
| 328 | } else if (strnstr(pcm_id, VOLTE_RX_CAPTURE_DAI_ID, size)) { |
| 329 | tp = &prtd->session[VOLTE_INDEX].rx_tap_point; |
| 330 | } else if (strnstr(pcm_id, VOLTE_RX_PLAYBACK_DAI_ID, size)) { |
| 331 | tp = &prtd->session[VOLTE_INDEX].rx_tap_point; |
| 332 | /* check for VoiceMMode1 */ |
| 333 | } else if (strnstr(pcm_id, VoMMode1_TX_CAPTURE_DAI_ID, size)) { |
| 334 | tp = &prtd->session[VOMMODE1_INDEX].tx_tap_point; |
| 335 | } else if (strnstr(pcm_id, VoMMode1_TX_PLAYBACK_DAI_ID, size)) { |
| 336 | tp = &prtd->session[VOMMODE1_INDEX].tx_tap_point; |
| 337 | } else if (strnstr(pcm_id, VoMMode1_RX_CAPTURE_DAI_ID, size)) { |
| 338 | tp = &prtd->session[VOMMODE1_INDEX].rx_tap_point; |
| 339 | } else if (strnstr(pcm_id, VoMMode1_RX_PLAYBACK_DAI_ID, size)) { |
| 340 | tp = &prtd->session[VOMMODE1_INDEX].rx_tap_point; |
| 341 | /* check for VoiceMMode2 */ |
| 342 | } else if (strnstr(pcm_id, VoMMode2_TX_CAPTURE_DAI_ID, size)) { |
| 343 | tp = &prtd->session[VOMMODE2_INDEX].tx_tap_point; |
| 344 | } else if (strnstr(pcm_id, VoMMode2_TX_PLAYBACK_DAI_ID, size)) { |
| 345 | tp = &prtd->session[VOMMODE2_INDEX].tx_tap_point; |
| 346 | } else if (strnstr(pcm_id, VoMMode2_RX_CAPTURE_DAI_ID, size)) { |
| 347 | tp = &prtd->session[VOMMODE2_INDEX].rx_tap_point; |
| 348 | } else if (strnstr(pcm_id, VoMMode2_RX_PLAYBACK_DAI_ID, size)) { |
| 349 | tp = &prtd->session[VOMMODE2_INDEX].rx_tap_point; |
| 350 | } else { |
| 351 | pr_err("%s: wrong dai id\n", __func__); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return tp; |
| 356 | } |
| 357 | |
| 358 | static struct tappnt_mxr_data *hpcm_get_tappnt_mixer_data(char *pcm_id, |
| 359 | struct hpcm_drv *prtd) |
| 360 | { |
| 361 | |
| 362 | if (strnstr(pcm_id, VOICE_TX_CAPTURE_DAI_ID, strlen(pcm_id)) || |
| 363 | strnstr(pcm_id, VOICE_TX_PLAYBACK_DAI_ID, strlen(pcm_id)) || |
| 364 | strnstr(pcm_id, VOLTE_TX_CAPTURE_DAI_ID, strlen(pcm_id)) || |
| 365 | strnstr(pcm_id, VOLTE_TX_PLAYBACK_DAI_ID, strlen(pcm_id)) || |
| 366 | strnstr(pcm_id, VoMMode1_TX_CAPTURE_DAI_ID, strlen(pcm_id)) || |
| 367 | strnstr(pcm_id, VoMMode1_TX_PLAYBACK_DAI_ID, strlen(pcm_id)) || |
| 368 | strnstr(pcm_id, VoMMode2_TX_CAPTURE_DAI_ID, strlen(pcm_id)) || |
| 369 | strnstr(pcm_id, VoMMode2_TX_PLAYBACK_DAI_ID, strlen(pcm_id))) { |
| 370 | return &prtd->mixer_conf.tx; |
| 371 | } else { |
| 372 | return &prtd->mixer_conf.rx; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | static int get_tappnt_value(char *pcm_id) |
| 377 | { |
| 378 | |
| 379 | if (strnstr(pcm_id, VOICE_TX_CAPTURE_DAI_ID, strlen(pcm_id)) || |
| 380 | strnstr(pcm_id, VOICE_TX_PLAYBACK_DAI_ID, strlen(pcm_id)) || |
| 381 | strnstr(pcm_id, VOLTE_TX_CAPTURE_DAI_ID, strlen(pcm_id)) || |
| 382 | strnstr(pcm_id, VOLTE_TX_PLAYBACK_DAI_ID, strlen(pcm_id)) || |
| 383 | strnstr(pcm_id, VoMMode1_TX_CAPTURE_DAI_ID, strlen(pcm_id)) || |
| 384 | strnstr(pcm_id, VoMMode1_TX_PLAYBACK_DAI_ID, strlen(pcm_id)) || |
| 385 | strnstr(pcm_id, VoMMode2_TX_CAPTURE_DAI_ID, strlen(pcm_id)) || |
| 386 | strnstr(pcm_id, VoMMode2_TX_PLAYBACK_DAI_ID, strlen(pcm_id))) { |
| 387 | return TX; |
| 388 | } else { |
| 389 | return RX; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | static bool hpcm_all_dais_are_ready(uint16_t direction, struct tap_point *tp, |
| 394 | enum hpcm_state state) |
| 395 | { |
| 396 | bool dais_started = false; |
| 397 | |
| 398 | /* |
| 399 | * Based on the direction set per tap point in the mixer control, |
| 400 | * all the dais per tap point should meet the required state for the |
| 401 | * commands such as vpcm_map_memory/vpcm_start to be executed. |
| 402 | */ |
| 403 | switch (direction) { |
| 404 | case VSS_IVPCM_TAP_POINT_DIR_OUT_IN: |
| 405 | if ((tp->playback_dai_data.state >= state) && |
| 406 | (tp->capture_dai_data.state >= state)) { |
| 407 | dais_started = true; |
| 408 | } |
| 409 | break; |
| 410 | |
| 411 | case VSS_IVPCM_TAP_POINT_DIR_IN: |
| 412 | if (tp->playback_dai_data.state >= state) |
| 413 | dais_started = true; |
| 414 | break; |
| 415 | |
| 416 | case VSS_IVPCM_TAP_POINT_DIR_OUT: |
| 417 | if (tp->capture_dai_data.state >= state) |
| 418 | dais_started = true; |
| 419 | break; |
| 420 | |
| 421 | default: |
| 422 | pr_err("invalid direction\n"); |
| 423 | } |
| 424 | |
| 425 | return dais_started; |
| 426 | } |
| 427 | |
| 428 | static void hpcm_create_free_queue(struct snd_dma_buffer *dma_buf, |
| 429 | struct dai_data *dai_data) |
| 430 | { |
| 431 | struct hpcm_buf_node *buf_node = NULL; |
| 432 | int i = 0, offset = 0; |
| 433 | |
| 434 | for (i = 0; i < HPCM_MAX_Q_LEN; i++) { |
| 435 | buf_node = (void *)dma_buf->area + offset; |
| 436 | list_add_tail(&buf_node->list, |
| 437 | &dai_data->free_queue); |
| 438 | offset = offset + sizeof(struct hpcm_buf_node); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | static void hpcm_free_allocated_mem(struct hpcm_drv *prtd) |
| 443 | { |
| 444 | phys_addr_t paddr = 0; |
| 445 | struct tap_point *txtp = NULL; |
| 446 | struct tap_point *rxtp = NULL; |
| 447 | struct session *sess = NULL; |
| 448 | |
| 449 | sess = &prtd->session[prtd->mixer_conf.sess_indx]; |
| 450 | txtp = &sess->tx_tap_point; |
| 451 | rxtp = &sess->rx_tap_point; |
| 452 | paddr = sess->sess_paddr; |
| 453 | |
| 454 | if (paddr) { |
| 455 | msm_audio_ion_free(prtd->ion_client, sess->ion_handle); |
| 456 | prtd->ion_client = NULL; |
| 457 | sess->ion_handle = NULL; |
| 458 | msm_audio_ion_free(sess->tp_mem_table.client, |
| 459 | sess->tp_mem_table.handle); |
| 460 | sess->tp_mem_table.client = NULL; |
| 461 | sess->tp_mem_table.handle = NULL; |
| 462 | sess->sess_paddr = 0; |
| 463 | sess->sess_kvaddr = 0; |
| 464 | sess->ion_handle = 0; |
| 465 | prtd->ion_client = 0; |
| 466 | sess->tp_mem_table.client = 0; |
| 467 | sess->tp_mem_table.handle = 0; |
| 468 | |
| 469 | txtp->capture_dai_data.vocpcm_ion_buffer.paddr = 0; |
| 470 | txtp->capture_dai_data.vocpcm_ion_buffer.kvaddr = 0; |
| 471 | |
| 472 | txtp->playback_dai_data.vocpcm_ion_buffer.paddr = 0; |
| 473 | txtp->playback_dai_data.vocpcm_ion_buffer.kvaddr = 0; |
| 474 | |
| 475 | rxtp->capture_dai_data.vocpcm_ion_buffer.paddr = 0; |
| 476 | rxtp->capture_dai_data.vocpcm_ion_buffer.kvaddr = 0; |
| 477 | |
| 478 | rxtp->playback_dai_data.vocpcm_ion_buffer.paddr = 0; |
| 479 | rxtp->playback_dai_data.vocpcm_ion_buffer.kvaddr = 0; |
| 480 | } else { |
| 481 | pr_debug("%s, paddr = 0, nothing to free\n", __func__); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | static void hpcm_unmap_and_free_shared_memory(struct hpcm_drv *prtd) |
| 486 | |
| 487 | { |
| 488 | phys_addr_t paddr = 0; |
| 489 | char *sess_name = hpcm_get_sess_name(prtd->mixer_conf.sess_indx); |
| 490 | |
| 491 | if (prtd->mixer_conf.sess_indx >= 0) |
| 492 | paddr = prtd->session[prtd->mixer_conf.sess_indx].sess_paddr; |
| 493 | else |
| 494 | paddr = 0; |
| 495 | |
| 496 | if (paddr) { |
| 497 | voc_send_cvp_unmap_vocpcm_memory(voc_get_session_id(sess_name)); |
| 498 | hpcm_free_allocated_mem(prtd); |
| 499 | } else { |
| 500 | pr_debug("%s, paddr = 0, nothing to unmap/free\n", __func__); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | static int hpcm_map_vocpcm_memory(struct hpcm_drv *prtd) |
| 505 | { |
| 506 | int ret = 0; |
| 507 | char *sess_name = hpcm_get_sess_name(prtd->mixer_conf.sess_indx); |
| 508 | struct session *sess = NULL; |
| 509 | |
| 510 | sess = &prtd->session[prtd->mixer_conf.sess_indx]; |
| 511 | |
| 512 | ret = voc_send_cvp_map_vocpcm_memory(voc_get_session_id(sess_name), |
| 513 | &sess->tp_mem_table, |
| 514 | sess->sess_paddr, |
| 515 | VHPCM_BLOCK_SIZE); |
| 516 | |
| 517 | return ret; |
| 518 | } |
| 519 | |
| 520 | static int hpcm_allocate_shared_memory(struct hpcm_drv *prtd) |
| 521 | { |
| 522 | int result; |
| 523 | int ret = 0; |
| 524 | size_t mem_len; |
| 525 | size_t len; |
| 526 | struct tap_point *txtp = NULL; |
| 527 | struct tap_point *rxtp = NULL; |
| 528 | struct session *sess = NULL; |
| 529 | |
| 530 | sess = &prtd->session[prtd->mixer_conf.sess_indx]; |
| 531 | txtp = &sess->tx_tap_point; |
| 532 | rxtp = &sess->rx_tap_point; |
| 533 | |
| 534 | result = msm_audio_ion_alloc("host_pcm_buffer", |
| 535 | &prtd->ion_client, |
| 536 | &sess->ion_handle, |
| 537 | VHPCM_BLOCK_SIZE, |
| 538 | &sess->sess_paddr, |
| 539 | &mem_len, |
| 540 | &sess->sess_kvaddr); |
| 541 | if (result) { |
| 542 | pr_err("%s: msm_audio_ion_alloc error, rc = %d\n", |
| 543 | __func__, result); |
| 544 | sess->sess_paddr = 0; |
| 545 | sess->sess_kvaddr = 0; |
| 546 | ret = -ENOMEM; |
| 547 | goto done; |
| 548 | } |
| 549 | pr_debug("%s: Host PCM memory block allocated\n", __func__); |
| 550 | |
| 551 | /* Allocate mem_map_table for tap point */ |
| 552 | result = msm_audio_ion_alloc("host_pcm_table", |
| 553 | &sess->tp_mem_table.client, |
| 554 | &sess->tp_mem_table.handle, |
| 555 | sizeof(struct vss_imemory_table_t), |
| 556 | &sess->tp_mem_table.phys, |
| 557 | &len, |
| 558 | &sess->tp_mem_table.data); |
| 559 | |
| 560 | if (result) { |
| 561 | pr_err("%s: msm_audio_ion_alloc error, rc = %d\n", |
| 562 | __func__, result); |
| 563 | msm_audio_ion_free(prtd->ion_client, sess->ion_handle); |
| 564 | prtd->ion_client = NULL; |
| 565 | sess->ion_handle = NULL; |
| 566 | sess->sess_paddr = 0; |
| 567 | sess->sess_kvaddr = 0; |
| 568 | ret = -ENOMEM; |
| 569 | goto done; |
| 570 | } |
| 571 | pr_debug("%s: Host PCM memory table allocated\n", __func__); |
| 572 | |
| 573 | memset(sess->tp_mem_table.data, 0, |
| 574 | sizeof(struct vss_imemory_table_t)); |
| 575 | |
| 576 | sess->tp_mem_table.size = sizeof(struct vss_imemory_table_t); |
| 577 | |
| 578 | pr_debug("%s: data %pK phys %pK\n", __func__, |
| 579 | sess->tp_mem_table.data, &sess->tp_mem_table.phys); |
| 580 | |
| 581 | /* Split 4096 block into four 1024 byte blocks for each dai */ |
| 582 | txtp->capture_dai_data.vocpcm_ion_buffer.paddr = |
| 583 | sess->sess_paddr; |
| 584 | txtp->capture_dai_data.vocpcm_ion_buffer.kvaddr = |
| 585 | sess->sess_kvaddr; |
| 586 | |
| 587 | txtp->playback_dai_data.vocpcm_ion_buffer.paddr = |
| 588 | sess->sess_paddr + VHPCM_BLOCK_SIZE/4; |
| 589 | txtp->playback_dai_data.vocpcm_ion_buffer.kvaddr = |
| 590 | sess->sess_kvaddr + VHPCM_BLOCK_SIZE/4; |
| 591 | |
| 592 | rxtp->capture_dai_data.vocpcm_ion_buffer.paddr = |
| 593 | sess->sess_paddr + (VHPCM_BLOCK_SIZE/4) * 2; |
| 594 | rxtp->capture_dai_data.vocpcm_ion_buffer.kvaddr = |
| 595 | sess->sess_kvaddr + (VHPCM_BLOCK_SIZE/4) * 2; |
| 596 | |
| 597 | rxtp->playback_dai_data.vocpcm_ion_buffer.paddr = |
| 598 | sess->sess_paddr + (VHPCM_BLOCK_SIZE/4) * 3; |
| 599 | rxtp->playback_dai_data.vocpcm_ion_buffer.kvaddr = |
| 600 | sess->sess_kvaddr + (VHPCM_BLOCK_SIZE/4) * 3; |
| 601 | |
| 602 | done: |
| 603 | return ret; |
| 604 | } |
| 605 | |
| 606 | static int hpcm_start_vocpcm(char *pcm_id, struct hpcm_drv *prtd, |
| 607 | struct tap_point *tp) |
| 608 | { |
| 609 | int indx = prtd->mixer_conf.sess_indx; |
| 610 | uint32_t *no_of_tp = &prtd->start_cmd.no_of_tapoints; |
| 611 | struct vss_ivpcm_tap_point *tap_pnt = &prtd->start_cmd.tap_pnt[0]; |
| 612 | uint32_t no_of_tp_req = 0; |
| 613 | char *sess_name = hpcm_get_sess_name(indx); |
| 614 | |
| 615 | if (prtd->mixer_conf.rx.enable) |
| 616 | no_of_tp_req++; |
| 617 | if (prtd->mixer_conf.tx.enable) |
| 618 | no_of_tp_req++; |
| 619 | |
| 620 | if (prtd->mixer_conf.rx.enable && (get_tappnt_value(pcm_id) == RX)) { |
| 621 | if (hpcm_all_dais_are_ready(prtd->mixer_conf.rx.direction, |
| 622 | tp, HPCM_PREPARED)) { |
| 623 | pr_debug("%s: RX conditions met\n", __func__); |
| 624 | tap_pnt[*no_of_tp].tap_point = |
| 625 | VSS_IVPCM_TAP_POINT_RX_DEFAULT; |
| 626 | tap_pnt[*no_of_tp].direction = |
| 627 | prtd->mixer_conf.rx.direction; |
| 628 | tap_pnt[*no_of_tp].sampling_rate = |
| 629 | prtd->mixer_conf.rx.sample_rate; |
| 630 | (*no_of_tp)++; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | if (prtd->mixer_conf.tx.enable && (get_tappnt_value(pcm_id) == TX)) { |
| 635 | if (hpcm_all_dais_are_ready(prtd->mixer_conf.tx.direction, |
| 636 | tp, HPCM_PREPARED)) { |
| 637 | pr_debug("%s: TX conditions met\n", __func__); |
| 638 | tap_pnt[*no_of_tp].tap_point = |
| 639 | VSS_IVPCM_TAP_POINT_TX_DEFAULT; |
| 640 | tap_pnt[*no_of_tp].direction = |
| 641 | prtd->mixer_conf.tx.direction; |
| 642 | tap_pnt[*no_of_tp].sampling_rate = |
| 643 | prtd->mixer_conf.tx.sample_rate; |
| 644 | (*no_of_tp)++; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | if ((prtd->mixer_conf.tx.enable || prtd->mixer_conf.rx.enable) && |
| 649 | *no_of_tp == no_of_tp_req) { |
| 650 | voc_send_cvp_start_vocpcm(voc_get_session_id(sess_name), |
| 651 | tap_pnt, *no_of_tp); |
| 652 | /* Reset the start command so that it is not called twice */ |
| 653 | memset(&prtd->start_cmd, 0, sizeof(struct start_cmd)); |
| 654 | } else { |
| 655 | pr_debug("%s: required pcm handles not opened yet\n", __func__); |
| 656 | } |
| 657 | |
| 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | /* Playback path*/ |
| 662 | static void hpcm_copy_playback_data_from_queue(struct dai_data *dai_data, |
| 663 | uint32_t *len) |
| 664 | { |
| 665 | struct hpcm_buf_node *buf_node = NULL; |
| 666 | unsigned long dsp_flags; |
| 667 | |
| 668 | if (dai_data->substream == NULL) |
| 669 | return; |
| 670 | |
| 671 | spin_lock_irqsave(&dai_data->dsp_lock, dsp_flags); |
| 672 | |
| 673 | if (!list_empty(&dai_data->filled_queue)) { |
| 674 | buf_node = list_first_entry(&dai_data->filled_queue, |
| 675 | struct hpcm_buf_node, list); |
| 676 | list_del(&buf_node->list); |
| 677 | *len = buf_node->frame.len; |
| 678 | memcpy((u8 *)dai_data->vocpcm_ion_buffer.kvaddr, |
| 679 | &buf_node->frame.voc_pkt[0], |
| 680 | buf_node->frame.len); |
| 681 | |
| 682 | list_add_tail(&buf_node->list, &dai_data->free_queue); |
| 683 | dai_data->pcm_irq_pos += dai_data->pcm_count; |
| 684 | spin_unlock_irqrestore(&dai_data->dsp_lock, dsp_flags); |
| 685 | snd_pcm_period_elapsed(dai_data->substream); |
| 686 | } else { |
| 687 | *len = 0; |
| 688 | spin_unlock_irqrestore(&dai_data->dsp_lock, dsp_flags); |
| 689 | pr_err("IN data not available\n"); |
| 690 | } |
| 691 | |
| 692 | wake_up(&dai_data->queue_wait); |
| 693 | } |
| 694 | |
| 695 | /* Capture path*/ |
| 696 | static void hpcm_copy_capture_data_to_queue(struct dai_data *dai_data, |
| 697 | uint32_t len) |
| 698 | { |
| 699 | struct hpcm_buf_node *buf_node = NULL; |
| 700 | unsigned long dsp_flags; |
| 701 | |
| 702 | if (dai_data->substream == NULL) |
| 703 | return; |
| 704 | |
| 705 | /* Copy out buffer packet into free_queue */ |
| 706 | spin_lock_irqsave(&dai_data->dsp_lock, dsp_flags); |
| 707 | |
| 708 | if (!list_empty(&dai_data->free_queue)) { |
| 709 | buf_node = list_first_entry(&dai_data->free_queue, |
| 710 | struct hpcm_buf_node, list); |
| 711 | list_del(&buf_node->list); |
| 712 | buf_node->frame.len = len; |
| 713 | memcpy(&buf_node->frame.voc_pkt[0], |
| 714 | (uint8_t *)dai_data->vocpcm_ion_buffer.kvaddr, |
| 715 | buf_node->frame.len); |
| 716 | list_add_tail(&buf_node->list, &dai_data->filled_queue); |
| 717 | dai_data->pcm_irq_pos += dai_data->pcm_count; |
| 718 | spin_unlock_irqrestore(&dai_data->dsp_lock, dsp_flags); |
| 719 | snd_pcm_period_elapsed(dai_data->substream); |
| 720 | } else { |
| 721 | spin_unlock_irqrestore(&dai_data->dsp_lock, dsp_flags); |
| 722 | pr_err("OUTPUT data dropped\n"); |
| 723 | } |
| 724 | |
| 725 | wake_up(&dai_data->queue_wait); |
| 726 | } |
| 727 | |
| 728 | void hpcm_notify_evt_processing(uint8_t *data, char *session, |
| 729 | void *private_data) |
| 730 | { |
| 731 | struct hpcm_drv *prtd = (struct hpcm_drv *)private_data; |
| 732 | struct vss_ivpcm_evt_notify_v2_t *notify_evt = |
| 733 | (struct vss_ivpcm_evt_notify_v2_t *)data; |
| 734 | struct vss_ivpcm_evt_push_buffer_v2_t push_buff_event; |
| 735 | struct tap_point *tp = NULL; |
| 736 | int in_buf_len = 0; |
| 737 | struct tappnt_mxr_data *tmd = NULL; |
| 738 | char *sess_name = hpcm_get_sess_name(prtd->mixer_conf.sess_indx); |
| 739 | |
| 740 | /* If it's not a timetick, it's a error notification, drop the event */ |
| 741 | if ((notify_evt->notify_mask & VSS_IVPCM_NOTIFY_MASK_TIMETICK) == 0) { |
| 742 | pr_err("%s: Error notification. mask=%d\n", __func__, |
| 743 | notify_evt->notify_mask); |
| 744 | return; |
| 745 | } |
| 746 | |
| 747 | if (notify_evt->tap_point == VSS_IVPCM_TAP_POINT_TX_DEFAULT) { |
| 748 | tp = &prtd->session[prtd->mixer_conf.sess_indx].tx_tap_point; |
| 749 | tmd = &prtd->mixer_conf.tx; |
| 750 | } else if (notify_evt->tap_point == VSS_IVPCM_TAP_POINT_RX_DEFAULT) { |
| 751 | tp = &prtd->session[prtd->mixer_conf.sess_indx].rx_tap_point; |
| 752 | tmd = &prtd->mixer_conf.rx; |
| 753 | } |
| 754 | |
| 755 | if (tp == NULL || tmd == NULL) { |
| 756 | pr_err("%s: tp = %pK or tmd = %pK is null\n", __func__, |
| 757 | tp, tmd); |
| 758 | |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | if (notify_evt->notify_mask & VSS_IVPCM_NOTIFY_MASK_OUTPUT_BUFFER) { |
| 763 | hpcm_copy_capture_data_to_queue(&tp->capture_dai_data, |
| 764 | notify_evt->filled_out_size); |
| 765 | } |
| 766 | |
| 767 | if (notify_evt->notify_mask & VSS_IVPCM_NOTIFY_MASK_INPUT_BUFFER) { |
| 768 | hpcm_copy_playback_data_from_queue(&tp->playback_dai_data, |
| 769 | &in_buf_len); |
| 770 | } |
| 771 | |
| 772 | switch (tmd->direction) { |
| 773 | /* |
| 774 | * When the dir is OUT_IN, for the first notify mask, pushbuf mask |
| 775 | * should be set to VSS_IVPCM_PUSH_BUFFER_MASK_OUTPUT_BUFFER since we |
| 776 | * atleast need one buffer's worth data before we can send IN buffer. |
| 777 | * For the consecutive notify evts, the push buf mask will set for both |
| 778 | * VSS_IVPCM_PUSH_BUFFER_MASK_OUTPUT_BUFFER and |
| 779 | * VSS_IVPCM_PUSH_BUFFER_MASK_IN_BUFFER. |
| 780 | */ |
| 781 | case VSS_IVPCM_TAP_POINT_DIR_OUT_IN: |
| 782 | if (notify_evt->notify_mask == |
| 783 | VSS_IVPCM_NOTIFY_MASK_TIMETICK) { |
| 784 | push_buff_event.push_buf_mask = |
| 785 | VSS_IVPCM_PUSH_BUFFER_MASK_OUTPUT_BUFFER; |
| 786 | } else { |
| 787 | push_buff_event.push_buf_mask = |
| 788 | VSS_IVPCM_PUSH_BUFFER_MASK_OUTPUT_BUFFER | |
| 789 | VSS_IVPCM_PUSH_BUFFER_MASK_INPUT_BUFFER; |
| 790 | } |
| 791 | break; |
| 792 | |
| 793 | case VSS_IVPCM_TAP_POINT_DIR_IN: |
| 794 | push_buff_event.push_buf_mask = |
| 795 | VSS_IVPCM_PUSH_BUFFER_MASK_INPUT_BUFFER; |
| 796 | break; |
| 797 | |
| 798 | case VSS_IVPCM_TAP_POINT_DIR_OUT: |
| 799 | push_buff_event.push_buf_mask = |
| 800 | VSS_IVPCM_PUSH_BUFFER_MASK_OUTPUT_BUFFER; |
| 801 | break; |
| 802 | } |
| 803 | |
| 804 | push_buff_event.tap_point = notify_evt->tap_point; |
| 805 | push_buff_event.out_buf_mem_address = |
| 806 | tp->capture_dai_data.vocpcm_ion_buffer.paddr; |
| 807 | push_buff_event.in_buf_mem_address = |
| 808 | tp->playback_dai_data.vocpcm_ion_buffer.paddr; |
| 809 | push_buff_event.sampling_rate = notify_evt->sampling_rate; |
| 810 | push_buff_event.num_in_channels = 1; |
| 811 | |
| 812 | /* |
| 813 | * ADSP must read and write from a cache aligned (128 byte) location, |
| 814 | * and in blocks of the cache alignment size. The 128 byte cache |
| 815 | * alignment requirement is guaranteed due to 4096 byte memory |
| 816 | * alignment requirement during memory allocation/mapping. The output |
| 817 | * buffer (ADSP write) size mask ensures that a 128 byte multiple |
| 818 | * worth of will be written. Internally, the input buffer (ADSP read) |
| 819 | * size will also be a multiple of 128 bytes. However it is the |
| 820 | * application's responsibility to ensure no other data is written in |
| 821 | * the specified length of memory. |
| 822 | */ |
| 823 | push_buff_event.out_buf_mem_size = ((notify_evt->request_buf_size) + |
| 824 | CACHE_ALIGNMENT_SIZE) & CACHE_ALIGNMENT_MASK; |
| 825 | push_buff_event.in_buf_mem_size = in_buf_len; |
| 826 | |
| 827 | voc_send_cvp_vocpcm_push_buf_evt(voc_get_session_id(sess_name), |
| 828 | &push_buff_event); |
| 829 | } |
| 830 | |
| 831 | static int msm_hpcm_configure_voice_put(struct snd_kcontrol *kcontrol, |
| 832 | struct snd_ctl_elem_value *ucontrol) |
| 833 | { |
| 834 | |
| 835 | int tap_point = ucontrol->value.integer.value[0]; |
| 836 | uint16_t direction = ucontrol->value.integer.value[1]; |
| 837 | uint16_t sample_rate = ucontrol->value.integer.value[2]; |
| 838 | struct tappnt_mxr_data *tmd = NULL; |
| 839 | int ret = 0; |
| 840 | |
| 841 | mutex_lock(&hpcm_drv.lock); |
| 842 | pr_debug("%s: tap_point = %d direction = %d sample_rate = %d\n", |
| 843 | __func__, tap_point, direction, sample_rate); |
| 844 | |
| 845 | if (!hpcm_is_valid_config(VOICE_INDEX, tap_point, direction, |
| 846 | sample_rate)) { |
| 847 | pr_err("Invalid vpcm mixer control voice values\n"); |
| 848 | ret = -EINVAL; |
| 849 | goto done; |
| 850 | } |
| 851 | |
| 852 | if (tap_point == RX) |
| 853 | tmd = &hpcm_drv.mixer_conf.rx; |
| 854 | else |
| 855 | tmd = &hpcm_drv.mixer_conf.tx; |
| 856 | |
| 857 | tmd->enable = true; |
| 858 | tmd->direction = direction; |
| 859 | tmd->sample_rate = sample_rate; |
| 860 | hpcm_drv.mixer_conf.sess_indx = VOICE_INDEX; |
| 861 | |
| 862 | done: |
| 863 | mutex_unlock(&hpcm_drv.lock); |
| 864 | return ret; |
| 865 | } |
| 866 | |
| 867 | static int msm_hpcm_configure_vmmode1_put(struct snd_kcontrol *kcontrol, |
| 868 | struct snd_ctl_elem_value *ucontrol) |
| 869 | { |
| 870 | |
| 871 | int tap_point = ucontrol->value.integer.value[0]; |
| 872 | uint16_t direction = ucontrol->value.integer.value[1]; |
| 873 | uint16_t sample_rate = ucontrol->value.integer.value[2]; |
| 874 | struct tappnt_mxr_data *tmd = NULL; |
| 875 | int ret = 0; |
| 876 | |
| 877 | mutex_lock(&hpcm_drv.lock); |
| 878 | pr_debug("%s: tap_point = %d direction = %d sample_rate = %d\n", |
| 879 | __func__, tap_point, direction, sample_rate); |
| 880 | |
| 881 | if (!hpcm_is_valid_config(VOMMODE1_INDEX, tap_point, direction, |
| 882 | sample_rate)) { |
| 883 | pr_err("Invalid vpcm mixer control voice values\n"); |
| 884 | ret = -EINVAL; |
| 885 | goto done; |
| 886 | } |
| 887 | |
| 888 | if (tap_point == RX) |
| 889 | tmd = &hpcm_drv.mixer_conf.rx; |
| 890 | else |
| 891 | tmd = &hpcm_drv.mixer_conf.tx; |
| 892 | |
| 893 | tmd->enable = true; |
| 894 | tmd->direction = direction; |
| 895 | tmd->sample_rate = sample_rate; |
| 896 | hpcm_drv.mixer_conf.sess_indx = VOMMODE1_INDEX; |
| 897 | |
| 898 | done: |
| 899 | mutex_unlock(&hpcm_drv.lock); |
| 900 | return ret; |
| 901 | } |
| 902 | |
| 903 | static int msm_hpcm_configure_vmmode2_put(struct snd_kcontrol *kcontrol, |
| 904 | struct snd_ctl_elem_value *ucontrol) |
| 905 | { |
| 906 | |
| 907 | int tap_point = ucontrol->value.integer.value[0]; |
| 908 | uint16_t direction = ucontrol->value.integer.value[1]; |
| 909 | uint16_t sample_rate = ucontrol->value.integer.value[2]; |
| 910 | struct tappnt_mxr_data *tmd = NULL; |
| 911 | int ret = 0; |
| 912 | |
| 913 | mutex_lock(&hpcm_drv.lock); |
| 914 | pr_debug("%s: tap_point = %d direction = %d sample_rate = %d\n", |
| 915 | __func__, tap_point, direction, sample_rate); |
| 916 | |
| 917 | if (!hpcm_is_valid_config(VOMMODE2_INDEX, tap_point, direction, |
| 918 | sample_rate)) { |
| 919 | pr_err("Invalid vpcm mixer control voice values\n"); |
| 920 | ret = -EINVAL; |
| 921 | goto done; |
| 922 | } |
| 923 | |
| 924 | if (tap_point == RX) |
| 925 | tmd = &hpcm_drv.mixer_conf.rx; |
| 926 | else |
| 927 | tmd = &hpcm_drv.mixer_conf.tx; |
| 928 | |
| 929 | tmd->enable = true; |
| 930 | tmd->direction = direction; |
| 931 | tmd->sample_rate = sample_rate; |
| 932 | hpcm_drv.mixer_conf.sess_indx = VOMMODE2_INDEX; |
| 933 | |
| 934 | done: |
| 935 | mutex_unlock(&hpcm_drv.lock); |
| 936 | return ret; |
| 937 | } |
| 938 | |
| 939 | static int msm_hpcm_configure_volte_put(struct snd_kcontrol *kcontrol, |
| 940 | struct snd_ctl_elem_value *ucontrol) |
| 941 | { |
| 942 | |
| 943 | int tap_point = ucontrol->value.integer.value[0]; |
| 944 | uint16_t direction = ucontrol->value.integer.value[1]; |
| 945 | uint16_t sample_rate = ucontrol->value.integer.value[2]; |
| 946 | struct tappnt_mxr_data *tmd = NULL; |
| 947 | int ret = 0; |
| 948 | |
| 949 | mutex_lock(&hpcm_drv.lock); |
| 950 | pr_debug("%s: tap_point=%d direction=%d sample_rate=%d\n", |
| 951 | __func__, tap_point, direction, sample_rate); |
| 952 | |
| 953 | if (!hpcm_is_valid_config(VOLTE_INDEX, tap_point, direction, |
| 954 | sample_rate)) { |
| 955 | pr_err("Invalid vpcm mixer control volte values\n"); |
| 956 | ret = -EINVAL; |
| 957 | goto done; |
| 958 | } |
| 959 | |
| 960 | if (tap_point == RX) |
| 961 | tmd = &hpcm_drv.mixer_conf.rx; |
| 962 | else |
| 963 | tmd = &hpcm_drv.mixer_conf.tx; |
| 964 | |
| 965 | tmd->enable = true; |
| 966 | tmd->direction = direction; |
| 967 | tmd->sample_rate = sample_rate; |
| 968 | hpcm_drv.mixer_conf.sess_indx = VOLTE_INDEX; |
| 969 | |
| 970 | done: |
| 971 | mutex_unlock(&hpcm_drv.lock); |
| 972 | return ret; |
| 973 | |
| 974 | } |
| 975 | |
| 976 | static struct snd_kcontrol_new msm_hpcm_controls[] = { |
| 977 | SOC_SINGLE_MULTI_EXT("HPCM_Voice tappoint direction samplerate", |
| 978 | SND_SOC_NOPM, 0, 16000, 0, 3, |
| 979 | NULL, msm_hpcm_configure_voice_put), |
| 980 | SOC_SINGLE_MULTI_EXT("HPCM_VoLTE tappoint direction samplerate", |
| 981 | SND_SOC_NOPM, 0, 16000, 0, 3, |
| 982 | NULL, msm_hpcm_configure_volte_put), |
| 983 | SOC_SINGLE_MULTI_EXT("HPCM_VMMode1 tappoint direction samplerate", |
| 984 | SND_SOC_NOPM, 0, 16000, 0, 3, |
| 985 | NULL, msm_hpcm_configure_vmmode1_put), |
| 986 | SOC_SINGLE_MULTI_EXT("HPCM_VMMode2 tappoint direction samplerate", |
| 987 | SND_SOC_NOPM, 0, 16000, 0, 3, |
| 988 | NULL, msm_hpcm_configure_vmmode2_put), |
| 989 | }; |
| 990 | |
| 991 | /* Sample rates supported */ |
| 992 | static unsigned int supported_sample_rates[] = {8000, 16000}; |
| 993 | |
| 994 | static struct snd_pcm_hw_constraint_list constraints_sample_rates = { |
| 995 | .count = ARRAY_SIZE(supported_sample_rates), |
| 996 | .list = supported_sample_rates, |
| 997 | .mask = 0, |
| 998 | }; |
| 999 | |
| 1000 | static int msm_pcm_close(struct snd_pcm_substream *substream) |
| 1001 | { |
| 1002 | int ret = 0; |
| 1003 | struct list_head *ptr = NULL; |
| 1004 | struct list_head *next = NULL; |
| 1005 | struct hpcm_buf_node *buf_node = NULL; |
| 1006 | struct snd_dma_buffer *dma_buf; |
| 1007 | struct snd_pcm_runtime *runtime; |
| 1008 | struct hpcm_drv *prtd; |
| 1009 | unsigned long dsp_flags; |
| 1010 | struct dai_data *dai_data = NULL; |
| 1011 | struct tap_point *tp = NULL; |
| 1012 | struct tappnt_mxr_data *tmd = NULL; |
| 1013 | char *sess_name = NULL; |
| 1014 | |
| 1015 | if (substream == NULL) { |
| 1016 | pr_err("substream is NULL\n"); |
| 1017 | return -EINVAL; |
| 1018 | } |
| 1019 | |
| 1020 | pr_debug("%s, %s\n", __func__, substream->pcm->id); |
| 1021 | runtime = substream->runtime; |
| 1022 | prtd = runtime->private_data; |
| 1023 | sess_name = hpcm_get_sess_name(prtd->mixer_conf.sess_indx); |
| 1024 | dai_data = hpcm_get_dai_data(substream->pcm->id, prtd); |
| 1025 | |
| 1026 | if (dai_data == NULL) { |
| 1027 | pr_err("%s, dai_data is NULL\n", __func__); |
| 1028 | |
| 1029 | ret = -EINVAL; |
| 1030 | goto done; |
| 1031 | } |
| 1032 | |
| 1033 | wake_up(&dai_data->queue_wait); |
| 1034 | mutex_lock(&prtd->lock); |
| 1035 | |
| 1036 | tmd = hpcm_get_tappnt_mixer_data(substream->pcm->id, prtd); |
| 1037 | |
| 1038 | tp = hpcm_get_tappoint_data(substream->pcm->id, prtd); |
| 1039 | /* Send stop command */ |
| 1040 | voc_send_cvp_stop_vocpcm(voc_get_session_id(sess_name)); |
| 1041 | /* Memory unmap/free takes place only when called the first time */ |
| 1042 | hpcm_unmap_and_free_shared_memory(prtd); |
| 1043 | /* Unregister host PCM event callback function */ |
| 1044 | voc_deregister_hpcm_evt_cb(); |
| 1045 | /* Reset the cached start cmd */ |
| 1046 | memset(&prtd->start_cmd, 0, sizeof(struct start_cmd)); |
| 1047 | /* Release all buffer */ |
| 1048 | pr_debug("%s: Release all buffer\n", __func__); |
| 1049 | substream = dai_data->substream; |
| 1050 | if (substream == NULL) { |
| 1051 | pr_debug("%s: substream is NULL\n", __func__); |
| 1052 | goto done; |
| 1053 | } |
| 1054 | dma_buf = &substream->dma_buffer; |
| 1055 | if (dma_buf == NULL) { |
| 1056 | pr_debug("%s: dma_buf is NULL\n", __func__); |
| 1057 | goto done; |
| 1058 | } |
| 1059 | if (dma_buf->area != NULL) { |
| 1060 | spin_lock_irqsave(&dai_data->dsp_lock, dsp_flags); |
| 1061 | list_for_each_safe(ptr, next, &dai_data->filled_queue) { |
| 1062 | buf_node = list_entry(ptr, |
| 1063 | struct hpcm_buf_node, list); |
| 1064 | list_del(&buf_node->list); |
| 1065 | } |
| 1066 | list_for_each_safe(ptr, next, &dai_data->free_queue) { |
| 1067 | buf_node = list_entry(ptr, |
| 1068 | struct hpcm_buf_node, list); |
| 1069 | list_del(&buf_node->list); |
| 1070 | } |
| 1071 | spin_unlock_irqrestore(&dai_data->dsp_lock, dsp_flags); |
| 1072 | dma_free_coherent(substream->pcm->card->dev, |
| 1073 | runtime->hw.buffer_bytes_max, dma_buf->area, |
| 1074 | dma_buf->addr); |
| 1075 | dma_buf->area = NULL; |
| 1076 | } |
| 1077 | dai_data->substream = NULL; |
| 1078 | dai_data->pcm_buf_pos = 0; |
| 1079 | dai_data->pcm_count = 0; |
| 1080 | dai_data->pcm_irq_pos = 0; |
| 1081 | dai_data->pcm_size = 0; |
| 1082 | dai_data->state = HPCM_CLOSED; |
| 1083 | hpcm_reset_mixer_config(prtd); |
| 1084 | |
| 1085 | done: |
| 1086 | mutex_unlock(&prtd->lock); |
| 1087 | return ret; |
| 1088 | } |
| 1089 | |
| 1090 | static int msm_pcm_playback_copy(struct snd_pcm_substream *substream, int a, |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1091 | unsigned long hwoff, void __user *buf, |
| 1092 | unsigned long fbytes) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1093 | { |
| 1094 | int ret = 0; |
| 1095 | struct hpcm_buf_node *buf_node = NULL; |
| 1096 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1097 | struct hpcm_drv *prtd = runtime->private_data; |
| 1098 | struct dai_data *dai_data = hpcm_get_dai_data(substream->pcm->id, prtd); |
| 1099 | unsigned long dsp_flags; |
| 1100 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1101 | if (dai_data == NULL) { |
| 1102 | pr_err("%s, dai_data is null\n", __func__); |
| 1103 | |
| 1104 | ret = -EINVAL; |
| 1105 | goto done; |
| 1106 | } |
| 1107 | |
| 1108 | ret = wait_event_interruptible_timeout(dai_data->queue_wait, |
| 1109 | (!list_empty(&dai_data->free_queue) || |
| 1110 | dai_data->state == HPCM_STOPPED), |
| 1111 | 1 * HZ); |
| 1112 | if (ret > 0) { |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1113 | if (fbytes <= HPCM_MAX_VOC_PKT_SIZE) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1114 | spin_lock_irqsave(&dai_data->dsp_lock, dsp_flags); |
| 1115 | buf_node = |
| 1116 | list_first_entry(&dai_data->free_queue, |
| 1117 | struct hpcm_buf_node, list); |
| 1118 | list_del(&buf_node->list); |
| 1119 | spin_unlock_irqrestore(&dai_data->dsp_lock, dsp_flags); |
| 1120 | ret = copy_from_user(&buf_node->frame.voc_pkt, buf, |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1121 | fbytes); |
| 1122 | buf_node->frame.len = fbytes; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1123 | spin_lock_irqsave(&dai_data->dsp_lock, dsp_flags); |
| 1124 | list_add_tail(&buf_node->list, &dai_data->filled_queue); |
| 1125 | spin_unlock_irqrestore(&dai_data->dsp_lock, dsp_flags); |
| 1126 | } else { |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1127 | pr_err("%s: Write cnt %lu is > HPCM_MAX_VOC_PKT_SIZE\n", |
| 1128 | __func__, fbytes); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1129 | ret = -ENOMEM; |
| 1130 | } |
| 1131 | } else if (ret == 0) { |
| 1132 | pr_err("%s: No free Playback buffer\n", __func__); |
| 1133 | ret = -ETIMEDOUT; |
| 1134 | } else { |
| 1135 | pr_err("%s: playback copy was interrupted\n", __func__); |
| 1136 | } |
| 1137 | |
| 1138 | done: |
| 1139 | return ret; |
| 1140 | } |
| 1141 | |
| 1142 | static int msm_pcm_capture_copy(struct snd_pcm_substream *substream, |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1143 | int channel, unsigned long hwoff, |
| 1144 | void __user *buf, unsigned long fbytes) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1145 | { |
| 1146 | int ret = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1147 | struct hpcm_buf_node *buf_node = NULL; |
| 1148 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1149 | struct hpcm_drv *prtd = runtime->private_data; |
| 1150 | struct dai_data *dai_data = hpcm_get_dai_data(substream->pcm->id, prtd); |
| 1151 | unsigned long dsp_flags; |
| 1152 | |
| 1153 | if (dai_data == NULL) { |
| 1154 | pr_err("%s, dai_data is null\n", __func__); |
| 1155 | |
| 1156 | ret = -EINVAL; |
| 1157 | goto done; |
| 1158 | } |
| 1159 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1160 | ret = wait_event_interruptible_timeout(dai_data->queue_wait, |
| 1161 | (!list_empty(&dai_data->filled_queue) || |
| 1162 | dai_data->state == HPCM_STOPPED), |
| 1163 | 1 * HZ); |
| 1164 | |
| 1165 | if (ret > 0) { |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1166 | if (fbytes <= HPCM_MAX_VOC_PKT_SIZE) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1167 | spin_lock_irqsave(&dai_data->dsp_lock, dsp_flags); |
| 1168 | buf_node = list_first_entry(&dai_data->filled_queue, |
| 1169 | struct hpcm_buf_node, list); |
| 1170 | list_del(&buf_node->list); |
| 1171 | spin_unlock_irqrestore(&dai_data->dsp_lock, dsp_flags); |
| 1172 | ret = copy_to_user(buf, &buf_node->frame.voc_pkt, |
| 1173 | buf_node->frame.len); |
| 1174 | if (ret) { |
| 1175 | pr_err("%s: Copy to user returned %d\n", |
| 1176 | __func__, ret); |
| 1177 | ret = -EFAULT; |
| 1178 | } |
| 1179 | spin_lock_irqsave(&dai_data->dsp_lock, dsp_flags); |
| 1180 | list_add_tail(&buf_node->list, &dai_data->free_queue); |
| 1181 | spin_unlock_irqrestore(&dai_data->dsp_lock, dsp_flags); |
| 1182 | |
| 1183 | } else { |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1184 | pr_err("%s: Read count %lu > HPCM_MAX_VOC_PKT_SIZE\n", |
| 1185 | __func__, fbytes); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1186 | ret = -ENOMEM; |
| 1187 | } |
| 1188 | |
| 1189 | } else if (ret == 0) { |
| 1190 | pr_err("%s: No Caputre data available\n", __func__); |
| 1191 | ret = -ETIMEDOUT; |
| 1192 | } else { |
| 1193 | pr_err("%s: Read was interrupted\n", __func__); |
| 1194 | ret = -ERESTARTSYS; |
| 1195 | } |
| 1196 | |
| 1197 | done: |
| 1198 | return ret; |
| 1199 | } |
| 1200 | |
| 1201 | static int msm_pcm_copy(struct snd_pcm_substream *substream, int channel, |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1202 | unsigned long hwoff, void __user *buf, |
| 1203 | unsigned long fbytes) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1204 | { |
| 1205 | int ret = 0; |
| 1206 | |
| 1207 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 1208 | ret = msm_pcm_playback_copy(substream, channel, |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1209 | hwoff, buf, fbytes); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1210 | else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 1211 | ret = msm_pcm_capture_copy(substream, channel, |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1212 | hwoff, buf, fbytes); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1213 | |
| 1214 | return ret; |
| 1215 | } |
| 1216 | |
| 1217 | static snd_pcm_uframes_t msm_pcm_pointer(struct snd_pcm_substream *substream) |
| 1218 | { |
| 1219 | struct dai_data *dai_data = NULL; |
| 1220 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1221 | struct hpcm_drv *prtd = runtime->private_data; |
| 1222 | snd_pcm_uframes_t ret; |
| 1223 | |
| 1224 | dai_data = hpcm_get_dai_data(substream->pcm->id, prtd); |
| 1225 | |
| 1226 | if (dai_data == NULL) { |
| 1227 | pr_err("%s, dai_data is null\n", __func__); |
| 1228 | |
| 1229 | ret = 0; |
| 1230 | goto done; |
| 1231 | } |
| 1232 | |
| 1233 | if (dai_data->pcm_irq_pos >= dai_data->pcm_size) |
| 1234 | dai_data->pcm_irq_pos = 0; |
| 1235 | |
| 1236 | ret = bytes_to_frames(runtime, (dai_data->pcm_irq_pos)); |
| 1237 | |
| 1238 | done: |
| 1239 | return ret; |
| 1240 | } |
| 1241 | |
| 1242 | static int msm_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 1243 | { |
| 1244 | int ret = 0; |
| 1245 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1246 | struct hpcm_drv *prtd = runtime->private_data; |
| 1247 | struct dai_data *dai_data = |
| 1248 | hpcm_get_dai_data(substream->pcm->id, prtd); |
| 1249 | |
| 1250 | if (dai_data == NULL) { |
| 1251 | pr_err("%s, dai_data is null\n", __func__); |
| 1252 | |
| 1253 | ret = -EINVAL; |
| 1254 | goto done; |
| 1255 | } |
| 1256 | |
| 1257 | pr_debug("%s, %s\n", __func__, substream->pcm->id); |
| 1258 | |
| 1259 | switch (cmd) { |
| 1260 | case SNDRV_PCM_TRIGGER_START: |
| 1261 | pr_debug("SNDRV_PCM_TRIGGER_START\n"); |
| 1262 | dai_data->state = HPCM_STARTED; |
| 1263 | break; |
| 1264 | |
| 1265 | case SNDRV_PCM_TRIGGER_STOP: |
| 1266 | pr_debug("SNDRV_PCM_TRIGGER_STOP\n"); |
| 1267 | dai_data->state = HPCM_STOPPED; |
| 1268 | break; |
| 1269 | |
| 1270 | default: |
| 1271 | ret = -EINVAL; |
| 1272 | break; |
| 1273 | } |
| 1274 | |
| 1275 | done: |
| 1276 | return ret; |
| 1277 | } |
| 1278 | |
| 1279 | static int msm_pcm_prepare(struct snd_pcm_substream *substream) |
| 1280 | { |
| 1281 | int ret = 0; |
| 1282 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1283 | struct hpcm_drv *prtd = runtime->private_data; |
| 1284 | struct dai_data *dai_data = NULL; |
| 1285 | struct tap_point *tp = NULL; |
| 1286 | |
| 1287 | pr_debug("%s, %s\n", __func__, substream->pcm->id); |
| 1288 | mutex_lock(&prtd->lock); |
| 1289 | |
| 1290 | dai_data = hpcm_get_dai_data(substream->pcm->id, prtd); |
| 1291 | |
| 1292 | if (dai_data == NULL) { |
| 1293 | pr_err("%s, dai_data is null\n", __func__); |
| 1294 | |
| 1295 | ret = -EINVAL; |
| 1296 | goto done; |
| 1297 | } |
| 1298 | |
| 1299 | dai_data->pcm_size = snd_pcm_lib_buffer_bytes(substream); |
| 1300 | dai_data->pcm_count = snd_pcm_lib_period_bytes(substream); |
| 1301 | dai_data->pcm_irq_pos = 0; |
| 1302 | dai_data->pcm_buf_pos = 0; |
| 1303 | dai_data->state = HPCM_PREPARED; |
| 1304 | |
| 1305 | /* Register event notify processing callback in prepare instead of |
| 1306 | * init() as q6voice module's init() can be called at a later point |
| 1307 | */ |
| 1308 | voc_register_hpcm_evt_cb(hpcm_notify_evt_processing, &hpcm_drv); |
| 1309 | |
| 1310 | tp = hpcm_get_tappoint_data(substream->pcm->id, prtd); |
| 1311 | if (tp != NULL) { |
| 1312 | ret = hpcm_start_vocpcm(substream->pcm->id, prtd, tp); |
| 1313 | if (ret) { |
| 1314 | pr_err("error sending start cmd err=%d\n", ret); |
| 1315 | goto done; |
| 1316 | } |
| 1317 | } else { |
| 1318 | pr_err("%s tp is NULL\n", __func__); |
| 1319 | } |
| 1320 | done: |
| 1321 | mutex_unlock(&prtd->lock); |
| 1322 | return ret; |
| 1323 | } |
| 1324 | |
| 1325 | static int msm_pcm_hw_params(struct snd_pcm_substream *substream, |
| 1326 | struct snd_pcm_hw_params *params) |
| 1327 | { |
| 1328 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1329 | struct snd_dma_buffer *dma_buf = &substream->dma_buffer; |
| 1330 | struct hpcm_drv *prtd = (struct hpcm_drv *)runtime->private_data; |
| 1331 | int ret = 0; |
| 1332 | |
| 1333 | pr_debug("%s: %s\n", __func__, substream->pcm->id); |
| 1334 | mutex_lock(&prtd->lock); |
| 1335 | |
| 1336 | /* Allocate and map voice host PCM ion buffer */ |
| 1337 | if (prtd->session[prtd->mixer_conf.sess_indx].sess_paddr == 0) { |
| 1338 | ret = hpcm_allocate_shared_memory(prtd); |
| 1339 | if (ret) { |
| 1340 | pr_err("error creating shared memory err=%d\n", ret); |
| 1341 | goto done; |
| 1342 | } |
| 1343 | |
| 1344 | ret = hpcm_map_vocpcm_memory(prtd); |
| 1345 | if (ret) { |
| 1346 | pr_err("error mapping shared memory err=%d\n", ret); |
| 1347 | hpcm_free_allocated_mem(prtd); |
| 1348 | goto done; |
| 1349 | } |
| 1350 | } else { |
| 1351 | pr_debug("%s, VHPCM memory allocation/mapping not performed\n" |
| 1352 | , __func__); |
| 1353 | } |
| 1354 | |
| 1355 | dma_buf->dev.type = SNDRV_DMA_TYPE_DEV; |
| 1356 | dma_buf->dev.dev = substream->pcm->card->dev; |
| 1357 | dma_buf->private_data = NULL; |
| 1358 | |
| 1359 | dma_buf->area = dma_alloc_coherent(substream->pcm->card->dev, |
| 1360 | runtime->hw.buffer_bytes_max, |
| 1361 | &dma_buf->addr, GFP_KERNEL); |
| 1362 | |
| 1363 | if (!dma_buf->area) { |
| 1364 | pr_err("%s:MSM dma_alloc failed\n", __func__); |
| 1365 | ret = -ENOMEM; |
| 1366 | goto done; |
| 1367 | } |
| 1368 | |
| 1369 | dma_buf->bytes = runtime->hw.buffer_bytes_max; |
| 1370 | memset(dma_buf->area, 0, runtime->hw.buffer_bytes_max); |
| 1371 | |
| 1372 | hpcm_create_free_queue(dma_buf, |
| 1373 | hpcm_get_dai_data(substream->pcm->id, prtd)); |
| 1374 | |
| 1375 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); |
| 1376 | |
| 1377 | done: |
| 1378 | mutex_unlock(&prtd->lock); |
| 1379 | return ret; |
| 1380 | } |
| 1381 | |
| 1382 | static int msm_pcm_open(struct snd_pcm_substream *substream) |
| 1383 | { |
| 1384 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1385 | struct hpcm_drv *prtd = &hpcm_drv; |
| 1386 | struct tappnt_mxr_data *tmd = NULL; |
| 1387 | struct dai_data *dai_data = NULL; |
| 1388 | int ret = 0; |
| 1389 | int tp_val = 0; |
| 1390 | |
| 1391 | pr_debug("%s, %s\n", __func__, substream->pcm->id); |
| 1392 | mutex_lock(&prtd->lock); |
| 1393 | |
| 1394 | dai_data = hpcm_get_dai_data(substream->pcm->id, prtd); |
| 1395 | |
| 1396 | if (dai_data == NULL) { |
| 1397 | pr_err("%s, dai_data is null\n", __func__); |
| 1398 | |
| 1399 | ret = -EINVAL; |
| 1400 | goto done; |
| 1401 | } |
| 1402 | |
| 1403 | runtime->hw = msm_pcm_hardware; |
| 1404 | |
| 1405 | ret = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 1406 | &constraints_sample_rates); |
| 1407 | if (ret < 0) |
| 1408 | pr_debug("snd_pcm_hw_constraint_list failed\n"); |
| 1409 | |
| 1410 | ret = snd_pcm_hw_constraint_integer(runtime, |
| 1411 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 1412 | if (ret < 0) { |
| 1413 | pr_debug("snd_pcm_hw_constraint_integer failed\n"); |
| 1414 | goto done; |
| 1415 | } |
| 1416 | |
| 1417 | tp_val = get_tappnt_value(substream->pcm->id); |
| 1418 | tmd = hpcm_get_tappnt_mixer_data(substream->pcm->id, prtd); |
| 1419 | |
| 1420 | /* Check wheather the kcontrol values set are valid */ |
| 1421 | if (!tmd || |
| 1422 | !(tmd->enable) || |
| 1423 | !hpcm_is_valid_config(prtd->mixer_conf.sess_indx, |
| 1424 | tp_val, tmd->direction, |
| 1425 | tmd->sample_rate)) { |
| 1426 | ret = -EINVAL; |
| 1427 | goto done; |
| 1428 | } |
| 1429 | |
| 1430 | dai_data->substream = substream; |
| 1431 | runtime->private_data = prtd; |
| 1432 | |
| 1433 | done: |
| 1434 | mutex_unlock(&prtd->lock); |
| 1435 | return ret; |
| 1436 | } |
| 1437 | |
| 1438 | static const struct snd_pcm_ops msm_pcm_ops = { |
| 1439 | .open = msm_pcm_open, |
| 1440 | .hw_params = msm_pcm_hw_params, |
| 1441 | .prepare = msm_pcm_prepare, |
| 1442 | .trigger = msm_pcm_trigger, |
| 1443 | .pointer = msm_pcm_pointer, |
Meng Wang | ac147b7 | 2017-10-30 16:46:16 +0800 | [diff] [blame^] | 1444 | .copy_user = msm_pcm_copy, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1445 | .close = msm_pcm_close, |
| 1446 | }; |
| 1447 | |
| 1448 | static int msm_asoc_pcm_new(struct snd_soc_pcm_runtime *rtd) |
| 1449 | { |
| 1450 | struct snd_card *card = rtd->card->snd_card; |
| 1451 | |
| 1452 | pr_debug("%s:\n", __func__); |
| 1453 | if (!card->dev->coherent_dma_mask) |
| 1454 | card->dev->coherent_dma_mask = DMA_BIT_MASK(32); |
| 1455 | |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
| 1459 | static int msm_pcm_hpcm_probe(struct snd_soc_platform *platform) |
| 1460 | { |
| 1461 | snd_soc_add_platform_controls(platform, msm_hpcm_controls, |
| 1462 | ARRAY_SIZE(msm_hpcm_controls)); |
| 1463 | |
| 1464 | return 0; |
| 1465 | } |
| 1466 | |
| 1467 | static struct snd_soc_platform_driver msm_soc_platform = { |
| 1468 | .ops = &msm_pcm_ops, |
| 1469 | .pcm_new = msm_asoc_pcm_new, |
| 1470 | .probe = msm_pcm_hpcm_probe, |
| 1471 | }; |
| 1472 | |
| 1473 | static int msm_pcm_probe(struct platform_device *pdev) |
| 1474 | { |
| 1475 | |
| 1476 | pr_info("%s: dev name %s\n", __func__, dev_name(&pdev->dev)); |
| 1477 | return snd_soc_register_platform(&pdev->dev, &msm_soc_platform); |
| 1478 | } |
| 1479 | |
| 1480 | static int msm_pcm_remove(struct platform_device *pdev) |
| 1481 | { |
| 1482 | snd_soc_unregister_platform(&pdev->dev); |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
| 1486 | static const struct of_device_id msm_voice_host_pcm_dt_match[] = { |
| 1487 | {.compatible = "qcom,msm-voice-host-pcm"}, |
| 1488 | {} |
| 1489 | }; |
| 1490 | MODULE_DEVICE_TABLE(of, msm_voice_host_pcm_dt_match); |
| 1491 | |
| 1492 | static struct platform_driver msm_pcm_driver = { |
| 1493 | .driver = { |
| 1494 | .name = "msm-voice-host-pcm", |
| 1495 | .owner = THIS_MODULE, |
| 1496 | .of_match_table = msm_voice_host_pcm_dt_match, |
| 1497 | }, |
| 1498 | .probe = msm_pcm_probe, |
| 1499 | .remove = msm_pcm_remove, |
| 1500 | }; |
| 1501 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 1502 | int __init msm_voice_host_init(void) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1503 | { |
| 1504 | int i = 0; |
| 1505 | struct session *s = NULL; |
| 1506 | |
| 1507 | memset(&hpcm_drv, 0, sizeof(hpcm_drv)); |
| 1508 | mutex_init(&hpcm_drv.lock); |
| 1509 | |
| 1510 | for (i = 0; i < MAX_SESSION; i++) { |
| 1511 | s = &hpcm_drv.session[i]; |
| 1512 | spin_lock_init(&s->rx_tap_point.capture_dai_data.dsp_lock); |
| 1513 | spin_lock_init(&s->rx_tap_point.playback_dai_data.dsp_lock); |
| 1514 | spin_lock_init(&s->tx_tap_point.capture_dai_data.dsp_lock); |
| 1515 | spin_lock_init(&s->tx_tap_point.playback_dai_data.dsp_lock); |
| 1516 | |
| 1517 | init_waitqueue_head( |
| 1518 | &s->rx_tap_point.capture_dai_data.queue_wait); |
| 1519 | init_waitqueue_head( |
| 1520 | &s->rx_tap_point.playback_dai_data.queue_wait); |
| 1521 | init_waitqueue_head( |
| 1522 | &s->tx_tap_point.capture_dai_data.queue_wait); |
| 1523 | init_waitqueue_head( |
| 1524 | &s->tx_tap_point.playback_dai_data.queue_wait); |
| 1525 | |
| 1526 | INIT_LIST_HEAD(&s->rx_tap_point.capture_dai_data.filled_queue); |
| 1527 | INIT_LIST_HEAD(&s->rx_tap_point.capture_dai_data.free_queue); |
| 1528 | INIT_LIST_HEAD(&s->rx_tap_point.playback_dai_data.filled_queue); |
| 1529 | INIT_LIST_HEAD(&s->rx_tap_point.playback_dai_data.free_queue); |
| 1530 | |
| 1531 | INIT_LIST_HEAD(&s->tx_tap_point.capture_dai_data.filled_queue); |
| 1532 | INIT_LIST_HEAD(&s->tx_tap_point.capture_dai_data.free_queue); |
| 1533 | INIT_LIST_HEAD(&s->tx_tap_point.playback_dai_data.filled_queue); |
| 1534 | INIT_LIST_HEAD(&s->tx_tap_point.playback_dai_data.free_queue); |
| 1535 | } |
| 1536 | |
| 1537 | return platform_driver_register(&msm_pcm_driver); |
| 1538 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1539 | |
Asish Bhattacharya | 5faacb3 | 2017-12-04 17:23:15 +0530 | [diff] [blame] | 1540 | void msm_voice_host_exit(void) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1541 | { |
| 1542 | platform_driver_unregister(&msm_pcm_driver); |
| 1543 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1544 | |
| 1545 | MODULE_DESCRIPTION("PCM module platform driver"); |
| 1546 | MODULE_LICENSE("GPL v2"); |