GNU Linux-libre 4.19.242-gnu1
[releases.git] / sound / soc / qcom / qdsp6 / q6asm-dai.c
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
3 // Copyright (c) 2018, Linaro Limited
4
5 #include <linux/init.h>
6 #include <linux/err.h>
7 #include <linux/module.h>
8 #include <linux/platform_device.h>
9 #include <linux/slab.h>
10 #include <sound/soc.h>
11 #include <sound/soc.h>
12 #include <sound/soc-dapm.h>
13 #include <sound/pcm.h>
14 #include <asm/dma.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/of_device.h>
17 #include <sound/pcm_params.h>
18 #include "q6asm.h"
19 #include "q6routing.h"
20 #include "q6dsp-errno.h"
21
22 #define DRV_NAME        "q6asm-fe-dai"
23
24 #define PLAYBACK_MIN_NUM_PERIODS    2
25 #define PLAYBACK_MAX_NUM_PERIODS   8
26 #define PLAYBACK_MAX_PERIOD_SIZE    65536
27 #define PLAYBACK_MIN_PERIOD_SIZE    128
28 #define CAPTURE_MIN_NUM_PERIODS     2
29 #define CAPTURE_MAX_NUM_PERIODS     8
30 #define CAPTURE_MAX_PERIOD_SIZE     4096
31 #define CAPTURE_MIN_PERIOD_SIZE     320
32 #define SID_MASK_DEFAULT        0xF
33
34 enum stream_state {
35         Q6ASM_STREAM_IDLE = 0,
36         Q6ASM_STREAM_STOPPED,
37         Q6ASM_STREAM_RUNNING,
38 };
39
40 struct q6asm_dai_rtd {
41         struct snd_pcm_substream *substream;
42         phys_addr_t phys;
43         unsigned int pcm_size;
44         unsigned int pcm_count;
45         unsigned int pcm_irq_pos;       /* IRQ position */
46         unsigned int periods;
47         uint16_t bits_per_sample;
48         uint16_t source; /* Encoding source bit mask */
49         struct audio_client *audio_client;
50         uint16_t session_id;
51         enum stream_state state;
52 };
53
54 struct q6asm_dai_data {
55         long long int sid;
56 };
57
58 static struct snd_pcm_hardware q6asm_dai_hardware_capture = {
59         .info =                 (SNDRV_PCM_INFO_MMAP |
60                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
61                                 SNDRV_PCM_INFO_MMAP_VALID |
62                                 SNDRV_PCM_INFO_INTERLEAVED |
63                                 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
64         .formats =              (SNDRV_PCM_FMTBIT_S16_LE |
65                                 SNDRV_PCM_FMTBIT_S24_LE),
66         .rates =                SNDRV_PCM_RATE_8000_48000,
67         .rate_min =             8000,
68         .rate_max =             48000,
69         .channels_min =         1,
70         .channels_max =         4,
71         .buffer_bytes_max =     CAPTURE_MAX_NUM_PERIODS *
72                                 CAPTURE_MAX_PERIOD_SIZE,
73         .period_bytes_min =     CAPTURE_MIN_PERIOD_SIZE,
74         .period_bytes_max =     CAPTURE_MAX_PERIOD_SIZE,
75         .periods_min =          CAPTURE_MIN_NUM_PERIODS,
76         .periods_max =          CAPTURE_MAX_NUM_PERIODS,
77         .fifo_size =            0,
78 };
79
80 static struct snd_pcm_hardware q6asm_dai_hardware_playback = {
81         .info =                 (SNDRV_PCM_INFO_MMAP |
82                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
83                                 SNDRV_PCM_INFO_MMAP_VALID |
84                                 SNDRV_PCM_INFO_INTERLEAVED |
85                                 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
86         .formats =              (SNDRV_PCM_FMTBIT_S16_LE |
87                                 SNDRV_PCM_FMTBIT_S24_LE),
88         .rates =                SNDRV_PCM_RATE_8000_192000,
89         .rate_min =             8000,
90         .rate_max =             192000,
91         .channels_min =         1,
92         .channels_max =         8,
93         .buffer_bytes_max =     (PLAYBACK_MAX_NUM_PERIODS *
94                                 PLAYBACK_MAX_PERIOD_SIZE),
95         .period_bytes_min =     PLAYBACK_MIN_PERIOD_SIZE,
96         .period_bytes_max =     PLAYBACK_MAX_PERIOD_SIZE,
97         .periods_min =          PLAYBACK_MIN_NUM_PERIODS,
98         .periods_max =          PLAYBACK_MAX_NUM_PERIODS,
99         .fifo_size =            0,
100 };
101
102 #define Q6ASM_FEDAI_DRIVER(num) { \
103                 .playback = {                                           \
104                         .stream_name = "MultiMedia"#num" Playback",     \
105                         .rates = (SNDRV_PCM_RATE_8000_192000|           \
106                                         SNDRV_PCM_RATE_KNOT),           \
107                         .formats = (SNDRV_PCM_FMTBIT_S16_LE |           \
108                                         SNDRV_PCM_FMTBIT_S24_LE),       \
109                         .channels_min = 1,                              \
110                         .channels_max = 8,                              \
111                         .rate_min =     8000,                           \
112                         .rate_max =     192000,                         \
113                 },                                                      \
114                 .capture = {                                            \
115                         .stream_name = "MultiMedia"#num" Capture",      \
116                         .rates = (SNDRV_PCM_RATE_8000_48000|            \
117                                         SNDRV_PCM_RATE_KNOT),           \
118                         .formats = (SNDRV_PCM_FMTBIT_S16_LE |           \
119                                     SNDRV_PCM_FMTBIT_S24_LE),           \
120                         .channels_min = 1,                              \
121                         .channels_max = 4,                              \
122                         .rate_min =     8000,                           \
123                         .rate_max =     48000,                          \
124                 },                                                      \
125                 .name = "MultiMedia"#num,                               \
126                 .probe = fe_dai_probe,                                  \
127                 .id = MSM_FRONTEND_DAI_MULTIMEDIA##num,                 \
128         }
129
130 /* Conventional and unconventional sample rate supported */
131 static unsigned int supported_sample_rates[] = {
132         8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
133         88200, 96000, 176400, 192000
134 };
135
136 static struct snd_pcm_hw_constraint_list constraints_sample_rates = {
137         .count = ARRAY_SIZE(supported_sample_rates),
138         .list = supported_sample_rates,
139         .mask = 0,
140 };
141
142 static void event_handler(uint32_t opcode, uint32_t token,
143                           uint32_t *payload, void *priv)
144 {
145         struct q6asm_dai_rtd *prtd = priv;
146         struct snd_pcm_substream *substream = prtd->substream;
147
148         switch (opcode) {
149         case ASM_CLIENT_EVENT_CMD_RUN_DONE:
150                 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
151                         q6asm_write_async(prtd->audio_client,
152                                    prtd->pcm_count, 0, 0, NO_TIMESTAMP);
153                 break;
154         case ASM_CLIENT_EVENT_CMD_EOS_DONE:
155                 prtd->state = Q6ASM_STREAM_STOPPED;
156                 break;
157         case ASM_CLIENT_EVENT_DATA_WRITE_DONE: {
158                 prtd->pcm_irq_pos += prtd->pcm_count;
159                 snd_pcm_period_elapsed(substream);
160                 if (prtd->state == Q6ASM_STREAM_RUNNING)
161                         q6asm_write_async(prtd->audio_client,
162                                            prtd->pcm_count, 0, 0, NO_TIMESTAMP);
163
164                 break;
165                 }
166         case ASM_CLIENT_EVENT_DATA_READ_DONE:
167                 prtd->pcm_irq_pos += prtd->pcm_count;
168                 snd_pcm_period_elapsed(substream);
169                 if (prtd->state == Q6ASM_STREAM_RUNNING)
170                         q6asm_read(prtd->audio_client);
171
172                 break;
173         default:
174                 break;
175         }
176 }
177
178 static int q6asm_dai_prepare(struct snd_pcm_substream *substream)
179 {
180         struct snd_pcm_runtime *runtime = substream->runtime;
181         struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
182         struct q6asm_dai_rtd *prtd = runtime->private_data;
183         struct snd_soc_component *c = snd_soc_rtdcom_lookup(soc_prtd, DRV_NAME);
184         struct q6asm_dai_data *pdata;
185         int ret, i;
186
187         pdata = snd_soc_component_get_drvdata(c);
188         if (!pdata)
189                 return -EINVAL;
190
191         if (!prtd || !prtd->audio_client) {
192                 pr_err("%s: private data null or audio client freed\n",
193                         __func__);
194                 return -EINVAL;
195         }
196
197         prtd->pcm_count = snd_pcm_lib_period_bytes(substream);
198         prtd->pcm_irq_pos = 0;
199         /* rate and channels are sent to audio driver */
200         if (prtd->state) {
201                 /* clear the previous setup if any  */
202                 q6asm_cmd(prtd->audio_client, CMD_CLOSE);
203                 q6asm_unmap_memory_regions(substream->stream,
204                                            prtd->audio_client);
205                 q6routing_stream_close(soc_prtd->dai_link->id,
206                                          substream->stream);
207         }
208
209         ret = q6asm_map_memory_regions(substream->stream, prtd->audio_client,
210                                        prtd->phys,
211                                        (prtd->pcm_size / prtd->periods),
212                                        prtd->periods);
213
214         if (ret < 0) {
215                 pr_err("Audio Start: Buffer Allocation failed rc = %d\n",
216                                                         ret);
217                 return -ENOMEM;
218         }
219
220         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
221                 ret = q6asm_open_write(prtd->audio_client, FORMAT_LINEAR_PCM,
222                                        prtd->bits_per_sample);
223         } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
224                 ret = q6asm_open_read(prtd->audio_client, FORMAT_LINEAR_PCM,
225                                        prtd->bits_per_sample);
226         }
227
228         if (ret < 0) {
229                 pr_err("%s: q6asm_open_write failed\n", __func__);
230                 q6asm_audio_client_free(prtd->audio_client);
231                 prtd->audio_client = NULL;
232                 return -ENOMEM;
233         }
234
235         prtd->session_id = q6asm_get_session_id(prtd->audio_client);
236         ret = q6routing_stream_open(soc_prtd->dai_link->id, LEGACY_PCM_MODE,
237                               prtd->session_id, substream->stream);
238         if (ret) {
239                 pr_err("%s: stream reg failed ret:%d\n", __func__, ret);
240                 return ret;
241         }
242
243         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
244                 ret = q6asm_media_format_block_multi_ch_pcm(
245                                 prtd->audio_client, runtime->rate,
246                                 runtime->channels, NULL,
247                                 prtd->bits_per_sample);
248         } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
249                 ret = q6asm_enc_cfg_blk_pcm_format_support(prtd->audio_client,
250                                         runtime->rate, runtime->channels,
251                                         prtd->bits_per_sample);
252
253                 /* Queue the buffers */
254                 for (i = 0; i < runtime->periods; i++)
255                         q6asm_read(prtd->audio_client);
256
257         }
258         if (ret < 0)
259                 pr_info("%s: CMD Format block failed\n", __func__);
260
261         prtd->state = Q6ASM_STREAM_RUNNING;
262
263         return 0;
264 }
265
266 static int q6asm_dai_trigger(struct snd_pcm_substream *substream, int cmd)
267 {
268         int ret = 0;
269         struct snd_pcm_runtime *runtime = substream->runtime;
270         struct q6asm_dai_rtd *prtd = runtime->private_data;
271
272         switch (cmd) {
273         case SNDRV_PCM_TRIGGER_START:
274         case SNDRV_PCM_TRIGGER_RESUME:
275         case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
276                 ret = q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
277                 break;
278         case SNDRV_PCM_TRIGGER_STOP:
279                 prtd->state = Q6ASM_STREAM_STOPPED;
280                 ret = q6asm_cmd_nowait(prtd->audio_client, CMD_EOS);
281                 break;
282         case SNDRV_PCM_TRIGGER_SUSPEND:
283         case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
284                 ret = q6asm_cmd_nowait(prtd->audio_client, CMD_PAUSE);
285                 break;
286         default:
287                 ret = -EINVAL;
288                 break;
289         }
290
291         return ret;
292 }
293
294 static int q6asm_dai_open(struct snd_pcm_substream *substream)
295 {
296         struct snd_pcm_runtime *runtime = substream->runtime;
297         struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
298         struct snd_soc_dai *cpu_dai = soc_prtd->cpu_dai;
299         struct snd_soc_component *c = snd_soc_rtdcom_lookup(soc_prtd, DRV_NAME);
300         struct q6asm_dai_rtd *prtd;
301         struct q6asm_dai_data *pdata;
302         struct device *dev = c->dev;
303         int ret = 0;
304         int stream_id;
305
306         stream_id = cpu_dai->driver->id;
307
308         pdata = snd_soc_component_get_drvdata(c);
309         if (!pdata) {
310                 pr_err("Drv data not found ..\n");
311                 return -EINVAL;
312         }
313
314         prtd = kzalloc(sizeof(struct q6asm_dai_rtd), GFP_KERNEL);
315         if (prtd == NULL)
316                 return -ENOMEM;
317
318         prtd->substream = substream;
319         prtd->audio_client = q6asm_audio_client_alloc(dev,
320                                 (q6asm_cb)event_handler, prtd, stream_id,
321                                 LEGACY_PCM_MODE);
322         if (IS_ERR(prtd->audio_client)) {
323                 pr_info("%s: Could not allocate memory\n", __func__);
324                 ret = PTR_ERR(prtd->audio_client);
325                 kfree(prtd);
326                 return ret;
327         }
328
329         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
330                 runtime->hw = q6asm_dai_hardware_playback;
331         else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
332                 runtime->hw = q6asm_dai_hardware_capture;
333
334         ret = snd_pcm_hw_constraint_list(runtime, 0,
335                                 SNDRV_PCM_HW_PARAM_RATE,
336                                 &constraints_sample_rates);
337         if (ret < 0)
338                 pr_info("snd_pcm_hw_constraint_list failed\n");
339         /* Ensure that buffer size is a multiple of period size */
340         ret = snd_pcm_hw_constraint_integer(runtime,
341                                             SNDRV_PCM_HW_PARAM_PERIODS);
342         if (ret < 0)
343                 pr_info("snd_pcm_hw_constraint_integer failed\n");
344
345         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
346                 ret = snd_pcm_hw_constraint_minmax(runtime,
347                         SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
348                         PLAYBACK_MIN_NUM_PERIODS * PLAYBACK_MIN_PERIOD_SIZE,
349                         PLAYBACK_MAX_NUM_PERIODS * PLAYBACK_MAX_PERIOD_SIZE);
350                 if (ret < 0) {
351                         pr_err("constraint for buffer bytes min max ret = %d\n",
352                                                                         ret);
353                 }
354         }
355
356         ret = snd_pcm_hw_constraint_step(runtime, 0,
357                 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
358         if (ret < 0) {
359                 pr_err("constraint for period bytes step ret = %d\n",
360                                                                 ret);
361         }
362         ret = snd_pcm_hw_constraint_step(runtime, 0,
363                 SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 32);
364         if (ret < 0) {
365                 pr_err("constraint for buffer bytes step ret = %d\n",
366                                                                 ret);
367         }
368
369         runtime->private_data = prtd;
370
371         snd_soc_set_runtime_hwparams(substream, &q6asm_dai_hardware_playback);
372
373         runtime->dma_bytes = q6asm_dai_hardware_playback.buffer_bytes_max;
374
375
376         if (pdata->sid < 0)
377                 prtd->phys = substream->dma_buffer.addr;
378         else
379                 prtd->phys = substream->dma_buffer.addr | (pdata->sid << 32);
380
381         snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
382
383         return 0;
384 }
385
386 static int q6asm_dai_close(struct snd_pcm_substream *substream)
387 {
388         struct snd_pcm_runtime *runtime = substream->runtime;
389         struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
390         struct q6asm_dai_rtd *prtd = runtime->private_data;
391
392         if (prtd->audio_client) {
393                 if (prtd->state)
394                         q6asm_cmd(prtd->audio_client, CMD_CLOSE);
395
396                 q6asm_unmap_memory_regions(substream->stream,
397                                            prtd->audio_client);
398                 q6asm_audio_client_free(prtd->audio_client);
399                 prtd->audio_client = NULL;
400         }
401         q6routing_stream_close(soc_prtd->dai_link->id,
402                                                 substream->stream);
403         kfree(prtd);
404         return 0;
405 }
406
407 static snd_pcm_uframes_t q6asm_dai_pointer(struct snd_pcm_substream *substream)
408 {
409
410         struct snd_pcm_runtime *runtime = substream->runtime;
411         struct q6asm_dai_rtd *prtd = runtime->private_data;
412
413         if (prtd->pcm_irq_pos >= prtd->pcm_size)
414                 prtd->pcm_irq_pos = 0;
415
416         return bytes_to_frames(runtime, (prtd->pcm_irq_pos));
417 }
418
419 static int q6asm_dai_mmap(struct snd_pcm_substream *substream,
420                                 struct vm_area_struct *vma)
421 {
422
423         struct snd_pcm_runtime *runtime = substream->runtime;
424         struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
425         struct snd_soc_component *c = snd_soc_rtdcom_lookup(soc_prtd, DRV_NAME);
426         struct device *dev = c->dev;
427
428         return dma_mmap_coherent(dev, vma,
429                         runtime->dma_area, runtime->dma_addr,
430                         runtime->dma_bytes);
431 }
432
433 static int q6asm_dai_hw_params(struct snd_pcm_substream *substream,
434                                 struct snd_pcm_hw_params *params)
435 {
436         struct snd_pcm_runtime *runtime = substream->runtime;
437         struct q6asm_dai_rtd *prtd = runtime->private_data;
438
439         prtd->pcm_size = params_buffer_bytes(params);
440         prtd->periods = params_periods(params);
441
442         switch (params_format(params)) {
443         case SNDRV_PCM_FORMAT_S16_LE:
444                 prtd->bits_per_sample = 16;
445                 break;
446         case SNDRV_PCM_FORMAT_S24_LE:
447                 prtd->bits_per_sample = 24;
448                 break;
449         }
450
451         return 0;
452 }
453
454 static struct snd_pcm_ops q6asm_dai_ops = {
455         .open           = q6asm_dai_open,
456         .hw_params      = q6asm_dai_hw_params,
457         .close          = q6asm_dai_close,
458         .ioctl          = snd_pcm_lib_ioctl,
459         .prepare        = q6asm_dai_prepare,
460         .trigger        = q6asm_dai_trigger,
461         .pointer        = q6asm_dai_pointer,
462         .mmap           = q6asm_dai_mmap,
463 };
464
465 static int q6asm_dai_pcm_new(struct snd_soc_pcm_runtime *rtd)
466 {
467         struct snd_pcm_substream *psubstream, *csubstream;
468         struct snd_soc_component *c = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
469         struct snd_pcm *pcm = rtd->pcm;
470         struct device *dev;
471         int size, ret;
472
473         dev = c->dev;
474         size = q6asm_dai_hardware_playback.buffer_bytes_max;
475         psubstream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
476         if (psubstream) {
477                 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size,
478                                           &psubstream->dma_buffer);
479                 if (ret) {
480                         dev_err(dev, "Cannot allocate buffer(s)\n");
481                         return ret;
482                 }
483         }
484
485         csubstream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
486         if (csubstream) {
487                 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size,
488                                           &csubstream->dma_buffer);
489                 if (ret) {
490                         dev_err(dev, "Cannot allocate buffer(s)\n");
491                         if (psubstream)
492                                 snd_dma_free_pages(&psubstream->dma_buffer);
493                         return ret;
494                 }
495         }
496
497         return ret;
498 }
499
500 static void q6asm_dai_pcm_free(struct snd_pcm *pcm)
501 {
502         struct snd_pcm_substream *substream;
503         int i;
504
505         for (i = 0; i < ARRAY_SIZE(pcm->streams); i++) {
506                 substream = pcm->streams[i].substream;
507                 if (substream) {
508                         snd_dma_free_pages(&substream->dma_buffer);
509                         substream->dma_buffer.area = NULL;
510                         substream->dma_buffer.addr = 0;
511                 }
512         }
513 }
514
515 static const struct snd_soc_dapm_route afe_pcm_routes[] = {
516         {"MM_DL1",  NULL, "MultiMedia1 Playback" },
517         {"MM_DL2",  NULL, "MultiMedia2 Playback" },
518         {"MM_DL3",  NULL, "MultiMedia3 Playback" },
519         {"MM_DL4",  NULL, "MultiMedia4 Playback" },
520         {"MM_DL5",  NULL, "MultiMedia5 Playback" },
521         {"MM_DL6",  NULL, "MultiMedia6 Playback" },
522         {"MM_DL7",  NULL, "MultiMedia7 Playback" },
523         {"MM_DL7",  NULL, "MultiMedia8 Playback" },
524         {"MultiMedia1 Capture", NULL, "MM_UL1"},
525         {"MultiMedia2 Capture", NULL, "MM_UL2"},
526         {"MultiMedia3 Capture", NULL, "MM_UL3"},
527         {"MultiMedia4 Capture", NULL, "MM_UL4"},
528         {"MultiMedia5 Capture", NULL, "MM_UL5"},
529         {"MultiMedia6 Capture", NULL, "MM_UL6"},
530         {"MultiMedia7 Capture", NULL, "MM_UL7"},
531         {"MultiMedia8 Capture", NULL, "MM_UL8"},
532
533 };
534
535 static int fe_dai_probe(struct snd_soc_dai *dai)
536 {
537         struct snd_soc_dapm_context *dapm;
538
539         dapm = snd_soc_component_get_dapm(dai->component);
540         snd_soc_dapm_add_routes(dapm, afe_pcm_routes,
541                                 ARRAY_SIZE(afe_pcm_routes));
542
543         return 0;
544 }
545
546
547 static const struct snd_soc_component_driver q6asm_fe_dai_component = {
548         .name           = DRV_NAME,
549         .ops            = &q6asm_dai_ops,
550         .pcm_new        = q6asm_dai_pcm_new,
551         .pcm_free       = q6asm_dai_pcm_free,
552
553 };
554
555 static struct snd_soc_dai_driver q6asm_fe_dais[] = {
556         Q6ASM_FEDAI_DRIVER(1),
557         Q6ASM_FEDAI_DRIVER(2),
558         Q6ASM_FEDAI_DRIVER(3),
559         Q6ASM_FEDAI_DRIVER(4),
560         Q6ASM_FEDAI_DRIVER(5),
561         Q6ASM_FEDAI_DRIVER(6),
562         Q6ASM_FEDAI_DRIVER(7),
563         Q6ASM_FEDAI_DRIVER(8),
564 };
565
566 static int q6asm_dai_probe(struct platform_device *pdev)
567 {
568         struct device *dev = &pdev->dev;
569         struct device_node *node = dev->of_node;
570         struct of_phandle_args args;
571         struct q6asm_dai_data *pdata;
572         int rc;
573
574         pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
575         if (!pdata)
576                 return -ENOMEM;
577
578         rc = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args);
579         if (rc < 0)
580                 pdata->sid = -1;
581         else
582                 pdata->sid = args.args[0] & SID_MASK_DEFAULT;
583
584         dev_set_drvdata(dev, pdata);
585
586         return devm_snd_soc_register_component(dev, &q6asm_fe_dai_component,
587                                         q6asm_fe_dais,
588                                         ARRAY_SIZE(q6asm_fe_dais));
589 }
590
591 static const struct of_device_id q6asm_dai_device_id[] = {
592         { .compatible = "qcom,q6asm-dais" },
593         {},
594 };
595 MODULE_DEVICE_TABLE(of, q6asm_dai_device_id);
596
597 static struct platform_driver q6asm_dai_platform_driver = {
598         .driver = {
599                 .name = "q6asm-dai",
600                 .of_match_table = of_match_ptr(q6asm_dai_device_id),
601         },
602         .probe = q6asm_dai_probe,
603 };
604 module_platform_driver(q6asm_dai_platform_driver);
605
606 MODULE_DESCRIPTION("Q6ASM dai driver");
607 MODULE_LICENSE("GPL v2");