blob: dbc6d33a65beaae9f9b0165619f989be41435667 [file] [log] [blame]
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/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 =
647 vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
648 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 =
671 vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
672 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
692static int msm_pcm_add_volume_control(struct snd_soc_pcm_runtime *rtd)
693{
694 int ret = 0;
695 struct snd_pcm *pcm = rtd->pcm;
696 struct snd_pcm_volume *volume_info;
697 struct snd_kcontrol *kctl;
698
699 dev_dbg(rtd->dev, "%s, Volume control add\n", __func__);
700 ret = snd_pcm_add_volume_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
701 NULL, 1, rtd->dai_link->id,
702 &volume_info);
703 if (ret < 0) {
704 pr_err("%s volume control failed ret %d\n", __func__, ret);
705 return ret;
706 }
707 kctl = volume_info->kctl;
708 kctl->put = msm_pcm_volume_ctl_put;
709 kctl->get = msm_pcm_volume_ctl_get;
710 kctl->tlv.p = msm_pcm_vol_gain;
711 return 0;
712}
713
714static int msm_pcm_chmap_ctl_put(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_value *ucontrol)
716{
717 int i;
718 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
719 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
720 struct snd_pcm_substream *substream;
721 struct msm_audio *prtd;
722
723 pr_debug("%s", __func__);
724 substream = snd_pcm_chmap_substream(info, idx);
725 if (!substream)
726 return -ENODEV;
727 if (!substream->runtime)
728 return 0;
729
730 prtd = substream->runtime->private_data;
731 if (prtd) {
732 prtd->set_channel_map = true;
733 for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL; i++)
734 prtd->channel_map[i] =
735 (char)(ucontrol->value.integer.value[i]);
736 }
737 return 0;
738}
739
740static int msm_pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol,
741 struct snd_ctl_elem_value *ucontrol)
742{
743 int i;
744 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
745 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
746 struct snd_pcm_substream *substream;
747 struct msm_audio *prtd;
748
749 pr_debug("%s", __func__);
750 substream = snd_pcm_chmap_substream(info, idx);
751 if (!substream)
752 return -ENODEV;
753 memset(ucontrol->value.integer.value, 0,
754 sizeof(ucontrol->value.integer.value));
755 if (!substream->runtime)
756 return 0; /* no channels set */
757
758 prtd = substream->runtime->private_data;
759
760 if (prtd && prtd->set_channel_map == true) {
761 for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL; i++)
762 ucontrol->value.integer.value[i] =
763 (int)prtd->channel_map[i];
764 } else {
765 for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL; i++)
766 ucontrol->value.integer.value[i] = 0;
767 }
768
769 return 0;
770}
771
772static int msm_pcm_add_chmap_control(struct snd_soc_pcm_runtime *rtd)
773{
774 struct snd_pcm *pcm = rtd->pcm;
775 struct snd_pcm_chmap *chmap_info;
776 struct snd_kcontrol *kctl;
777 char device_num[12];
778 int i, ret;
779
780 pr_debug("%s, Channel map cntrl add\n", __func__);
781 ret = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
782 snd_pcm_std_chmaps,
783 PCM_FORMAT_MAX_NUM_CHANNEL, 0,
784 &chmap_info);
785 if (ret)
786 return ret;
787
788 kctl = chmap_info->kctl;
789 for (i = 0; i < kctl->count; i++)
790 kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
791 snprintf(device_num, sizeof(device_num), "%d", pcm->device);
792 strlcat(kctl->id.name, device_num, sizeof(kctl->id.name));
793 pr_debug("%s, Overwriting channel map control name to: %s",
794 __func__, kctl->id.name);
795 kctl->put = msm_pcm_chmap_ctl_put;
796 kctl->get = msm_pcm_chmap_ctl_get;
797 return 0;
798}
799
800static int msm_pcm_fe_topology_info(struct snd_kcontrol *kcontrol,
801 struct snd_ctl_elem_info *uinfo)
802{
803 const struct soc_enum *e = &msm_pcm_fe_topology_enum[0];
804
805 return snd_ctl_enum_info(uinfo, 1, e->items, e->texts);
806}
807
808static int msm_pcm_fe_topology_get(struct snd_kcontrol *kcontrol,
809 struct snd_ctl_elem_value *ucontrol)
810{
811 unsigned long fe_id = kcontrol->private_value;
812
813 if (fe_id >= MSM_FRONTEND_DAI_MAX) {
814 pr_err("%s Received out of bound fe_id %lu\n", __func__, fe_id);
815 return -EINVAL;
816 }
817
818 pr_debug("%s: %lu topology %s\n", __func__, fe_id,
819 msm_pcm_fe_topology_text[msm_pcm_fe_topology[fe_id]]);
820 ucontrol->value.enumerated.item[0] = msm_pcm_fe_topology[fe_id];
821 return 0;
822}
823
824static int msm_pcm_fe_topology_put(struct snd_kcontrol *kcontrol,
825 struct snd_ctl_elem_value *ucontrol)
826{
827 unsigned long fe_id = kcontrol->private_value;
828 unsigned int item;
829
830 if (fe_id >= MSM_FRONTEND_DAI_MAX) {
831 pr_err("%s Received out of bound fe_id %lu\n", __func__, fe_id);
832 return -EINVAL;
833 }
834
835 item = ucontrol->value.enumerated.item[0];
836 if (item >= ARRAY_SIZE(msm_pcm_fe_topology_text)) {
837 pr_err("%s Received out of bound topology %lu\n", __func__,
838 fe_id);
839 return -EINVAL;
840 }
841
842 pr_debug("%s: %lu new topology %s\n", __func__, fe_id,
843 msm_pcm_fe_topology_text[item]);
844 msm_pcm_fe_topology[fe_id] = item;
845 return 0;
846}
847
848static int msm_pcm_add_fe_topology_control(struct snd_soc_pcm_runtime *rtd)
849{
850 const char *mixer_ctl_name = "PCM_Dev";
851 const char *deviceNo = "NN";
852 const char *topo_text = "Topology";
853 char *mixer_str = NULL;
854 int ctl_len;
855 int ret;
856 struct snd_kcontrol_new topology_control[1] = {
857 {
858 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
859 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
860 .name = "?",
861 .info = msm_pcm_fe_topology_info,
862 .get = msm_pcm_fe_topology_get,
863 .put = msm_pcm_fe_topology_put,
864 .private_value = 0,
865 },
866 };
867
868 ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1 +
869 strlen(topo_text) + 1;
870 mixer_str = kzalloc(ctl_len, GFP_KERNEL);
871
872 if (!mixer_str)
873 return -ENOMEM;
874
875 snprintf(mixer_str, ctl_len, "%s %d %s", mixer_ctl_name,
876 rtd->pcm->device, topo_text);
877
878 topology_control[0].name = mixer_str;
879 topology_control[0].private_value = rtd->dai_link->id;
880 ret = snd_soc_add_platform_controls(rtd->platform, topology_control,
881 ARRAY_SIZE(topology_control));
882 msm_pcm_fe_topology[rtd->dai_link->id] = 0;
883 kfree(mixer_str);
884 return ret;
885}
886
887static int msm_pcm_playback_app_type_cfg_ctl_put(struct snd_kcontrol *kcontrol,
888 struct snd_ctl_elem_value *ucontrol)
889{
890 u64 fe_id = kcontrol->private_value;
891 int session_type = SESSION_TYPE_RX;
892 int be_id = ucontrol->value.integer.value[3];
893 struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
894 int ret = 0;
895
896 cfg_data.app_type = ucontrol->value.integer.value[0];
897 cfg_data.acdb_dev_id = ucontrol->value.integer.value[1];
898 if (ucontrol->value.integer.value[2] != 0)
899 cfg_data.sample_rate = ucontrol->value.integer.value[2];
900 pr_debug("%s: fe_id- %llu session_type- %d be_id- %d app_type- %d acdb_dev_id- %d sample_rate- %d\n",
901 __func__, fe_id, session_type, be_id,
902 cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
903 ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
904 be_id, &cfg_data);
905 if (ret < 0)
906 pr_err("%s: msm_pcm_routing_reg_stream_app_type_cfg failed returned %d\n",
907 __func__, ret);
908 return ret;
909}
910
911static int msm_pcm_playback_app_type_cfg_ctl_get(struct snd_kcontrol *kcontrol,
912 struct snd_ctl_elem_value *ucontrol)
913{
914 u64 fe_id = kcontrol->private_value;
915 int session_type = SESSION_TYPE_RX;
916 int be_id = 0;
917 struct msm_pcm_stream_app_type_cfg cfg_data = {0};
918 int ret = 0;
919
920 ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
921 &be_id, &cfg_data);
922 if (ret < 0) {
923 pr_err("%s: msm_pcm_routing_get_stream_app_type_cfg failed returned %d\n",
924 __func__, ret);
925 goto done;
926 }
927
928 ucontrol->value.integer.value[0] = cfg_data.app_type;
929 ucontrol->value.integer.value[1] = cfg_data.acdb_dev_id;
930 ucontrol->value.integer.value[2] = cfg_data.sample_rate;
931 ucontrol->value.integer.value[3] = be_id;
932 pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
933 __func__, fe_id, session_type, be_id,
934 cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
935done:
936 return ret;
937}
938
939static int msm_pcm_capture_app_type_cfg_ctl_put(struct snd_kcontrol *kcontrol,
940 struct snd_ctl_elem_value *ucontrol)
941{
942 u64 fe_id = kcontrol->private_value;
943 int session_type = SESSION_TYPE_TX;
944 int be_id = ucontrol->value.integer.value[3];
945 struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
946 int ret = 0;
947
948 cfg_data.app_type = ucontrol->value.integer.value[0];
949 cfg_data.acdb_dev_id = ucontrol->value.integer.value[1];
950 if (ucontrol->value.integer.value[2] != 0)
951 cfg_data.sample_rate = ucontrol->value.integer.value[2];
952 pr_debug("%s: fe_id- %llu session_type- %d be_id- %d app_type- %d acdb_dev_id- %d sample_rate- %d\n",
953 __func__, fe_id, session_type, be_id,
954 cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
955 ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
956 be_id, &cfg_data);
957 if (ret < 0)
958 pr_err("%s: msm_pcm_routing_reg_stream_app_type_cfg failed returned %d\n",
959 __func__, ret);
960
961 return ret;
962}
963
964static int msm_pcm_capture_app_type_cfg_ctl_get(struct snd_kcontrol *kcontrol,
965 struct snd_ctl_elem_value *ucontrol)
966{
967 u64 fe_id = kcontrol->private_value;
968 int session_type = SESSION_TYPE_TX;
969 int be_id = 0;
970 struct msm_pcm_stream_app_type_cfg cfg_data = {0};
971 int ret = 0;
972
973 ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
974 &be_id, &cfg_data);
975 if (ret < 0) {
976 pr_err("%s: msm_pcm_routing_get_stream_app_type_cfg failed returned %d\n",
977 __func__, ret);
978 goto done;
979 }
980
981 ucontrol->value.integer.value[0] = cfg_data.app_type;
982 ucontrol->value.integer.value[1] = cfg_data.acdb_dev_id;
983 ucontrol->value.integer.value[2] = cfg_data.sample_rate;
984 ucontrol->value.integer.value[3] = be_id;
985 pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
986 __func__, fe_id, session_type, be_id,
987 cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
988done:
989 return ret;
990}
991
992static int msm_pcm_add_app_type_controls(struct snd_soc_pcm_runtime *rtd)
993{
994 struct snd_pcm *pcm = rtd->pcm;
995 struct snd_pcm_usr *app_type_info;
996 struct snd_kcontrol *kctl;
997 const char *playback_mixer_ctl_name = "Audio Stream";
998 const char *capture_mixer_ctl_name = "Audio Stream Capture";
999 const char *deviceNo = "NN";
1000 const char *suffix = "App Type Cfg";
1001 int ctl_len, ret = 0;
1002
1003 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
1004 ctl_len = strlen(playback_mixer_ctl_name) + 1 +
1005 strlen(deviceNo) + 1 +
1006 strlen(suffix) + 1;
1007 pr_debug("%s: Playback app type cntrl add\n", __func__);
1008 ret = snd_pcm_add_usr_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1009 NULL, 1, ctl_len, rtd->dai_link->id,
1010 &app_type_info);
1011 if (ret < 0) {
1012 pr_err("%s: playback app type cntrl add failed, err: %d\n",
1013 __func__, ret);
1014 return ret;
1015 }
1016 kctl = app_type_info->kctl;
1017 snprintf(kctl->id.name, ctl_len, "%s %d %s",
1018 playback_mixer_ctl_name, rtd->pcm->device, suffix);
1019 kctl->put = msm_pcm_playback_app_type_cfg_ctl_put;
1020 kctl->get = msm_pcm_playback_app_type_cfg_ctl_get;
1021 }
1022
1023 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
1024 ctl_len = strlen(capture_mixer_ctl_name) + 1 +
1025 strlen(deviceNo) + 1 + strlen(suffix) + 1;
1026 pr_debug("%s: Capture app type cntrl add\n", __func__);
1027 ret = snd_pcm_add_usr_ctls(pcm, SNDRV_PCM_STREAM_CAPTURE,
1028 NULL, 1, ctl_len, rtd->dai_link->id,
1029 &app_type_info);
1030 if (ret < 0) {
1031 pr_err("%s: capture app type cntrl add failed, err: %d\n",
1032 __func__, ret);
1033 return ret;
1034 }
1035 kctl = app_type_info->kctl;
1036 snprintf(kctl->id.name, ctl_len, "%s %d %s",
1037 capture_mixer_ctl_name, rtd->pcm->device, suffix);
1038 kctl->put = msm_pcm_capture_app_type_cfg_ctl_put;
1039 kctl->get = msm_pcm_capture_app_type_cfg_ctl_get;
1040 }
1041
1042 return 0;
1043}
1044
Asish Bhattacharya84f7f732017-07-25 16:29:27 +05301045static int msm_pcm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
1046 unsigned int cmd, unsigned long arg)
1047{
1048 int ret = 0;
1049 struct snd_pcm *pcm = hw->private_data;
1050 struct snd_pcm_mmap_fd __user *_mmap_fd = NULL;
1051 struct snd_pcm_mmap_fd mmap_fd;
1052 struct snd_pcm_substream *substream = NULL;
1053 int32_t dir = -1;
1054
1055 switch (cmd) {
1056 case SNDRV_PCM_IOCTL_MMAP_DATA_FD:
1057 _mmap_fd = (struct snd_pcm_mmap_fd __user *)arg;
1058 if (get_user(dir, (int32_t __user *)&(_mmap_fd->dir))) {
1059 pr_err("%s: error copying mmap_fd from user\n",
1060 __func__);
1061 ret = -EFAULT;
1062 break;
1063 }
1064 if (dir != OUT && dir != IN) {
1065 pr_err("%s invalid stream dir\n", __func__);
1066 ret = -EINVAL;
1067 break;
1068 }
1069 substream = pcm->streams[dir].substream;
1070 if (!substream) {
1071 pr_err("%s substream not found\n", __func__);
1072 ret = -ENODEV;
1073 break;
1074 }
1075 pr_debug("%s : %s MMAP Data fd\n", __func__,
1076 dir == 0 ? "P" : "C");
1077 if (msm_pcm_mmap_fd(substream, &mmap_fd) < 0) {
1078 pr_err("%s: error getting fd\n",
1079 __func__);
1080 ret = -EFAULT;
1081 break;
1082 }
1083 if (put_user(mmap_fd.fd, &_mmap_fd->fd) ||
1084 put_user(mmap_fd.size, &_mmap_fd->size) ||
1085 put_user(mmap_fd.actual_size, &_mmap_fd->actual_size)) {
1086 pr_err("%s: error copying fd\n", __func__);
1087 return -EFAULT;
1088 }
1089 break;
1090 default:
1091 ret = -EINVAL;
1092 break;
1093 }
1094 return ret;
1095}
1096
1097#ifdef CONFIG_COMPAT
1098static int msm_pcm_hwdep_compat_ioctl(struct snd_hwdep *hw,
1099 struct file *file,
1100 unsigned int cmd,
1101 unsigned long arg)
1102{
1103 /* we only support mmap fd. Handling is common in both modes */
1104 return msm_pcm_hwdep_ioctl(hw, file, cmd, arg);
1105}
1106#else
1107static int msm_pcm_hwdep_compat_ioctl(struct snd_hwdep *hw,
1108 struct file *file,
1109 unsigned int cmd,
1110 unsigned long arg)
1111{
1112 return -EINVAL;
1113}
1114#endif
1115
1116static int msm_pcm_add_hwdep_dev(struct snd_soc_pcm_runtime *runtime)
1117{
1118 struct snd_hwdep *hwdep;
1119 int rc;
1120 char id[] = "NOIRQ_NN";
1121
1122 snprintf(id, sizeof(id), "NOIRQ_%d", runtime->pcm->device);
1123 pr_debug("%s: pcm dev %d\n", __func__, runtime->pcm->device);
1124 rc = snd_hwdep_new(runtime->card->snd_card,
1125 &id[0],
1126 HWDEP_FE_BASE + runtime->pcm->device,
1127 &hwdep);
1128 if (!hwdep || rc < 0) {
1129 pr_err("%s: hwdep intf failed to create %s - hwdep\n", __func__,
1130 id);
1131 return rc;
1132 }
1133
1134 hwdep->iface = SNDRV_HWDEP_IFACE_AUDIO_BE; /* for lack of a FE iface */
1135 hwdep->private_data = runtime->pcm; /* of type struct snd_pcm */
1136 hwdep->ops.ioctl = msm_pcm_hwdep_ioctl;
1137 hwdep->ops.ioctl_compat = msm_pcm_hwdep_compat_ioctl;
1138 return 0;
1139}
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301140
1141static int msm_asoc_pcm_new(struct snd_soc_pcm_runtime *rtd)
1142{
1143 struct snd_card *card = rtd->card->snd_card;
1144 struct snd_pcm *pcm = rtd->pcm;
1145 int ret;
1146
1147 pr_debug("%s , register new control\n", __func__);
1148 if (!card->dev->coherent_dma_mask)
1149 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
1150
1151 ret = msm_pcm_add_chmap_control(rtd);
1152 if (ret) {
1153 pr_err("%s failed to add chmap cntls\n", __func__);
1154 goto exit;
1155 }
1156 ret = msm_pcm_add_volume_control(rtd);
1157 if (ret) {
1158 pr_err("%s: Could not add pcm Volume Control %d\n",
1159 __func__, ret);
1160 }
1161
1162 ret = msm_pcm_add_fe_topology_control(rtd);
1163 if (ret) {
1164 pr_err("%s: Could not add pcm topology control %d\n",
1165 __func__, ret);
1166 }
1167
1168 ret = msm_pcm_add_app_type_controls(rtd);
1169 if (ret) {
1170 pr_err("%s: Could not add app type controls failed %d\n",
1171 __func__, ret);
1172 }
Asish Bhattacharya84f7f732017-07-25 16:29:27 +05301173 ret = msm_pcm_add_hwdep_dev(rtd);
1174 if (ret)
1175 pr_err("%s: Could not add hw dep node\n", __func__);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301176 pcm->nonatomic = true;
1177exit:
1178 return ret;
1179}
1180
1181
1182static const struct snd_pcm_ops msm_pcm_ops = {
1183 .open = msm_pcm_open,
1184 .prepare = msm_pcm_prepare,
1185 .copy = msm_pcm_copy,
1186 .hw_params = msm_pcm_hw_params,
1187 .ioctl = msm_pcm_ioctl,
Asish Bhattacharya84f7f732017-07-25 16:29:27 +05301188#ifdef CONFIG_COMPAT
1189 .compat_ioctl = msm_pcm_compat_ioctl,
1190#endif
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301191 .trigger = msm_pcm_trigger,
1192 .pointer = msm_pcm_pointer,
1193 .mmap = msm_pcm_mmap,
1194 .close = msm_pcm_close,
1195};
1196
1197static struct snd_soc_platform_driver msm_soc_platform = {
1198 .ops = &msm_pcm_ops,
1199 .pcm_new = msm_asoc_pcm_new,
1200};
1201
1202static int msm_pcm_probe(struct platform_device *pdev)
1203{
1204 int rc;
1205 struct msm_plat_data *pdata;
1206 const char *latency_level;
1207 int perf_mode = LOW_LATENCY_PCM_MODE;
1208
1209 dev_dbg(&pdev->dev, "Pull mode driver probe\n");
1210
1211 if (of_property_read_bool(pdev->dev.of_node,
1212 "qcom,msm-pcm-low-latency")) {
1213
1214 rc = of_property_read_string(pdev->dev.of_node,
1215 "qcom,latency-level", &latency_level);
1216 if (!rc) {
1217 if (!strcmp(latency_level, "ultra"))
1218 perf_mode = ULTRA_LOW_LATENCY_PCM_MODE;
1219 else if (!strcmp(latency_level, "ull-pp"))
1220 perf_mode = ULL_POST_PROCESSING_PCM_MODE;
1221 }
1222 }
1223
1224 pdata = devm_kzalloc(&pdev->dev,
1225 sizeof(struct msm_plat_data), GFP_KERNEL);
1226 if (!pdata)
1227 return -ENOMEM;
1228
1229 pdata->perf_mode = perf_mode;
1230
1231 dev_set_drvdata(&pdev->dev, pdata);
1232
1233 dev_dbg(&pdev->dev, "%s: dev name %s\n",
1234 __func__, dev_name(&pdev->dev));
1235 dev_dbg(&pdev->dev, "Pull mode driver register\n");
1236 rc = snd_soc_register_platform(&pdev->dev,
1237 &msm_soc_platform);
1238
1239 if (rc)
1240 dev_err(&pdev->dev, "Failed to register pull mode driver\n");
1241
1242 return rc;
1243}
1244
1245static int msm_pcm_remove(struct platform_device *pdev)
1246{
1247 struct msm_plat_data *pdata;
1248
1249 dev_dbg(&pdev->dev, "Pull mode remove\n");
1250 pdata = dev_get_drvdata(&pdev->dev);
1251 devm_kfree(&pdev->dev, pdata);
1252 snd_soc_unregister_platform(&pdev->dev);
1253 return 0;
1254}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301255static const struct of_device_id msm_pcm_noirq_dt_match[] = {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301256 {.compatible = "qcom,msm-pcm-dsp-noirq"},
1257 {}
1258};
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301259MODULE_DEVICE_TABLE(of, msm_pcm_noirq_dt_match);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301260
1261static struct platform_driver msm_pcm_driver_noirq = {
1262 .driver = {
1263 .name = "msm-pcm-dsp-noirq",
1264 .owner = THIS_MODULE,
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301265 .of_match_table = msm_pcm_noirq_dt_match,
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301266 },
1267 .probe = msm_pcm_probe,
1268 .remove = msm_pcm_remove,
1269};
1270
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301271int __init msm_pcm_noirq_init(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301272{
1273 return platform_driver_register(&msm_pcm_driver_noirq);
1274}
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301275
Asish Bhattacharya5faacb32017-12-04 17:23:15 +05301276void msm_pcm_noirq_exit(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301277{
1278 platform_driver_unregister(&msm_pcm_driver_noirq);
1279}
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301280
1281MODULE_DESCRIPTION("PCM NOIRQ module platform driver");
1282MODULE_LICENSE("GPL v2");