blob: a1fec925139dd3a9e11d23446a877dd97b9fcb1a [file] [log] [blame]
Haynes Mathew Georged00e1062018-04-06 18:18:51 -07001/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302 *
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/moduleparam.h>
17#include <linux/time.h>
18#include <linux/wait.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
21#include <linux/of_device.h>
22#include <linux/dma-mapping.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053023
24#include <sound/core.h>
25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27#include <sound/pcm.h>
28#include <sound/initval.h>
29#include <sound/control.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053030#include <sound/timer.h>
Asish Bhattacharya84f7f732017-07-25 16:29:27 +053031#include <sound/hwdep.h>
32
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053033#include <asm/dma.h>
34#include <sound/tlv.h>
35#include <sound/pcm_params.h>
Asish Bhattacharya84f7f732017-07-25 16:29:27 +053036#include <sound/devdep_params.h>
Laxminath Kasam605b42f2017-08-01 22:02:15 +053037#include <dsp/msm_audio_ion.h>
38#include <dsp/q6audio-v2.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053039
40#include "msm-pcm-q6-v2.h"
41#include "msm-pcm-routing-v2.h"
42
43#define PCM_MASTER_VOL_MAX_STEPS 0x2000
44static const DECLARE_TLV_DB_LINEAR(msm_pcm_vol_gain, 0,
45 PCM_MASTER_VOL_MAX_STEPS);
46
47struct snd_msm {
48 struct snd_card *card;
49 struct snd_pcm *pcm;
50};
51
52#define CMD_EOS_MIN_TIMEOUT_LENGTH 50
53#define CMD_EOS_TIMEOUT_MULTIPLIER (HZ * 50)
54
55#define ATRACE_END() \
56 trace_printk("tracing_mark_write: E\n")
57#define ATRACE_BEGIN(name) \
58 trace_printk("tracing_mark_write: B|%d|%s\n", current->tgid, name)
59#define ATRACE_FUNC() ATRACE_BEGIN(__func__)
60#define ATRACE_INT(name, value) \
61 trace_printk("tracing_mark_write: C|%d|%s|%d\n", \
62 current->tgid, name, (int)(value))
63
64#define SIO_PLAYBACK_MAX_PERIOD_SIZE PLAYBACK_MAX_PERIOD_SIZE
65#define SIO_PLAYBACK_MIN_PERIOD_SIZE 48
66#define SIO_PLAYBACK_MAX_NUM_PERIODS 512
67#define SIO_PLAYBACK_MIN_NUM_PERIODS PLAYBACK_MIN_NUM_PERIODS
68#define SIO_PLAYBACK_MIN_BYTES (SIO_PLAYBACK_MIN_NUM_PERIODS * \
69 SIO_PLAYBACK_MIN_PERIOD_SIZE)
70
71#define SIO_PLAYBACK_MAX_BYTES ((SIO_PLAYBACK_MAX_NUM_PERIODS) * \
72 (SIO_PLAYBACK_MAX_PERIOD_SIZE))
73
74#define SIO_CAPTURE_MAX_PERIOD_SIZE CAPTURE_MAX_PERIOD_SIZE
75#define SIO_CAPTURE_MIN_PERIOD_SIZE 48
76#define SIO_CAPTURE_MAX_NUM_PERIODS 512
77#define SIO_CAPTURE_MIN_NUM_PERIODS CAPTURE_MIN_NUM_PERIODS
78
79#define SIO_CAPTURE_MIN_BYTES (SIO_CAPTURE_MIN_NUM_PERIODS * \
80 SIO_CAPTURE_MIN_PERIOD_SIZE)
81
82#define SIO_CAPTURE_MAX_BYTES (SIO_CAPTURE_MAX_NUM_PERIODS * \
83 SIO_CAPTURE_MAX_PERIOD_SIZE)
84
85static struct snd_pcm_hardware msm_pcm_hardware_playback = {
86 .info = (SNDRV_PCM_INFO_MMAP |
87 SNDRV_PCM_INFO_BLOCK_TRANSFER |
88 SNDRV_PCM_INFO_MMAP_VALID |
89 SNDRV_PCM_INFO_INTERLEAVED |
90 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP |
91 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
92 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
93 SNDRV_PCM_FMTBIT_S24_LE |
94 SNDRV_PCM_FMTBIT_S24_3LE),
95 .rates = SNDRV_PCM_RATE_8000_192000,
96 .rate_min = 8000,
97 .rate_max = 192000,
98 .channels_min = 1,
99 .channels_max = 8,
100 .buffer_bytes_max = SIO_PLAYBACK_MAX_NUM_PERIODS *
101 SIO_PLAYBACK_MAX_PERIOD_SIZE,
102 .period_bytes_min = SIO_PLAYBACK_MIN_PERIOD_SIZE,
103 .period_bytes_max = SIO_PLAYBACK_MAX_PERIOD_SIZE,
104 .periods_min = SIO_PLAYBACK_MIN_NUM_PERIODS,
105 .periods_max = SIO_PLAYBACK_MAX_NUM_PERIODS,
106 .fifo_size = 0,
107};
108
109static struct snd_pcm_hardware msm_pcm_hardware_capture = {
110 .info = (SNDRV_PCM_INFO_MMAP |
111 SNDRV_PCM_INFO_BLOCK_TRANSFER |
112 SNDRV_PCM_INFO_MMAP_VALID |
113 SNDRV_PCM_INFO_INTERLEAVED |
114 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP |
115 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
116 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
117 SNDRV_PCM_FMTBIT_S24_LE |
118 SNDRV_PCM_FMTBIT_S24_3LE),
119 .rates = SNDRV_PCM_RATE_8000_48000,
120 .rate_min = 8000,
121 .rate_max = 48000,
122 .channels_min = 1,
123 .channels_max = 4,
124 .buffer_bytes_max = SIO_CAPTURE_MAX_NUM_PERIODS *
125 SIO_CAPTURE_MAX_PERIOD_SIZE,
126 .period_bytes_min = SIO_CAPTURE_MIN_PERIOD_SIZE,
127 .period_bytes_max = SIO_CAPTURE_MAX_PERIOD_SIZE,
128 .periods_min = SIO_CAPTURE_MIN_NUM_PERIODS,
129 .periods_max = SIO_CAPTURE_MAX_NUM_PERIODS,
130 .fifo_size = 0,
131};
132
133/* Conventional and unconventional sample rate supported */
134static unsigned int supported_sample_rates[] = {
135 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
136 88200, 96000, 176400, 192000
137};
138
139static struct snd_pcm_hw_constraint_list constraints_sample_rates = {
140 .count = ARRAY_SIZE(supported_sample_rates),
141 .list = supported_sample_rates,
142 .mask = 0,
143};
144
145static unsigned long msm_pcm_fe_topology[MSM_FRONTEND_DAI_MAX];
146
147/* default value is DTS (i.e read from device tree) */
148static char const *msm_pcm_fe_topology_text[] = {
149 "DTS", "ULL", "ULL_PP", "LL" };
150
151static const struct soc_enum msm_pcm_fe_topology_enum[] = {
152 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(msm_pcm_fe_topology_text),
153 msm_pcm_fe_topology_text),
154};
155
156static void event_handler(uint32_t opcode,
157 uint32_t token, uint32_t *payload, void *priv)
158{
159 uint32_t *ptrmem = (uint32_t *)payload;
160
161 switch (opcode) {
162 case ASM_DATA_EVENT_WATERMARK:
163 pr_debug("%s: Watermark level = 0x%08x\n", __func__, *ptrmem);
164 break;
165 case APR_BASIC_RSP_RESULT:
166 pr_debug("%s: Payload = [0x%x]stat[0x%x]\n",
167 __func__, payload[0], payload[1]);
168 switch (payload[0]) {
169 case ASM_SESSION_CMD_RUN_V2:
170 case ASM_SESSION_CMD_PAUSE:
171 case ASM_STREAM_CMD_FLUSH:
172 break;
173 default:
174 break;
175 }
176 break;
177 default:
178 pr_debug("Not Supported Event opcode[0x%x]\n", opcode);
179 break;
180 }
181}
182
183static int msm_pcm_open(struct snd_pcm_substream *substream)
184{
185 struct snd_pcm_runtime *runtime = substream->runtime;
186 struct msm_audio *prtd;
187 int ret = 0;
188
189 prtd = kzalloc(sizeof(struct msm_audio), GFP_KERNEL);
190
191 if (prtd == NULL)
192 return -ENOMEM;
193
194 prtd->substream = substream;
195 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
196 runtime->hw = msm_pcm_hardware_playback;
197 else
198 runtime->hw = msm_pcm_hardware_capture;
199
200 ret = snd_pcm_hw_constraint_list(runtime, 0,
201 SNDRV_PCM_HW_PARAM_RATE,
202 &constraints_sample_rates);
203 if (ret)
204 pr_info("snd_pcm_hw_constraint_list failed\n");
205
206 ret = snd_pcm_hw_constraint_integer(runtime,
207 SNDRV_PCM_HW_PARAM_PERIODS);
208 if (ret)
209 pr_info("snd_pcm_hw_constraint_integer failed\n");
210
211 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
212 ret = snd_pcm_hw_constraint_minmax(runtime,
213 SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
214 SIO_PLAYBACK_MIN_BYTES,
215 SIO_PLAYBACK_MAX_BYTES);
216 if (ret) {
217 pr_info("%s: P buffer bytes minmax constraint ret %d\n",
218 __func__, ret);
219 }
220 } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
221 ret = snd_pcm_hw_constraint_minmax(runtime,
222 SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
223 SIO_CAPTURE_MIN_BYTES,
224 SIO_CAPTURE_MAX_BYTES);
225 if (ret) {
226 pr_info("%s: C buffer bytes minmax constraint ret %d\n",
227 __func__, ret);
228 }
229 }
230
231 ret = snd_pcm_hw_constraint_step(runtime, 0,
232 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
233 if (ret) {
234 pr_err("%s: Constraint for period bytes step ret = %d\n",
235 __func__, ret);
236 }
237 ret = snd_pcm_hw_constraint_step(runtime, 0,
238 SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 32);
239 if (ret) {
240 pr_err("%s: Constraint for buffer bytes step ret = %d\n",
241 __func__, ret);
242 }
243 prtd->audio_client = q6asm_audio_client_alloc(
244 (app_cb)event_handler, prtd);
245 if (!prtd->audio_client) {
246 pr_err("%s: client alloc failed\n", __func__);
247 ret = -ENOMEM;
248 goto fail_cmd;
249 }
250 prtd->dsp_cnt = 0;
251 prtd->set_channel_map = false;
252 runtime->private_data = prtd;
253 return 0;
254
255fail_cmd:
256 kfree(prtd);
257 return ret;
258}
259
260static int msm_pcm_hw_params(struct snd_pcm_substream *substream,
261 struct snd_pcm_hw_params *params)
262
263{
264 struct snd_pcm_runtime *runtime = substream->runtime;
265 struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
266 struct msm_audio *prtd = runtime->private_data;
267 struct msm_plat_data *pdata;
268 struct snd_dma_buffer *dma_buf = &substream->dma_buffer;
269 struct audio_buffer *buf;
270 struct shared_io_config config;
271 uint16_t sample_word_size;
272 uint16_t bits_per_sample;
273 int ret;
274 int dir = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? IN : OUT;
275 unsigned long topology;
276 int perf_mode;
277
278 pdata = (struct msm_plat_data *)
279 dev_get_drvdata(soc_prtd->platform->dev);
280 if (!pdata) {
281 ret = -EINVAL;
282 pr_err("%s: platform data not populated ret: %d\n", __func__,
283 ret);
284 return ret;
285 }
286
287 topology = msm_pcm_fe_topology[soc_prtd->dai_link->id];
288
289 if (!strcmp(msm_pcm_fe_topology_text[topology], "ULL_PP"))
290 perf_mode = ULL_POST_PROCESSING_PCM_MODE;
291 else if (!strcmp(msm_pcm_fe_topology_text[topology], "ULL"))
292 perf_mode = ULTRA_LOW_LATENCY_PCM_MODE;
293 else if (!strcmp(msm_pcm_fe_topology_text[topology], "LL"))
294 perf_mode = LOW_LATENCY_PCM_MODE;
295 else
296 /* use the default from the device tree */
297 perf_mode = pdata->perf_mode;
298
299
300 /* need to set LOW_LATENCY_PCM_MODE for capture since
301 * push mode does not support ULL
302 */
303 prtd->audio_client->perf_mode = (dir == IN) ?
304 perf_mode :
305 LOW_LATENCY_PCM_MODE;
306
307 /* rate and channels are sent to audio driver */
308 prtd->samp_rate = params_rate(params);
309 prtd->channel_mode = params_channels(params);
310 if (prtd->enabled)
311 return 0;
312
313 switch (runtime->format) {
314 case SNDRV_PCM_FORMAT_S24_LE:
315 bits_per_sample = 24;
316 sample_word_size = 32;
317 break;
318 case SNDRV_PCM_FORMAT_S24_3LE:
319 bits_per_sample = 24;
320 sample_word_size = 24;
321 break;
322 case SNDRV_PCM_FORMAT_S16_LE:
323 default:
324 bits_per_sample = 16;
325 sample_word_size = 16;
326 break;
327 }
328
329 config.format = FORMAT_LINEAR_PCM;
330 config.bits_per_sample = bits_per_sample;
331 config.rate = params_rate(params);
332 config.channels = params_channels(params);
333 config.sample_word_size = sample_word_size;
334 config.bufsz = params_buffer_bytes(params) / params_periods(params);
335 config.bufcnt = params_periods(params);
336
337 ret = q6asm_open_shared_io(prtd->audio_client, &config, dir);
338 if (ret) {
339 pr_err("%s: q6asm_open_write_shared_io failed ret: %d\n",
340 __func__, ret);
341 return ret;
342 }
343
344 prtd->pcm_size = params_buffer_bytes(params);
345 prtd->pcm_count = params_buffer_bytes(params);
346 prtd->pcm_irq_pos = 0;
347
348 buf = prtd->audio_client->port[dir].buf;
349 dma_buf->dev.type = SNDRV_DMA_TYPE_DEV;
350 dma_buf->dev.dev = substream->pcm->card->dev;
351 dma_buf->private_data = NULL;
352 dma_buf->area = buf->data;
353 dma_buf->addr = buf->phys;
354 dma_buf->bytes = prtd->pcm_size;
355
356 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
357
358 pr_debug("%s: session ID %d, perf %d\n", __func__,
359 prtd->audio_client->session,
360 prtd->audio_client->perf_mode);
361 prtd->session_id = prtd->audio_client->session;
362
363 pr_debug("msm_pcm_routing_reg_phy_stream w/ id %d\n",
364 soc_prtd->dai_link->id);
365 ret = msm_pcm_routing_reg_phy_stream(soc_prtd->dai_link->id,
366 prtd->audio_client->perf_mode,
367 prtd->session_id, substream->stream);
368
369 if (ret) {
370 pr_err("%s: stream reg failed ret:%d\n", __func__, ret);
371 return ret;
372 }
373
374 atomic_set(&prtd->out_count, runtime->periods);
375 prtd->enabled = 1;
376 prtd->cmd_pending = 0;
377 prtd->cmd_interrupt = 0;
378
379 return 0;
380}
381
382static int msm_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
383{
384 int ret = 0;
385 struct snd_pcm_runtime *runtime = substream->runtime;
386 struct msm_audio *prtd = runtime->private_data;
387 int dir = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 0 : 1;
388 struct audio_buffer *buf;
389
390 switch (cmd) {
391 case SNDRV_PCM_TRIGGER_START:
392 case SNDRV_PCM_TRIGGER_RESUME:
393 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
394 pr_debug("%s: %s Trigger start\n", __func__,
395 dir == 0 ? "P" : "C");
396 ret = q6asm_run(prtd->audio_client, 0, 0, 0);
397 if (ret)
398 break;
399 atomic_set(&prtd->start, 1);
400 break;
401 case SNDRV_PCM_TRIGGER_STOP:
402 pr_debug("%s: SNDRV_PCM_TRIGGER_STOP\n", __func__);
403 atomic_set(&prtd->start, 0);
404 q6asm_cmd(prtd->audio_client, CMD_PAUSE);
405 q6asm_cmd(prtd->audio_client, CMD_FLUSH);
406 buf = q6asm_shared_io_buf(prtd->audio_client, dir);
407 if (buf == NULL) {
408 pr_err("%s: shared IO buffer is null\n", __func__);
409 ret = -EINVAL;
410 break;
411 }
412 memset(buf->data, 0, buf->actual_size);
413 break;
414 case SNDRV_PCM_TRIGGER_SUSPEND:
415 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
416 pr_debug("%s: SNDRV_PCM_TRIGGER_PAUSE\n", __func__);
417 ret = q6asm_cmd_nowait(prtd->audio_client, CMD_PAUSE);
418 atomic_set(&prtd->start, 0);
419 break;
420 default:
421 ret = -EINVAL;
422 break;
423 }
424 return ret;
425}
426
Asish Bhattacharya84f7f732017-07-25 16:29:27 +0530427
428static int msm_pcm_mmap_fd(struct snd_pcm_substream *substream,
429 struct snd_pcm_mmap_fd *mmap_fd)
430{
431 struct msm_audio *prtd;
432 struct audio_port_data *apd;
433 struct audio_buffer *ab;
434 int dir = -1;
435
436 if (!substream->runtime) {
437 pr_err("%s substream runtime not found\n", __func__);
438 return -EFAULT;
439 }
440
441 prtd = substream->runtime->private_data;
442 if (!prtd || !prtd->audio_client || !prtd->mmap_flag) {
443 pr_err("%s no audio client or not an mmap session\n", __func__);
444 return -EINVAL;
445 }
446
447 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
448 dir = IN;
449 else
450 dir = OUT;
451
452 apd = prtd->audio_client->port;
453 ab = &(apd[dir].buf[0]);
454 mmap_fd->fd = ion_share_dma_buf_fd(ab->client, ab->handle);
455 if (mmap_fd->fd >= 0) {
456 mmap_fd->dir = dir;
457 mmap_fd->actual_size = ab->actual_size;
458 mmap_fd->size = ab->size;
459 }
460 return mmap_fd->fd < 0 ? -EFAULT : 0;
461}
462
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530463static int msm_pcm_ioctl(struct snd_pcm_substream *substream,
464 unsigned int cmd, void *arg)
465{
466 struct snd_pcm_runtime *runtime = substream->runtime;
467 struct msm_audio *prtd = runtime->private_data;
468 int dir = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 0 : 1;
469 struct audio_buffer *buf;
470
471 switch (cmd) {
472 case SNDRV_PCM_IOCTL1_RESET:
473 pr_debug("%s: %s SNDRV_PCM_IOCTL1_RESET\n", __func__,
474 dir == 0 ? "P" : "C");
475 buf = q6asm_shared_io_buf(prtd->audio_client, dir);
476
477 if (buf && buf->data)
478 memset(buf->data, 0, buf->actual_size);
479 break;
480 default:
481 break;
482 }
483
484 return snd_pcm_lib_ioctl(substream, cmd, arg);
485}
486
Asish Bhattacharya84f7f732017-07-25 16:29:27 +0530487#ifdef CONFIG_COMPAT
488static int msm_pcm_compat_ioctl(struct snd_pcm_substream *substream,
489 unsigned int cmd, void *arg)
490{
491 /* we only handle RESET which is common for both modes */
492 return msm_pcm_ioctl(substream, cmd, arg);
493}
494#endif
495
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530496static snd_pcm_uframes_t msm_pcm_pointer(struct snd_pcm_substream *substream)
497{
498 struct snd_pcm_runtime *runtime = substream->runtime;
499 uint32_t read_index, wall_clk_msw, wall_clk_lsw;
500 /*these are offsets, unlike ASoC's full values*/
501 snd_pcm_sframes_t hw_ptr;
502 snd_pcm_sframes_t period_size;
503 int ret;
504 int retries = 10;
505 struct msm_audio *prtd = runtime->private_data;
506
507 period_size = runtime->period_size;
508
509 do {
510 ret = q6asm_get_shared_pos(prtd->audio_client,
511 &read_index, &wall_clk_msw,
512 &wall_clk_lsw);
513 } while (ret == -EAGAIN && --retries);
514
515 if (ret || !period_size) {
516 pr_err("get_shared_pos error or zero period size\n");
517 return 0;
518 }
519
520 hw_ptr = bytes_to_frames(substream->runtime,
521 read_index);
522
523 if (runtime->control->appl_ptr == 0) {
524 pr_debug("ptr(%s): appl(0), hw = %lu read_index = %u\n",
525 prtd->substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
526 "P" : "C",
527 hw_ptr, read_index);
528 }
529 return (hw_ptr/period_size) * period_size;
530}
531
532static int msm_pcm_copy(struct snd_pcm_substream *substream, int a,
533 snd_pcm_uframes_t hwoff, void __user *buf, snd_pcm_uframes_t frames)
534{
535 return -EINVAL;
536}
537
538static int msm_pcm_mmap(struct snd_pcm_substream *substream,
539 struct vm_area_struct *vma)
540{
541 struct snd_pcm_runtime *runtime = substream->runtime;
542 struct msm_audio *prtd = runtime->private_data;
543 struct audio_client *ac = prtd->audio_client;
544 struct audio_port_data *apd = ac->port;
545 struct audio_buffer *ab;
546 int dir = -1;
547 int ret;
548
549 pr_debug("%s: mmap begin\n", __func__);
550 prtd->mmap_flag = 1;
551
552 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
553 dir = IN;
554 else
555 dir = OUT;
556
557 ab = &(apd[dir].buf[0]);
558
559 ret = msm_audio_ion_mmap(ab, vma);
560
561 if (ret)
562 prtd->mmap_flag = 0;
563
564 return ret;
565}
566
567static int msm_pcm_prepare(struct snd_pcm_substream *substream)
568{
569 struct snd_pcm_runtime *runtime = substream->runtime;
570 struct msm_audio *prtd = runtime->private_data;
571
572 if (!prtd || !prtd->mmap_flag)
573 return -EIO;
574
575 return 0;
576}
577
578static int msm_pcm_close(struct snd_pcm_substream *substream)
579{
580 struct snd_pcm_runtime *runtime = substream->runtime;
581 struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
582 struct msm_audio *prtd = runtime->private_data;
583 struct audio_client *ac = prtd->audio_client;
584 uint32_t timeout;
585 int dir = 0;
586 int ret = 0;
587
588 if (ac) {
589 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
590 dir = IN;
591 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
592 dir = OUT;
593
594 /* determine timeout length */
595 if (runtime->frame_bits == 0 || runtime->rate == 0) {
596 timeout = CMD_EOS_MIN_TIMEOUT_LENGTH;
597 } else {
598 timeout = (runtime->period_size *
599 CMD_EOS_TIMEOUT_MULTIPLIER) /
600 ((runtime->frame_bits / 8) *
601 runtime->rate);
602 if (timeout < CMD_EOS_MIN_TIMEOUT_LENGTH)
603 timeout = CMD_EOS_MIN_TIMEOUT_LENGTH;
604 }
605
606 q6asm_cmd(ac, CMD_CLOSE);
607
608 ret = q6asm_shared_io_free(ac, dir);
609
610 if (ret) {
611 pr_err("%s: Failed to close pull mode, ret %d\n",
612 __func__, ret);
613 }
614 q6asm_audio_client_free(ac);
615 }
616 msm_pcm_routing_dereg_phy_stream(soc_prtd->dai_link->id,
617 dir == IN ?
618 SNDRV_PCM_STREAM_PLAYBACK :
619 SNDRV_PCM_STREAM_CAPTURE);
620 kfree(prtd);
621 runtime->private_data = NULL;
622
623 return 0;
624}
625
626static int msm_pcm_set_volume(struct msm_audio *prtd, uint32_t volume)
627{
628 int rc = 0;
629
630 if (prtd && prtd->audio_client) {
631 pr_debug("%s: channels %d volume 0x%x\n", __func__,
632 prtd->channel_mode, volume);
633 rc = q6asm_set_volume(prtd->audio_client, volume);
634 if (rc < 0) {
635 pr_err("%s: Send Volume command failed rc=%d\n",
636 __func__, rc);
637 }
638 }
639 return rc;
640}
641
642static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol,
643 struct snd_ctl_elem_value *ucontrol)
644{
645 struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol);
646 struct snd_pcm_substream *substream =
Haynes Mathew Georged00e1062018-04-06 18:18:51 -0700647 vol->pcm->streams[vol->stream].substream;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530648 struct msm_audio *prtd;
649
650 pr_debug("%s\n", __func__);
651 if (!substream) {
652 pr_err("%s substream not found\n", __func__);
653 return -ENODEV;
654 }
655 if (!substream->runtime) {
656 pr_err("%s substream runtime not found\n", __func__);
657 return 0;
658 }
659 prtd = substream->runtime->private_data;
660 if (prtd)
661 ucontrol->value.integer.value[0] = prtd->volume;
662 return 0;
663}
664
665static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol,
666 struct snd_ctl_elem_value *ucontrol)
667{
668 int rc = 0;
669 struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol);
670 struct snd_pcm_substream *substream =
Haynes Mathew Georged00e1062018-04-06 18:18:51 -0700671 vol->pcm->streams[vol->stream].substream;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530672 struct msm_audio *prtd;
673 int volume = ucontrol->value.integer.value[0];
674
675 pr_debug("%s: volume : 0x%x\n", __func__, volume);
676 if (!substream) {
677 pr_err("%s substream not found\n", __func__);
678 return -ENODEV;
679 }
680 if (!substream->runtime) {
681 pr_err("%s substream runtime not found\n", __func__);
682 return 0;
683 }
684 prtd = substream->runtime->private_data;
685 if (prtd) {
686 rc = msm_pcm_set_volume(prtd, volume);
687 prtd->volume = volume;
688 }
689 return rc;
690}
691
Haynes Mathew Georged00e1062018-04-06 18:18:51 -0700692static int msm_pcm_add_volume_control(struct snd_soc_pcm_runtime *rtd,
693 int stream)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530694{
695 int ret = 0;
696 struct snd_pcm *pcm = rtd->pcm;
697 struct snd_pcm_volume *volume_info;
698 struct snd_kcontrol *kctl;
699
Haynes Mathew Georged00e1062018-04-06 18:18:51 -0700700 dev_dbg(rtd->dev, "%s, volume control add\n", __func__);
701 ret = snd_pcm_add_volume_ctls(pcm, stream,
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530702 NULL, 1, rtd->dai_link->id,
703 &volume_info);
704 if (ret < 0) {
705 pr_err("%s volume control failed ret %d\n", __func__, ret);
706 return ret;
707 }
708 kctl = volume_info->kctl;
709 kctl->put = msm_pcm_volume_ctl_put;
710 kctl->get = msm_pcm_volume_ctl_get;
711 kctl->tlv.p = msm_pcm_vol_gain;
712 return 0;
713}
714
715static int msm_pcm_chmap_ctl_put(struct snd_kcontrol *kcontrol,
716 struct snd_ctl_elem_value *ucontrol)
717{
718 int i;
719 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
720 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
721 struct snd_pcm_substream *substream;
722 struct msm_audio *prtd;
723
724 pr_debug("%s", __func__);
725 substream = snd_pcm_chmap_substream(info, idx);
726 if (!substream)
727 return -ENODEV;
728 if (!substream->runtime)
729 return 0;
730
731 prtd = substream->runtime->private_data;
732 if (prtd) {
733 prtd->set_channel_map = true;
734 for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL; i++)
735 prtd->channel_map[i] =
736 (char)(ucontrol->value.integer.value[i]);
737 }
738 return 0;
739}
740
741static int msm_pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol,
742 struct snd_ctl_elem_value *ucontrol)
743{
744 int i;
745 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
746 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
747 struct snd_pcm_substream *substream;
748 struct msm_audio *prtd;
749
750 pr_debug("%s", __func__);
751 substream = snd_pcm_chmap_substream(info, idx);
752 if (!substream)
753 return -ENODEV;
754 memset(ucontrol->value.integer.value, 0,
755 sizeof(ucontrol->value.integer.value));
756 if (!substream->runtime)
757 return 0; /* no channels set */
758
759 prtd = substream->runtime->private_data;
760
761 if (prtd && prtd->set_channel_map == true) {
762 for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL; i++)
763 ucontrol->value.integer.value[i] =
764 (int)prtd->channel_map[i];
765 } else {
766 for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL; i++)
767 ucontrol->value.integer.value[i] = 0;
768 }
769
770 return 0;
771}
772
773static int msm_pcm_add_chmap_control(struct snd_soc_pcm_runtime *rtd)
774{
775 struct snd_pcm *pcm = rtd->pcm;
776 struct snd_pcm_chmap *chmap_info;
777 struct snd_kcontrol *kctl;
778 char device_num[12];
779 int i, ret;
780
781 pr_debug("%s, Channel map cntrl add\n", __func__);
782 ret = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
783 snd_pcm_std_chmaps,
784 PCM_FORMAT_MAX_NUM_CHANNEL, 0,
785 &chmap_info);
786 if (ret)
787 return ret;
788
789 kctl = chmap_info->kctl;
790 for (i = 0; i < kctl->count; i++)
791 kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
792 snprintf(device_num, sizeof(device_num), "%d", pcm->device);
793 strlcat(kctl->id.name, device_num, sizeof(kctl->id.name));
794 pr_debug("%s, Overwriting channel map control name to: %s",
795 __func__, kctl->id.name);
796 kctl->put = msm_pcm_chmap_ctl_put;
797 kctl->get = msm_pcm_chmap_ctl_get;
798 return 0;
799}
800
801static int msm_pcm_fe_topology_info(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_info *uinfo)
803{
804 const struct soc_enum *e = &msm_pcm_fe_topology_enum[0];
805
806 return snd_ctl_enum_info(uinfo, 1, e->items, e->texts);
807}
808
809static int msm_pcm_fe_topology_get(struct snd_kcontrol *kcontrol,
810 struct snd_ctl_elem_value *ucontrol)
811{
812 unsigned long fe_id = kcontrol->private_value;
813
814 if (fe_id >= MSM_FRONTEND_DAI_MAX) {
815 pr_err("%s Received out of bound fe_id %lu\n", __func__, fe_id);
816 return -EINVAL;
817 }
818
819 pr_debug("%s: %lu topology %s\n", __func__, fe_id,
820 msm_pcm_fe_topology_text[msm_pcm_fe_topology[fe_id]]);
821 ucontrol->value.enumerated.item[0] = msm_pcm_fe_topology[fe_id];
822 return 0;
823}
824
825static int msm_pcm_fe_topology_put(struct snd_kcontrol *kcontrol,
826 struct snd_ctl_elem_value *ucontrol)
827{
828 unsigned long fe_id = kcontrol->private_value;
829 unsigned int item;
830
831 if (fe_id >= MSM_FRONTEND_DAI_MAX) {
832 pr_err("%s Received out of bound fe_id %lu\n", __func__, fe_id);
833 return -EINVAL;
834 }
835
836 item = ucontrol->value.enumerated.item[0];
837 if (item >= ARRAY_SIZE(msm_pcm_fe_topology_text)) {
838 pr_err("%s Received out of bound topology %lu\n", __func__,
839 fe_id);
840 return -EINVAL;
841 }
842
843 pr_debug("%s: %lu new topology %s\n", __func__, fe_id,
844 msm_pcm_fe_topology_text[item]);
845 msm_pcm_fe_topology[fe_id] = item;
846 return 0;
847}
848
849static int msm_pcm_add_fe_topology_control(struct snd_soc_pcm_runtime *rtd)
850{
851 const char *mixer_ctl_name = "PCM_Dev";
852 const char *deviceNo = "NN";
853 const char *topo_text = "Topology";
854 char *mixer_str = NULL;
855 int ctl_len;
856 int ret;
857 struct snd_kcontrol_new topology_control[1] = {
858 {
859 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
860 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
861 .name = "?",
862 .info = msm_pcm_fe_topology_info,
863 .get = msm_pcm_fe_topology_get,
864 .put = msm_pcm_fe_topology_put,
865 .private_value = 0,
866 },
867 };
868
869 ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1 +
870 strlen(topo_text) + 1;
871 mixer_str = kzalloc(ctl_len, GFP_KERNEL);
872
873 if (!mixer_str)
874 return -ENOMEM;
875
876 snprintf(mixer_str, ctl_len, "%s %d %s", mixer_ctl_name,
877 rtd->pcm->device, topo_text);
878
879 topology_control[0].name = mixer_str;
880 topology_control[0].private_value = rtd->dai_link->id;
881 ret = snd_soc_add_platform_controls(rtd->platform, topology_control,
882 ARRAY_SIZE(topology_control));
883 msm_pcm_fe_topology[rtd->dai_link->id] = 0;
884 kfree(mixer_str);
885 return ret;
886}
887
888static int msm_pcm_playback_app_type_cfg_ctl_put(struct snd_kcontrol *kcontrol,
889 struct snd_ctl_elem_value *ucontrol)
890{
891 u64 fe_id = kcontrol->private_value;
892 int session_type = SESSION_TYPE_RX;
893 int be_id = ucontrol->value.integer.value[3];
894 struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
895 int ret = 0;
896
897 cfg_data.app_type = ucontrol->value.integer.value[0];
898 cfg_data.acdb_dev_id = ucontrol->value.integer.value[1];
899 if (ucontrol->value.integer.value[2] != 0)
900 cfg_data.sample_rate = ucontrol->value.integer.value[2];
901 pr_debug("%s: fe_id- %llu session_type- %d be_id- %d app_type- %d acdb_dev_id- %d sample_rate- %d\n",
902 __func__, fe_id, session_type, be_id,
903 cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
904 ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
905 be_id, &cfg_data);
906 if (ret < 0)
907 pr_err("%s: msm_pcm_routing_reg_stream_app_type_cfg failed returned %d\n",
908 __func__, ret);
909 return ret;
910}
911
912static int msm_pcm_playback_app_type_cfg_ctl_get(struct snd_kcontrol *kcontrol,
913 struct snd_ctl_elem_value *ucontrol)
914{
915 u64 fe_id = kcontrol->private_value;
916 int session_type = SESSION_TYPE_RX;
917 int be_id = 0;
918 struct msm_pcm_stream_app_type_cfg cfg_data = {0};
919 int ret = 0;
920
921 ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
922 &be_id, &cfg_data);
923 if (ret < 0) {
924 pr_err("%s: msm_pcm_routing_get_stream_app_type_cfg failed returned %d\n",
925 __func__, ret);
926 goto done;
927 }
928
929 ucontrol->value.integer.value[0] = cfg_data.app_type;
930 ucontrol->value.integer.value[1] = cfg_data.acdb_dev_id;
931 ucontrol->value.integer.value[2] = cfg_data.sample_rate;
932 ucontrol->value.integer.value[3] = be_id;
933 pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
934 __func__, fe_id, session_type, be_id,
935 cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
936done:
937 return ret;
938}
939
940static int msm_pcm_capture_app_type_cfg_ctl_put(struct snd_kcontrol *kcontrol,
941 struct snd_ctl_elem_value *ucontrol)
942{
943 u64 fe_id = kcontrol->private_value;
944 int session_type = SESSION_TYPE_TX;
945 int be_id = ucontrol->value.integer.value[3];
946 struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
947 int ret = 0;
948
949 cfg_data.app_type = ucontrol->value.integer.value[0];
950 cfg_data.acdb_dev_id = ucontrol->value.integer.value[1];
951 if (ucontrol->value.integer.value[2] != 0)
952 cfg_data.sample_rate = ucontrol->value.integer.value[2];
953 pr_debug("%s: fe_id- %llu session_type- %d be_id- %d app_type- %d acdb_dev_id- %d sample_rate- %d\n",
954 __func__, fe_id, session_type, be_id,
955 cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
956 ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
957 be_id, &cfg_data);
958 if (ret < 0)
959 pr_err("%s: msm_pcm_routing_reg_stream_app_type_cfg failed returned %d\n",
960 __func__, ret);
961
962 return ret;
963}
964
965static int msm_pcm_capture_app_type_cfg_ctl_get(struct snd_kcontrol *kcontrol,
966 struct snd_ctl_elem_value *ucontrol)
967{
968 u64 fe_id = kcontrol->private_value;
969 int session_type = SESSION_TYPE_TX;
970 int be_id = 0;
971 struct msm_pcm_stream_app_type_cfg cfg_data = {0};
972 int ret = 0;
973
974 ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
975 &be_id, &cfg_data);
976 if (ret < 0) {
977 pr_err("%s: msm_pcm_routing_get_stream_app_type_cfg failed returned %d\n",
978 __func__, ret);
979 goto done;
980 }
981
982 ucontrol->value.integer.value[0] = cfg_data.app_type;
983 ucontrol->value.integer.value[1] = cfg_data.acdb_dev_id;
984 ucontrol->value.integer.value[2] = cfg_data.sample_rate;
985 ucontrol->value.integer.value[3] = be_id;
986 pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
987 __func__, fe_id, session_type, be_id,
988 cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
989done:
990 return ret;
991}
992
993static int msm_pcm_add_app_type_controls(struct snd_soc_pcm_runtime *rtd)
994{
995 struct snd_pcm *pcm = rtd->pcm;
996 struct snd_pcm_usr *app_type_info;
997 struct snd_kcontrol *kctl;
998 const char *playback_mixer_ctl_name = "Audio Stream";
999 const char *capture_mixer_ctl_name = "Audio Stream Capture";
1000 const char *deviceNo = "NN";
1001 const char *suffix = "App Type Cfg";
1002 int ctl_len, ret = 0;
1003
1004 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
1005 ctl_len = strlen(playback_mixer_ctl_name) + 1 +
1006 strlen(deviceNo) + 1 +
1007 strlen(suffix) + 1;
1008 pr_debug("%s: Playback app type cntrl add\n", __func__);
1009 ret = snd_pcm_add_usr_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1010 NULL, 1, ctl_len, rtd->dai_link->id,
1011 &app_type_info);
1012 if (ret < 0) {
1013 pr_err("%s: playback app type cntrl add failed, err: %d\n",
1014 __func__, ret);
1015 return ret;
1016 }
1017 kctl = app_type_info->kctl;
1018 snprintf(kctl->id.name, ctl_len, "%s %d %s",
1019 playback_mixer_ctl_name, rtd->pcm->device, suffix);
1020 kctl->put = msm_pcm_playback_app_type_cfg_ctl_put;
1021 kctl->get = msm_pcm_playback_app_type_cfg_ctl_get;
1022 }
1023
1024 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
1025 ctl_len = strlen(capture_mixer_ctl_name) + 1 +
1026 strlen(deviceNo) + 1 + strlen(suffix) + 1;
1027 pr_debug("%s: Capture app type cntrl add\n", __func__);
1028 ret = snd_pcm_add_usr_ctls(pcm, SNDRV_PCM_STREAM_CAPTURE,
1029 NULL, 1, ctl_len, rtd->dai_link->id,
1030 &app_type_info);
1031 if (ret < 0) {
1032 pr_err("%s: capture app type cntrl add failed, err: %d\n",
1033 __func__, ret);
1034 return ret;
1035 }
1036 kctl = app_type_info->kctl;
1037 snprintf(kctl->id.name, ctl_len, "%s %d %s",
1038 capture_mixer_ctl_name, rtd->pcm->device, suffix);
1039 kctl->put = msm_pcm_capture_app_type_cfg_ctl_put;
1040 kctl->get = msm_pcm_capture_app_type_cfg_ctl_get;
1041 }
1042
1043 return 0;
1044}
1045
Asish Bhattacharya84f7f732017-07-25 16:29:27 +05301046static int msm_pcm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
1047 unsigned int cmd, unsigned long arg)
1048{
1049 int ret = 0;
1050 struct snd_pcm *pcm = hw->private_data;
1051 struct snd_pcm_mmap_fd __user *_mmap_fd = NULL;
1052 struct snd_pcm_mmap_fd mmap_fd;
1053 struct snd_pcm_substream *substream = NULL;
1054 int32_t dir = -1;
1055
1056 switch (cmd) {
1057 case SNDRV_PCM_IOCTL_MMAP_DATA_FD:
1058 _mmap_fd = (struct snd_pcm_mmap_fd __user *)arg;
1059 if (get_user(dir, (int32_t __user *)&(_mmap_fd->dir))) {
1060 pr_err("%s: error copying mmap_fd from user\n",
1061 __func__);
1062 ret = -EFAULT;
1063 break;
1064 }
1065 if (dir != OUT && dir != IN) {
1066 pr_err("%s invalid stream dir\n", __func__);
1067 ret = -EINVAL;
1068 break;
1069 }
1070 substream = pcm->streams[dir].substream;
1071 if (!substream) {
1072 pr_err("%s substream not found\n", __func__);
1073 ret = -ENODEV;
1074 break;
1075 }
1076 pr_debug("%s : %s MMAP Data fd\n", __func__,
1077 dir == 0 ? "P" : "C");
1078 if (msm_pcm_mmap_fd(substream, &mmap_fd) < 0) {
1079 pr_err("%s: error getting fd\n",
1080 __func__);
1081 ret = -EFAULT;
1082 break;
1083 }
1084 if (put_user(mmap_fd.fd, &_mmap_fd->fd) ||
1085 put_user(mmap_fd.size, &_mmap_fd->size) ||
1086 put_user(mmap_fd.actual_size, &_mmap_fd->actual_size)) {
1087 pr_err("%s: error copying fd\n", __func__);
1088 return -EFAULT;
1089 }
1090 break;
1091 default:
1092 ret = -EINVAL;
1093 break;
1094 }
1095 return ret;
1096}
1097
1098#ifdef CONFIG_COMPAT
1099static int msm_pcm_hwdep_compat_ioctl(struct snd_hwdep *hw,
1100 struct file *file,
1101 unsigned int cmd,
1102 unsigned long arg)
1103{
1104 /* we only support mmap fd. Handling is common in both modes */
1105 return msm_pcm_hwdep_ioctl(hw, file, cmd, arg);
1106}
1107#else
1108static int msm_pcm_hwdep_compat_ioctl(struct snd_hwdep *hw,
1109 struct file *file,
1110 unsigned int cmd,
1111 unsigned long arg)
1112{
1113 return -EINVAL;
1114}
1115#endif
1116
1117static int msm_pcm_add_hwdep_dev(struct snd_soc_pcm_runtime *runtime)
1118{
1119 struct snd_hwdep *hwdep;
1120 int rc;
1121 char id[] = "NOIRQ_NN";
1122
1123 snprintf(id, sizeof(id), "NOIRQ_%d", runtime->pcm->device);
1124 pr_debug("%s: pcm dev %d\n", __func__, runtime->pcm->device);
1125 rc = snd_hwdep_new(runtime->card->snd_card,
1126 &id[0],
1127 HWDEP_FE_BASE + runtime->pcm->device,
1128 &hwdep);
1129 if (!hwdep || rc < 0) {
1130 pr_err("%s: hwdep intf failed to create %s - hwdep\n", __func__,
1131 id);
1132 return rc;
1133 }
1134
1135 hwdep->iface = SNDRV_HWDEP_IFACE_AUDIO_BE; /* for lack of a FE iface */
1136 hwdep->private_data = runtime->pcm; /* of type struct snd_pcm */
1137 hwdep->ops.ioctl = msm_pcm_hwdep_ioctl;
1138 hwdep->ops.ioctl_compat = msm_pcm_hwdep_compat_ioctl;
1139 return 0;
1140}
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301141
1142static int msm_asoc_pcm_new(struct snd_soc_pcm_runtime *rtd)
1143{
1144 struct snd_card *card = rtd->card->snd_card;
1145 struct snd_pcm *pcm = rtd->pcm;
1146 int ret;
1147
1148 pr_debug("%s , register new control\n", __func__);
1149 if (!card->dev->coherent_dma_mask)
1150 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
1151
1152 ret = msm_pcm_add_chmap_control(rtd);
1153 if (ret) {
1154 pr_err("%s failed to add chmap cntls\n", __func__);
1155 goto exit;
1156 }
Haynes Mathew Georged00e1062018-04-06 18:18:51 -07001157 ret = msm_pcm_add_volume_control(rtd, SNDRV_PCM_STREAM_PLAYBACK);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301158 if (ret) {
Haynes Mathew Georged00e1062018-04-06 18:18:51 -07001159 pr_err("%s: Could not add pcm playback volume Control %d\n",
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301160 __func__, ret);
1161 }
Haynes Mathew Georged00e1062018-04-06 18:18:51 -07001162 ret = msm_pcm_add_volume_control(rtd, SNDRV_PCM_STREAM_CAPTURE);
1163 if (ret) {
1164 pr_err("%s: Could not add pcm capture volume Control %d\n",
1165 __func__, ret);
1166 }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301167 ret = msm_pcm_add_fe_topology_control(rtd);
1168 if (ret) {
1169 pr_err("%s: Could not add pcm topology control %d\n",
1170 __func__, ret);
1171 }
1172
1173 ret = msm_pcm_add_app_type_controls(rtd);
1174 if (ret) {
1175 pr_err("%s: Could not add app type controls failed %d\n",
1176 __func__, ret);
1177 }
Asish Bhattacharya84f7f732017-07-25 16:29:27 +05301178 ret = msm_pcm_add_hwdep_dev(rtd);
1179 if (ret)
1180 pr_err("%s: Could not add hw dep node\n", __func__);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301181 pcm->nonatomic = true;
1182exit:
1183 return ret;
1184}
1185
1186
1187static const struct snd_pcm_ops msm_pcm_ops = {
1188 .open = msm_pcm_open,
1189 .prepare = msm_pcm_prepare,
1190 .copy = msm_pcm_copy,
1191 .hw_params = msm_pcm_hw_params,
1192 .ioctl = msm_pcm_ioctl,
Asish Bhattacharya84f7f732017-07-25 16:29:27 +05301193#ifdef CONFIG_COMPAT
1194 .compat_ioctl = msm_pcm_compat_ioctl,
1195#endif
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301196 .trigger = msm_pcm_trigger,
1197 .pointer = msm_pcm_pointer,
1198 .mmap = msm_pcm_mmap,
1199 .close = msm_pcm_close,
1200};
1201
1202static struct snd_soc_platform_driver msm_soc_platform = {
1203 .ops = &msm_pcm_ops,
1204 .pcm_new = msm_asoc_pcm_new,
1205};
1206
1207static int msm_pcm_probe(struct platform_device *pdev)
1208{
1209 int rc;
1210 struct msm_plat_data *pdata;
1211 const char *latency_level;
1212 int perf_mode = LOW_LATENCY_PCM_MODE;
1213
1214 dev_dbg(&pdev->dev, "Pull mode driver probe\n");
1215
1216 if (of_property_read_bool(pdev->dev.of_node,
1217 "qcom,msm-pcm-low-latency")) {
1218
1219 rc = of_property_read_string(pdev->dev.of_node,
1220 "qcom,latency-level", &latency_level);
1221 if (!rc) {
1222 if (!strcmp(latency_level, "ultra"))
1223 perf_mode = ULTRA_LOW_LATENCY_PCM_MODE;
1224 else if (!strcmp(latency_level, "ull-pp"))
1225 perf_mode = ULL_POST_PROCESSING_PCM_MODE;
1226 }
1227 }
1228
1229 pdata = devm_kzalloc(&pdev->dev,
1230 sizeof(struct msm_plat_data), GFP_KERNEL);
1231 if (!pdata)
1232 return -ENOMEM;
1233
1234 pdata->perf_mode = perf_mode;
1235
1236 dev_set_drvdata(&pdev->dev, pdata);
1237
1238 dev_dbg(&pdev->dev, "%s: dev name %s\n",
1239 __func__, dev_name(&pdev->dev));
1240 dev_dbg(&pdev->dev, "Pull mode driver register\n");
1241 rc = snd_soc_register_platform(&pdev->dev,
1242 &msm_soc_platform);
1243
1244 if (rc)
1245 dev_err(&pdev->dev, "Failed to register pull mode driver\n");
1246
1247 return rc;
1248}
1249
1250static int msm_pcm_remove(struct platform_device *pdev)
1251{
1252 struct msm_plat_data *pdata;
1253
1254 dev_dbg(&pdev->dev, "Pull mode remove\n");
1255 pdata = dev_get_drvdata(&pdev->dev);
1256 devm_kfree(&pdev->dev, pdata);
1257 snd_soc_unregister_platform(&pdev->dev);
1258 return 0;
1259}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301260static const struct of_device_id msm_pcm_noirq_dt_match[] = {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301261 {.compatible = "qcom,msm-pcm-dsp-noirq"},
1262 {}
1263};
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301264MODULE_DEVICE_TABLE(of, msm_pcm_noirq_dt_match);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301265
1266static struct platform_driver msm_pcm_driver_noirq = {
1267 .driver = {
1268 .name = "msm-pcm-dsp-noirq",
1269 .owner = THIS_MODULE,
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301270 .of_match_table = msm_pcm_noirq_dt_match,
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301271 },
1272 .probe = msm_pcm_probe,
1273 .remove = msm_pcm_remove,
1274};
1275
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301276int __init msm_pcm_noirq_init(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301277{
1278 return platform_driver_register(&msm_pcm_driver_noirq);
1279}
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301280
Asish Bhattacharya5faacb32017-12-04 17:23:15 +05301281void msm_pcm_noirq_exit(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301282{
1283 platform_driver_unregister(&msm_pcm_driver_noirq);
1284}
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301285
1286MODULE_DESCRIPTION("PCM NOIRQ module platform driver");
1287MODULE_LICENSE("GPL v2");