ASoC: wm_adsp: Declare firmware controls from codec driver
[muen/linux.git] / sound / soc / qcom / qdsp6 / q6afe-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/err.h>
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/device.h>
9 #include <linux/platform_device.h>
10 #include <linux/slab.h>
11 #include <sound/pcm.h>
12 #include <sound/soc.h>
13 #include <sound/pcm_params.h>
14 #include "q6afe.h"
15
16 #define Q6AFE_TDM_PB_DAI(pre, num, did) {                               \
17                 .playback = {                                           \
18                         .stream_name = pre" TDM"#num" Playback",        \
19                         .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
20                                 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
21                                 SNDRV_PCM_RATE_176400,                  \
22                         .formats = SNDRV_PCM_FMTBIT_S16_LE |            \
23                                    SNDRV_PCM_FMTBIT_S24_LE |            \
24                                    SNDRV_PCM_FMTBIT_S32_LE,             \
25                         .channels_min = 1,                              \
26                         .channels_max = 8,                              \
27                         .rate_min = 8000,                               \
28                         .rate_max = 176400,                             \
29                 },                                                      \
30                 .name = #did,                                           \
31                 .ops = &q6tdm_ops,                                      \
32                 .id = did,                                              \
33                 .probe = msm_dai_q6_dai_probe,                          \
34                 .remove = msm_dai_q6_dai_remove,                        \
35         }
36
37 #define Q6AFE_TDM_CAP_DAI(pre, num, did) {                              \
38                 .capture = {                                            \
39                         .stream_name = pre" TDM"#num" Capture",         \
40                         .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
41                                 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
42                                 SNDRV_PCM_RATE_176400,                  \
43                         .formats = SNDRV_PCM_FMTBIT_S16_LE |            \
44                                    SNDRV_PCM_FMTBIT_S24_LE |            \
45                                    SNDRV_PCM_FMTBIT_S32_LE,             \
46                         .channels_min = 1,                              \
47                         .channels_max = 8,                              \
48                         .rate_min = 8000,                               \
49                         .rate_max = 176400,                             \
50                 },                                                      \
51                 .name = #did,                                           \
52                 .ops = &q6tdm_ops,                                      \
53                 .id = did,                                              \
54                 .probe = msm_dai_q6_dai_probe,                          \
55                 .remove = msm_dai_q6_dai_remove,                        \
56         }
57
58 struct q6afe_dai_priv_data {
59         uint32_t sd_line_mask;
60         uint32_t sync_mode;
61         uint32_t sync_src;
62         uint32_t data_out_enable;
63         uint32_t invert_sync;
64         uint32_t data_delay;
65         uint32_t data_align;
66 };
67
68 struct q6afe_dai_data {
69         struct q6afe_port *port[AFE_PORT_MAX];
70         struct q6afe_port_config port_config[AFE_PORT_MAX];
71         bool is_port_started[AFE_PORT_MAX];
72         struct q6afe_dai_priv_data priv[AFE_PORT_MAX];
73 };
74
75 static int q6slim_hw_params(struct snd_pcm_substream *substream,
76                             struct snd_pcm_hw_params *params,
77                             struct snd_soc_dai *dai)
78 {
79
80         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
81         struct q6afe_slim_cfg *slim = &dai_data->port_config[dai->id].slim;
82
83         slim->sample_rate = params_rate(params);
84
85         switch (params_format(params)) {
86         case SNDRV_PCM_FORMAT_S16_LE:
87         case SNDRV_PCM_FORMAT_SPECIAL:
88                 slim->bit_width = 16;
89                 break;
90         case SNDRV_PCM_FORMAT_S24_LE:
91                 slim->bit_width = 24;
92                 break;
93         case SNDRV_PCM_FORMAT_S32_LE:
94                 slim->bit_width = 32;
95                 break;
96         default:
97                 pr_err("%s: format %d\n",
98                         __func__, params_format(params));
99                 return -EINVAL;
100         }
101
102         return 0;
103 }
104
105 static int q6hdmi_hw_params(struct snd_pcm_substream *substream,
106                                 struct snd_pcm_hw_params *params,
107                                 struct snd_soc_dai *dai)
108 {
109         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
110         int channels = params_channels(params);
111         struct q6afe_hdmi_cfg *hdmi = &dai_data->port_config[dai->id].hdmi;
112
113         hdmi->sample_rate = params_rate(params);
114         switch (params_format(params)) {
115         case SNDRV_PCM_FORMAT_S16_LE:
116                 hdmi->bit_width = 16;
117                 break;
118         case SNDRV_PCM_FORMAT_S24_LE:
119                 hdmi->bit_width = 24;
120                 break;
121         }
122
123         /* HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4 */
124         switch (channels) {
125         case 2:
126                 hdmi->channel_allocation = 0;
127                 break;
128         case 3:
129                 hdmi->channel_allocation = 0x02;
130                 break;
131         case 4:
132                 hdmi->channel_allocation = 0x06;
133                 break;
134         case 5:
135                 hdmi->channel_allocation = 0x0A;
136                 break;
137         case 6:
138                 hdmi->channel_allocation = 0x0B;
139                 break;
140         case 7:
141                 hdmi->channel_allocation = 0x12;
142                 break;
143         case 8:
144                 hdmi->channel_allocation = 0x13;
145                 break;
146         default:
147                 dev_err(dai->dev, "invalid Channels = %u\n", channels);
148                 return -EINVAL;
149         }
150
151         return 0;
152 }
153
154 static int q6i2s_hw_params(struct snd_pcm_substream *substream,
155                            struct snd_pcm_hw_params *params,
156                            struct snd_soc_dai *dai)
157 {
158         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
159         struct q6afe_i2s_cfg *i2s = &dai_data->port_config[dai->id].i2s_cfg;
160
161         i2s->sample_rate = params_rate(params);
162         i2s->bit_width = params_width(params);
163         i2s->num_channels = params_channels(params);
164         i2s->sd_line_mask = dai_data->priv[dai->id].sd_line_mask;
165
166         return 0;
167 }
168
169 static int q6i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
170 {
171         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
172         struct q6afe_i2s_cfg *i2s = &dai_data->port_config[dai->id].i2s_cfg;
173
174         i2s->fmt = fmt;
175
176         return 0;
177 }
178
179 static int q6tdm_set_tdm_slot(struct snd_soc_dai *dai,
180                                 unsigned int tx_mask,
181                                 unsigned int rx_mask,
182                                 int slots, int slot_width)
183 {
184
185         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
186         struct q6afe_tdm_cfg *tdm = &dai_data->port_config[dai->id].tdm;
187         unsigned int cap_mask;
188         int rc = 0;
189
190         /* HW only supports 16 and 32 bit slot width configuration */
191         if ((slot_width != 16) && (slot_width != 32)) {
192                 dev_err(dai->dev, "%s: invalid slot_width %d\n",
193                         __func__, slot_width);
194                 return -EINVAL;
195         }
196
197         /* HW supports 1-32 slots configuration. Typical: 1, 2, 4, 8, 16, 32 */
198         switch (slots) {
199         case 2:
200                 cap_mask = 0x03;
201                 break;
202         case 4:
203                 cap_mask = 0x0F;
204                 break;
205         case 8:
206                 cap_mask = 0xFF;
207                 break;
208         case 16:
209                 cap_mask = 0xFFFF;
210                 break;
211         default:
212                 dev_err(dai->dev, "%s: invalid slots %d\n",
213                         __func__, slots);
214                 return -EINVAL;
215         }
216
217         switch (dai->id) {
218         case PRIMARY_TDM_RX_0 ... QUINARY_TDM_TX_7:
219                 tdm->nslots_per_frame = slots;
220                 tdm->slot_width = slot_width;
221                 /* TDM RX dais ids are even and tx are odd */
222                 tdm->slot_mask = (dai->id & 0x1 ? tx_mask : rx_mask) & cap_mask;
223                 break;
224         default:
225                 dev_err(dai->dev, "%s: invalid dai id 0x%x\n",
226                         __func__, dai->id);
227                 return -EINVAL;
228         }
229
230         return rc;
231 }
232
233 static int q6tdm_set_channel_map(struct snd_soc_dai *dai,
234                                 unsigned int tx_num, unsigned int *tx_slot,
235                                 unsigned int rx_num, unsigned int *rx_slot)
236 {
237
238         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
239         struct q6afe_tdm_cfg *tdm = &dai_data->port_config[dai->id].tdm;
240         int rc = 0;
241         int i = 0;
242
243         switch (dai->id) {
244         case PRIMARY_TDM_RX_0 ... QUINARY_TDM_TX_7:
245                 if (dai->id & 0x1) {
246                         if (!tx_slot) {
247                                 dev_err(dai->dev, "tx slot not found\n");
248                                 return -EINVAL;
249                         }
250                         if (tx_num > AFE_PORT_MAX_AUDIO_CHAN_CNT) {
251                                 dev_err(dai->dev, "invalid tx num %d\n",
252                                         tx_num);
253                                 return -EINVAL;
254                         }
255
256                         for (i = 0; i < tx_num; i++)
257                                 tdm->ch_mapping[i] = tx_slot[i];
258
259                         for (i = tx_num; i < AFE_PORT_MAX_AUDIO_CHAN_CNT; i++)
260                                 tdm->ch_mapping[i] = Q6AFE_CMAP_INVALID;
261
262                         tdm->num_channels = tx_num;
263                 } else {
264                         /* rx */
265                         if (!rx_slot) {
266                                 dev_err(dai->dev, "rx slot not found\n");
267                                 return -EINVAL;
268                         }
269                         if (rx_num > AFE_PORT_MAX_AUDIO_CHAN_CNT) {
270                                 dev_err(dai->dev, "invalid rx num %d\n",
271                                         rx_num);
272                                 return -EINVAL;
273                         }
274
275                         for (i = 0; i < rx_num; i++)
276                                 tdm->ch_mapping[i] = rx_slot[i];
277
278                         for (i = rx_num; i < AFE_PORT_MAX_AUDIO_CHAN_CNT; i++)
279                                 tdm->ch_mapping[i] = Q6AFE_CMAP_INVALID;
280
281                         tdm->num_channels = rx_num;
282                 }
283
284                 break;
285         default:
286                 dev_err(dai->dev, "%s: invalid dai id 0x%x\n",
287                         __func__, dai->id);
288                 return -EINVAL;
289         }
290
291         return rc;
292 }
293
294 static int q6tdm_hw_params(struct snd_pcm_substream *substream,
295                            struct snd_pcm_hw_params *params,
296                            struct snd_soc_dai *dai)
297 {
298         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
299         struct q6afe_tdm_cfg *tdm = &dai_data->port_config[dai->id].tdm;
300
301         tdm->bit_width = params_width(params);
302         tdm->sample_rate = params_rate(params);
303         tdm->num_channels = params_channels(params);
304         tdm->data_align_type = dai_data->priv[dai->id].data_align;
305         tdm->sync_src = dai_data->priv[dai->id].sync_src;
306         tdm->sync_mode = dai_data->priv[dai->id].sync_mode;
307
308         return 0;
309 }
310 static void q6afe_dai_shutdown(struct snd_pcm_substream *substream,
311                                 struct snd_soc_dai *dai)
312 {
313         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
314         int rc;
315
316         rc = q6afe_port_stop(dai_data->port[dai->id]);
317         if (rc < 0)
318                 dev_err(dai->dev, "fail to close AFE port (%d)\n", rc);
319
320         dai_data->is_port_started[dai->id] = false;
321
322 }
323
324 static int q6afe_dai_prepare(struct snd_pcm_substream *substream,
325                 struct snd_soc_dai *dai)
326 {
327         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
328         int rc;
329
330         if (dai_data->is_port_started[dai->id]) {
331                 /* stop the port and restart with new port config */
332                 rc = q6afe_port_stop(dai_data->port[dai->id]);
333                 if (rc < 0) {
334                         dev_err(dai->dev, "fail to close AFE port (%d)\n", rc);
335                         return rc;
336                 }
337         }
338
339         switch (dai->id) {
340         case HDMI_RX:
341                 q6afe_hdmi_port_prepare(dai_data->port[dai->id],
342                                         &dai_data->port_config[dai->id].hdmi);
343                 break;
344         case SLIMBUS_0_RX ... SLIMBUS_6_TX:
345                 q6afe_slim_port_prepare(dai_data->port[dai->id],
346                                         &dai_data->port_config[dai->id].slim);
347                 break;
348         case PRIMARY_MI2S_RX ... QUATERNARY_MI2S_TX:
349                 rc = q6afe_i2s_port_prepare(dai_data->port[dai->id],
350                                &dai_data->port_config[dai->id].i2s_cfg);
351                 if (rc < 0) {
352                         dev_err(dai->dev, "fail to prepare AFE port %x\n",
353                                 dai->id);
354                         return rc;
355                 }
356                 break;
357         case PRIMARY_TDM_RX_0 ... QUINARY_TDM_TX_7:
358                 q6afe_tdm_port_prepare(dai_data->port[dai->id],
359                                         &dai_data->port_config[dai->id].tdm);
360                 break;
361         default:
362                 return -EINVAL;
363         }
364
365         rc = q6afe_port_start(dai_data->port[dai->id]);
366         if (rc < 0) {
367                 dev_err(dai->dev, "fail to start AFE port %x\n", dai->id);
368                 return rc;
369         }
370         dai_data->is_port_started[dai->id] = true;
371
372         return 0;
373 }
374
375 static int q6slim_set_channel_map(struct snd_soc_dai *dai,
376                                 unsigned int tx_num, unsigned int *tx_slot,
377                                 unsigned int rx_num, unsigned int *rx_slot)
378 {
379         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
380         struct q6afe_port_config *pcfg = &dai_data->port_config[dai->id];
381         int i;
382
383         if (dai->id & 0x1) {
384                 /* TX */
385                 if (!tx_slot) {
386                         pr_err("%s: tx slot not found\n", __func__);
387                         return -EINVAL;
388                 }
389
390                 for (i = 0; i < tx_num; i++)
391                         pcfg->slim.ch_mapping[i] = tx_slot[i];
392
393                 pcfg->slim.num_channels = tx_num;
394
395
396         } else {
397                 if (!rx_slot) {
398                         pr_err("%s: rx slot not found\n", __func__);
399                         return -EINVAL;
400                 }
401
402                 for (i = 0; i < rx_num; i++)
403                         pcfg->slim.ch_mapping[i] =   rx_slot[i];
404
405                 pcfg->slim.num_channels = rx_num;
406
407         }
408
409         return 0;
410 }
411
412 static int q6afe_mi2s_set_sysclk(struct snd_soc_dai *dai,
413                 int clk_id, unsigned int freq, int dir)
414 {
415         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
416         struct q6afe_port *port = dai_data->port[dai->id];
417
418         switch (clk_id) {
419         case LPAIF_DIG_CLK:
420                 return q6afe_port_set_sysclk(port, clk_id, 0, 5, freq, dir);
421         case LPAIF_BIT_CLK:
422         case LPAIF_OSR_CLK:
423                 return q6afe_port_set_sysclk(port, clk_id,
424                                              Q6AFE_LPASS_CLK_SRC_INTERNAL,
425                                              Q6AFE_LPASS_CLK_ROOT_DEFAULT,
426                                              freq, dir);
427         case Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT ... Q6AFE_LPASS_CLK_ID_QUI_MI2S_OSR:
428         case Q6AFE_LPASS_CLK_ID_MCLK_1 ... Q6AFE_LPASS_CLK_ID_INT_MCLK_1:
429                 return q6afe_port_set_sysclk(port, clk_id,
430                                              Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
431                                              Q6AFE_LPASS_CLK_ROOT_DEFAULT,
432                                              freq, dir);
433         case Q6AFE_LPASS_CLK_ID_PRI_TDM_IBIT ... Q6AFE_LPASS_CLK_ID_QUIN_TDM_EBIT:
434                 return q6afe_port_set_sysclk(port, clk_id,
435                                              Q6AFE_LPASS_CLK_ATTRIBUTE_INVERT_COUPLE_NO,
436                                              Q6AFE_LPASS_CLK_ROOT_DEFAULT,
437                                              freq, dir);
438         }
439
440         return 0;
441 }
442
443 static const struct snd_soc_dapm_route q6afe_dapm_routes[] = {
444         {"HDMI Playback", NULL, "HDMI_RX"},
445         {"Slimbus1 Playback", NULL, "SLIMBUS_1_RX"},
446         {"Slimbus2 Playback", NULL, "SLIMBUS_2_RX"},
447         {"Slimbus3 Playback", NULL, "SLIMBUS_3_RX"},
448         {"Slimbus4 Playback", NULL, "SLIMBUS_4_RX"},
449         {"Slimbus5 Playback", NULL, "SLIMBUS_5_RX"},
450         {"Slimbus6 Playback", NULL, "SLIMBUS_6_RX"},
451
452         {"SLIMBUS_0_TX", NULL, "Slimbus Capture"},
453         {"SLIMBUS_1_TX", NULL, "Slimbus1 Capture"},
454         {"SLIMBUS_2_TX", NULL, "Slimbus2 Capture"},
455         {"SLIMBUS_3_TX", NULL, "Slimbus3 Capture"},
456         {"SLIMBUS_4_TX", NULL, "Slimbus4 Capture"},
457         {"SLIMBUS_5_TX", NULL, "Slimbus5 Capture"},
458         {"SLIMBUS_6_TX", NULL, "Slimbus6 Capture"},
459
460         {"Primary MI2S Playback", NULL, "PRI_MI2S_RX"},
461         {"Secondary MI2S Playback", NULL, "SEC_MI2S_RX"},
462         {"Tertiary MI2S Playback", NULL, "TERT_MI2S_RX"},
463         {"Quaternary MI2S Playback", NULL, "QUAT_MI2S_RX"},
464
465         {"Primary TDM0 Playback", NULL, "PRIMARY_TDM_RX_0"},
466         {"Primary TDM1 Playback", NULL, "PRIMARY_TDM_RX_1"},
467         {"Primary TDM2 Playback", NULL, "PRIMARY_TDM_RX_2"},
468         {"Primary TDM3 Playback", NULL, "PRIMARY_TDM_RX_3"},
469         {"Primary TDM4 Playback", NULL, "PRIMARY_TDM_RX_4"},
470         {"Primary TDM5 Playback", NULL, "PRIMARY_TDM_RX_5"},
471         {"Primary TDM6 Playback", NULL, "PRIMARY_TDM_RX_6"},
472         {"Primary TDM7 Playback", NULL, "PRIMARY_TDM_RX_7"},
473
474         {"Secondary TDM0 Playback", NULL, "SEC_TDM_RX_0"},
475         {"Secondary TDM1 Playback", NULL, "SEC_TDM_RX_1"},
476         {"Secondary TDM2 Playback", NULL, "SEC_TDM_RX_2"},
477         {"Secondary TDM3 Playback", NULL, "SEC_TDM_RX_3"},
478         {"Secondary TDM4 Playback", NULL, "SEC_TDM_RX_4"},
479         {"Secondary TDM5 Playback", NULL, "SEC_TDM_RX_5"},
480         {"Secondary TDM6 Playback", NULL, "SEC_TDM_RX_6"},
481         {"Secondary TDM7 Playback", NULL, "SEC_TDM_RX_7"},
482
483         {"Tertiary TDM0 Playback", NULL, "TERT_TDM_RX_0"},
484         {"Tertiary TDM1 Playback", NULL, "TERT_TDM_RX_1"},
485         {"Tertiary TDM2 Playback", NULL, "TERT_TDM_RX_2"},
486         {"Tertiary TDM3 Playback", NULL, "TERT_TDM_RX_3"},
487         {"Tertiary TDM4 Playback", NULL, "TERT_TDM_RX_4"},
488         {"Tertiary TDM5 Playback", NULL, "TERT_TDM_RX_5"},
489         {"Tertiary TDM6 Playback", NULL, "TERT_TDM_RX_6"},
490         {"Tertiary TDM7 Playback", NULL, "TERT_TDM_RX_7"},
491
492         {"Quaternary TDM0 Playback", NULL, "QUAT_TDM_RX_0"},
493         {"Quaternary TDM1 Playback", NULL, "QUAT_TDM_RX_1"},
494         {"Quaternary TDM2 Playback", NULL, "QUAT_TDM_RX_2"},
495         {"Quaternary TDM3 Playback", NULL, "QUAT_TDM_RX_3"},
496         {"Quaternary TDM4 Playback", NULL, "QUAT_TDM_RX_4"},
497         {"Quaternary TDM5 Playback", NULL, "QUAT_TDM_RX_5"},
498         {"Quaternary TDM6 Playback", NULL, "QUAT_TDM_RX_6"},
499         {"Quaternary TDM7 Playback", NULL, "QUAT_TDM_RX_7"},
500
501         {"Quinary TDM0 Playback", NULL, "QUIN_TDM_RX_0"},
502         {"Quinary TDM1 Playback", NULL, "QUIN_TDM_RX_1"},
503         {"Quinary TDM2 Playback", NULL, "QUIN_TDM_RX_2"},
504         {"Quinary TDM3 Playback", NULL, "QUIN_TDM_RX_3"},
505         {"Quinary TDM4 Playback", NULL, "QUIN_TDM_RX_4"},
506         {"Quinary TDM5 Playback", NULL, "QUIN_TDM_RX_5"},
507         {"Quinary TDM6 Playback", NULL, "QUIN_TDM_RX_6"},
508         {"Quinary TDM7 Playback", NULL, "QUIN_TDM_RX_7"},
509
510         {"PRIMARY_TDM_TX_0", NULL, "Primary TDM0 Capture"},
511         {"PRIMARY_TDM_TX_1", NULL, "Primary TDM1 Capture"},
512         {"PRIMARY_TDM_TX_2", NULL, "Primary TDM2 Capture"},
513         {"PRIMARY_TDM_TX_3", NULL, "Primary TDM3 Capture"},
514         {"PRIMARY_TDM_TX_4", NULL, "Primary TDM4 Capture"},
515         {"PRIMARY_TDM_TX_5", NULL, "Primary TDM5 Capture"},
516         {"PRIMARY_TDM_TX_6", NULL, "Primary TDM6 Capture"},
517         {"PRIMARY_TDM_TX_7", NULL, "Primary TDM7 Capture"},
518
519         {"SEC_TDM_TX_0", NULL, "Secondary TDM0 Capture"},
520         {"SEC_TDM_TX_1", NULL, "Secondary TDM1 Capture"},
521         {"SEC_TDM_TX_2", NULL, "Secondary TDM2 Capture"},
522         {"SEC_TDM_TX_3", NULL, "Secondary TDM3 Capture"},
523         {"SEC_TDM_TX_4", NULL, "Secondary TDM4 Capture"},
524         {"SEC_TDM_TX_5", NULL, "Secondary TDM5 Capture"},
525         {"SEC_TDM_TX_6", NULL, "Secondary TDM6 Capture"},
526         {"SEC_TDM_TX_7", NULL, "Secondary TDM7 Capture"},
527
528         {"TERT_TDM_TX_0", NULL, "Tertiary TDM0 Capture"},
529         {"TERT_TDM_TX_1", NULL, "Tertiary TDM1 Capture"},
530         {"TERT_TDM_TX_2", NULL, "Tertiary TDM2 Capture"},
531         {"TERT_TDM_TX_3", NULL, "Tertiary TDM3 Capture"},
532         {"TERT_TDM_TX_4", NULL, "Tertiary TDM4 Capture"},
533         {"TERT_TDM_TX_5", NULL, "Tertiary TDM5 Capture"},
534         {"TERT_TDM_TX_6", NULL, "Tertiary TDM6 Capture"},
535         {"TERT_TDM_TX_7", NULL, "Tertiary TDM7 Capture"},
536
537         {"QUAT_TDM_TX_0", NULL, "Quaternary TDM0 Capture"},
538         {"QUAT_TDM_TX_1", NULL, "Quaternary TDM1 Capture"},
539         {"QUAT_TDM_TX_2", NULL, "Quaternary TDM2 Capture"},
540         {"QUAT_TDM_TX_3", NULL, "Quaternary TDM3 Capture"},
541         {"QUAT_TDM_TX_4", NULL, "Quaternary TDM4 Capture"},
542         {"QUAT_TDM_TX_5", NULL, "Quaternary TDM5 Capture"},
543         {"QUAT_TDM_TX_6", NULL, "Quaternary TDM6 Capture"},
544         {"QUAT_TDM_TX_7", NULL, "Quaternary TDM7 Capture"},
545
546         {"QUIN_TDM_TX_0", NULL, "Quinary TDM0 Capture"},
547         {"QUIN_TDM_TX_1", NULL, "Quinary TDM1 Capture"},
548         {"QUIN_TDM_TX_2", NULL, "Quinary TDM2 Capture"},
549         {"QUIN_TDM_TX_3", NULL, "Quinary TDM3 Capture"},
550         {"QUIN_TDM_TX_4", NULL, "Quinary TDM4 Capture"},
551         {"QUIN_TDM_TX_5", NULL, "Quinary TDM5 Capture"},
552         {"QUIN_TDM_TX_6", NULL, "Quinary TDM6 Capture"},
553         {"QUIN_TDM_TX_7", NULL, "Quinary TDM7 Capture"},
554
555         {"TERT_MI2S_TX", NULL, "Tertiary MI2S Capture"},
556         {"PRI_MI2S_TX", NULL, "Primary MI2S Capture"},
557         {"SEC_MI2S_TX", NULL, "Secondary MI2S Capture"},
558         {"QUAT_MI2S_TX", NULL, "Quaternary MI2S Capture"},
559 };
560
561 static struct snd_soc_dai_ops q6hdmi_ops = {
562         .prepare        = q6afe_dai_prepare,
563         .hw_params      = q6hdmi_hw_params,
564         .shutdown       = q6afe_dai_shutdown,
565 };
566
567 static struct snd_soc_dai_ops q6i2s_ops = {
568         .prepare        = q6afe_dai_prepare,
569         .hw_params      = q6i2s_hw_params,
570         .set_fmt        = q6i2s_set_fmt,
571         .shutdown       = q6afe_dai_shutdown,
572         .set_sysclk     = q6afe_mi2s_set_sysclk,
573 };
574
575 static struct snd_soc_dai_ops q6slim_ops = {
576         .prepare        = q6afe_dai_prepare,
577         .hw_params      = q6slim_hw_params,
578         .shutdown       = q6afe_dai_shutdown,
579         .set_channel_map = q6slim_set_channel_map,
580 };
581
582 static struct snd_soc_dai_ops q6tdm_ops = {
583         .prepare        = q6afe_dai_prepare,
584         .shutdown       = q6afe_dai_shutdown,
585         .set_sysclk     = q6afe_mi2s_set_sysclk,
586         .set_tdm_slot     = q6tdm_set_tdm_slot,
587         .set_channel_map  = q6tdm_set_channel_map,
588         .hw_params        = q6tdm_hw_params,
589 };
590
591 static int msm_dai_q6_dai_probe(struct snd_soc_dai *dai)
592 {
593         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
594         struct q6afe_port *port;
595
596         port = q6afe_port_get_from_id(dai->dev, dai->id);
597         if (IS_ERR(port)) {
598                 dev_err(dai->dev, "Unable to get afe port\n");
599                 return -EINVAL;
600         }
601         dai_data->port[dai->id] = port;
602
603         return 0;
604 }
605
606 static int msm_dai_q6_dai_remove(struct snd_soc_dai *dai)
607 {
608         struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
609
610         q6afe_port_put(dai_data->port[dai->id]);
611         dai_data->port[dai->id] = NULL;
612
613         return 0;
614 }
615
616 static struct snd_soc_dai_driver q6afe_dais[] = {
617         {
618                 .playback = {
619                         .stream_name = "HDMI Playback",
620                         .rates = SNDRV_PCM_RATE_48000 |
621                                  SNDRV_PCM_RATE_96000 |
622                                  SNDRV_PCM_RATE_192000,
623                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
624                                    SNDRV_PCM_FMTBIT_S24_LE,
625                         .channels_min = 2,
626                         .channels_max = 8,
627                         .rate_max =     192000,
628                         .rate_min =     48000,
629                 },
630                 .ops = &q6hdmi_ops,
631                 .id = HDMI_RX,
632                 .name = "HDMI",
633                 .probe = msm_dai_q6_dai_probe,
634                 .remove = msm_dai_q6_dai_remove,
635         }, {
636                 .name = "SLIMBUS_0_RX",
637                 .ops = &q6slim_ops,
638                 .id = SLIMBUS_0_RX,
639                 .probe = msm_dai_q6_dai_probe,
640                 .remove = msm_dai_q6_dai_remove,
641                 .playback = {
642                         .stream_name = "Slimbus Playback",
643                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
644                                  SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
645                                  SNDRV_PCM_RATE_192000,
646                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
647                                    SNDRV_PCM_FMTBIT_S24_LE,
648                         .channels_min = 1,
649                         .channels_max = 8,
650                         .rate_min = 8000,
651                         .rate_max = 192000,
652                 },
653         }, {
654                 .name = "SLIMBUS_0_TX",
655                 .ops = &q6slim_ops,
656                 .id = SLIMBUS_0_TX,
657                 .probe = msm_dai_q6_dai_probe,
658                 .remove = msm_dai_q6_dai_remove,
659                 .capture = {
660                         .stream_name = "Slimbus Capture",
661                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
662                                  SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
663                                  SNDRV_PCM_RATE_192000,
664                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
665                                    SNDRV_PCM_FMTBIT_S24_LE,
666                         .channels_min = 1,
667                         .channels_max = 8,
668                         .rate_min = 8000,
669                         .rate_max = 192000,
670                 },
671         }, {
672                 .playback = {
673                         .stream_name = "Slimbus1 Playback",
674                         .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
675                                  SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
676                                  SNDRV_PCM_RATE_192000,
677                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
678                                    SNDRV_PCM_FMTBIT_S24_LE,
679                         .channels_min = 1,
680                         .channels_max = 2,
681                         .rate_min = 8000,
682                         .rate_max = 192000,
683                 },
684                 .name = "SLIMBUS_1_RX",
685                 .ops = &q6slim_ops,
686                 .id = SLIMBUS_1_RX,
687                 .probe = msm_dai_q6_dai_probe,
688                 .remove = msm_dai_q6_dai_remove,
689         }, {
690                 .name = "SLIMBUS_1_TX",
691                 .ops = &q6slim_ops,
692                 .id = SLIMBUS_1_TX,
693                 .probe = msm_dai_q6_dai_probe,
694                 .remove = msm_dai_q6_dai_remove,
695                 .capture = {
696                         .stream_name = "Slimbus1 Capture",
697                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
698                                  SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
699                                  SNDRV_PCM_RATE_192000,
700                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
701                                    SNDRV_PCM_FMTBIT_S24_LE,
702                         .channels_min = 1,
703                         .channels_max = 8,
704                         .rate_min = 8000,
705                         .rate_max = 192000,
706                 },
707         }, {
708                 .playback = {
709                         .stream_name = "Slimbus2 Playback",
710                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
711                                  SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
712                                  SNDRV_PCM_RATE_192000,
713                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
714                                    SNDRV_PCM_FMTBIT_S24_LE,
715                         .channels_min = 1,
716                         .channels_max = 8,
717                         .rate_min = 8000,
718                         .rate_max = 192000,
719                 },
720                 .name = "SLIMBUS_2_RX",
721                 .ops = &q6slim_ops,
722                 .id = SLIMBUS_2_RX,
723                 .probe = msm_dai_q6_dai_probe,
724                 .remove = msm_dai_q6_dai_remove,
725
726         }, {
727                 .name = "SLIMBUS_2_TX",
728                 .ops = &q6slim_ops,
729                 .id = SLIMBUS_2_TX,
730                 .probe = msm_dai_q6_dai_probe,
731                 .remove = msm_dai_q6_dai_remove,
732                 .capture = {
733                         .stream_name = "Slimbus2 Capture",
734                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
735                                  SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
736                                  SNDRV_PCM_RATE_192000,
737                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
738                                    SNDRV_PCM_FMTBIT_S24_LE,
739                         .channels_min = 1,
740                         .channels_max = 8,
741                         .rate_min = 8000,
742                         .rate_max = 192000,
743                 },
744         }, {
745                 .playback = {
746                         .stream_name = "Slimbus3 Playback",
747                         .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
748                                  SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
749                                  SNDRV_PCM_RATE_192000,
750                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
751                                    SNDRV_PCM_FMTBIT_S24_LE,
752                         .channels_min = 1,
753                         .channels_max = 2,
754                         .rate_min = 8000,
755                         .rate_max = 192000,
756                 },
757                 .name = "SLIMBUS_3_RX",
758                 .ops = &q6slim_ops,
759                 .id = SLIMBUS_3_RX,
760                 .probe = msm_dai_q6_dai_probe,
761                 .remove = msm_dai_q6_dai_remove,
762
763         }, {
764                 .name = "SLIMBUS_3_TX",
765                 .ops = &q6slim_ops,
766                 .id = SLIMBUS_3_TX,
767                 .probe = msm_dai_q6_dai_probe,
768                 .remove = msm_dai_q6_dai_remove,
769                 .capture = {
770                         .stream_name = "Slimbus3 Capture",
771                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
772                                  SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
773                                  SNDRV_PCM_RATE_192000,
774                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
775                                    SNDRV_PCM_FMTBIT_S24_LE,
776                         .channels_min = 1,
777                         .channels_max = 8,
778                         .rate_min = 8000,
779                         .rate_max = 192000,
780                 },
781         }, {
782                 .playback = {
783                         .stream_name = "Slimbus4 Playback",
784                         .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
785                                  SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
786                                  SNDRV_PCM_RATE_192000,
787                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
788                                    SNDRV_PCM_FMTBIT_S24_LE,
789                         .channels_min = 1,
790                         .channels_max = 2,
791                         .rate_min = 8000,
792                         .rate_max = 192000,
793                 },
794                 .name = "SLIMBUS_4_RX",
795                 .ops = &q6slim_ops,
796                 .id = SLIMBUS_4_RX,
797                 .probe = msm_dai_q6_dai_probe,
798                 .remove = msm_dai_q6_dai_remove,
799
800         }, {
801                 .name = "SLIMBUS_4_TX",
802                 .ops = &q6slim_ops,
803                 .id = SLIMBUS_4_TX,
804                 .probe = msm_dai_q6_dai_probe,
805                 .remove = msm_dai_q6_dai_remove,
806                 .capture = {
807                         .stream_name = "Slimbus4 Capture",
808                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
809                                  SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
810                                  SNDRV_PCM_RATE_192000,
811                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
812                                    SNDRV_PCM_FMTBIT_S24_LE,
813                         .channels_min = 1,
814                         .channels_max = 8,
815                         .rate_min = 8000,
816                         .rate_max = 192000,
817                 },
818         }, {
819                 .playback = {
820                         .stream_name = "Slimbus5 Playback",
821                         .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
822                                  SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
823                                  SNDRV_PCM_RATE_192000,
824                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
825                                    SNDRV_PCM_FMTBIT_S24_LE,
826                         .channels_min = 1,
827                         .channels_max = 2,
828                         .rate_min = 8000,
829                         .rate_max = 192000,
830                 },
831                 .name = "SLIMBUS_5_RX",
832                 .ops = &q6slim_ops,
833                 .id = SLIMBUS_5_RX,
834                 .probe = msm_dai_q6_dai_probe,
835                 .remove = msm_dai_q6_dai_remove,
836
837         }, {
838                 .name = "SLIMBUS_5_TX",
839                 .ops = &q6slim_ops,
840                 .id = SLIMBUS_5_TX,
841                 .probe = msm_dai_q6_dai_probe,
842                 .remove = msm_dai_q6_dai_remove,
843                 .capture = {
844                         .stream_name = "Slimbus5 Capture",
845                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
846                                  SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
847                                  SNDRV_PCM_RATE_192000,
848                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
849                                    SNDRV_PCM_FMTBIT_S24_LE,
850                         .channels_min = 1,
851                         .channels_max = 8,
852                         .rate_min = 8000,
853                         .rate_max = 192000,
854                 },
855         }, {
856                 .playback = {
857                         .stream_name = "Slimbus6 Playback",
858                         .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
859                                  SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
860                                  SNDRV_PCM_RATE_192000,
861                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
862                                    SNDRV_PCM_FMTBIT_S24_LE,
863                         .channels_min = 1,
864                         .channels_max = 2,
865                         .rate_min = 8000,
866                         .rate_max = 192000,
867                 },
868                 .ops = &q6slim_ops,
869                 .name = "SLIMBUS_6_RX",
870                 .id = SLIMBUS_6_RX,
871                 .probe = msm_dai_q6_dai_probe,
872                 .remove = msm_dai_q6_dai_remove,
873
874         }, {
875                 .name = "SLIMBUS_6_TX",
876                 .ops = &q6slim_ops,
877                 .id = SLIMBUS_6_TX,
878                 .probe = msm_dai_q6_dai_probe,
879                 .remove = msm_dai_q6_dai_remove,
880                 .capture = {
881                         .stream_name = "Slimbus6 Capture",
882                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
883                                  SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
884                                  SNDRV_PCM_RATE_192000,
885                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
886                                    SNDRV_PCM_FMTBIT_S24_LE,
887                         .channels_min = 1,
888                         .channels_max = 8,
889                         .rate_min = 8000,
890                         .rate_max = 192000,
891                 },
892         }, {
893                 .playback = {
894                         .stream_name = "Primary MI2S Playback",
895                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
896                                  SNDRV_PCM_RATE_16000,
897                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
898                                    SNDRV_PCM_FMTBIT_S24_LE,
899                         .rate_min =     8000,
900                         .rate_max =     48000,
901                 },
902                 .id = PRIMARY_MI2S_RX,
903                 .name = "PRI_MI2S_RX",
904                 .ops = &q6i2s_ops,
905                 .probe = msm_dai_q6_dai_probe,
906                 .remove = msm_dai_q6_dai_remove,
907         }, {
908                 .capture = {
909                         .stream_name = "Primary MI2S Capture",
910                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
911                                  SNDRV_PCM_RATE_16000,
912                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
913                                    SNDRV_PCM_FMTBIT_S24_LE,
914                         .rate_min =     8000,
915                         .rate_max =     48000,
916                 },
917                 .id = PRIMARY_MI2S_TX,
918                 .name = "PRI_MI2S_TX",
919                 .ops = &q6i2s_ops,
920                 .probe = msm_dai_q6_dai_probe,
921                 .remove = msm_dai_q6_dai_remove,
922         }, {
923                 .playback = {
924                         .stream_name = "Secondary MI2S Playback",
925                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
926                                  SNDRV_PCM_RATE_16000,
927                         .formats = SNDRV_PCM_FMTBIT_S16_LE,
928                         .rate_min =     8000,
929                         .rate_max =     48000,
930                 },
931                 .name = "SEC_MI2S_RX",
932                 .id = SECONDARY_MI2S_RX,
933                 .ops = &q6i2s_ops,
934                 .probe = msm_dai_q6_dai_probe,
935                 .remove = msm_dai_q6_dai_remove,
936         }, {
937                 .capture = {
938                         .stream_name = "Secondary MI2S Capture",
939                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
940                                  SNDRV_PCM_RATE_16000,
941                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
942                                    SNDRV_PCM_FMTBIT_S24_LE,
943                         .rate_min =     8000,
944                         .rate_max =     48000,
945                 },
946                 .id = SECONDARY_MI2S_TX,
947                 .name = "SEC_MI2S_TX",
948                 .ops = &q6i2s_ops,
949                 .probe = msm_dai_q6_dai_probe,
950                 .remove = msm_dai_q6_dai_remove,
951         }, {
952                 .playback = {
953                         .stream_name = "Tertiary MI2S Playback",
954                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
955                                  SNDRV_PCM_RATE_16000,
956                         .formats = SNDRV_PCM_FMTBIT_S16_LE,
957                         .rate_min =     8000,
958                         .rate_max =     48000,
959                 },
960                 .name = "TERT_MI2S_RX",
961                 .id = TERTIARY_MI2S_RX,
962                 .ops = &q6i2s_ops,
963                 .probe = msm_dai_q6_dai_probe,
964                 .remove = msm_dai_q6_dai_remove,
965         }, {
966                 .capture = {
967                         .stream_name = "Tertiary MI2S Capture",
968                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
969                                  SNDRV_PCM_RATE_16000,
970                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
971                                    SNDRV_PCM_FMTBIT_S24_LE,
972                         .rate_min =     8000,
973                         .rate_max =     48000,
974                 },
975                 .id = TERTIARY_MI2S_TX,
976                 .name = "TERT_MI2S_TX",
977                 .ops = &q6i2s_ops,
978                 .probe = msm_dai_q6_dai_probe,
979                 .remove = msm_dai_q6_dai_remove,
980         }, {
981                 .playback = {
982                         .stream_name = "Quaternary MI2S Playback",
983                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
984                                  SNDRV_PCM_RATE_16000,
985                         .formats = SNDRV_PCM_FMTBIT_S16_LE,
986                         .rate_min =     8000,
987                         .rate_max =     48000,
988                 },
989                 .name = "QUAT_MI2S_RX",
990                 .id = QUATERNARY_MI2S_RX,
991                 .ops = &q6i2s_ops,
992                 .probe = msm_dai_q6_dai_probe,
993                 .remove = msm_dai_q6_dai_remove,
994         }, {
995                 .capture = {
996                         .stream_name = "Quaternary MI2S Capture",
997                         .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
998                                  SNDRV_PCM_RATE_16000,
999                         .formats = SNDRV_PCM_FMTBIT_S16_LE |
1000                                    SNDRV_PCM_FMTBIT_S24_LE,
1001                         .rate_min =     8000,
1002                         .rate_max =     48000,
1003                 },
1004                 .id = QUATERNARY_MI2S_TX,
1005                 .name = "QUAT_MI2S_TX",
1006                 .ops = &q6i2s_ops,
1007                 .probe = msm_dai_q6_dai_probe,
1008                 .remove = msm_dai_q6_dai_remove,
1009         },
1010         Q6AFE_TDM_PB_DAI("Primary", 0, PRIMARY_TDM_RX_0),
1011         Q6AFE_TDM_PB_DAI("Primary", 1, PRIMARY_TDM_RX_1),
1012         Q6AFE_TDM_PB_DAI("Primary", 2, PRIMARY_TDM_RX_2),
1013         Q6AFE_TDM_PB_DAI("Primary", 3, PRIMARY_TDM_RX_3),
1014         Q6AFE_TDM_PB_DAI("Primary", 4, PRIMARY_TDM_RX_4),
1015         Q6AFE_TDM_PB_DAI("Primary", 5, PRIMARY_TDM_RX_5),
1016         Q6AFE_TDM_PB_DAI("Primary", 6, PRIMARY_TDM_RX_6),
1017         Q6AFE_TDM_PB_DAI("Primary", 7, PRIMARY_TDM_RX_7),
1018         Q6AFE_TDM_CAP_DAI("Primary", 0, PRIMARY_TDM_TX_0),
1019         Q6AFE_TDM_CAP_DAI("Primary", 1, PRIMARY_TDM_TX_1),
1020         Q6AFE_TDM_CAP_DAI("Primary", 2, PRIMARY_TDM_TX_2),
1021         Q6AFE_TDM_CAP_DAI("Primary", 3, PRIMARY_TDM_TX_3),
1022         Q6AFE_TDM_CAP_DAI("Primary", 4, PRIMARY_TDM_TX_4),
1023         Q6AFE_TDM_CAP_DAI("Primary", 5, PRIMARY_TDM_TX_5),
1024         Q6AFE_TDM_CAP_DAI("Primary", 6, PRIMARY_TDM_TX_6),
1025         Q6AFE_TDM_CAP_DAI("Primary", 7, PRIMARY_TDM_TX_7),
1026         Q6AFE_TDM_PB_DAI("Secondary", 0, SECONDARY_TDM_RX_0),
1027         Q6AFE_TDM_PB_DAI("Secondary", 1, SECONDARY_TDM_RX_1),
1028         Q6AFE_TDM_PB_DAI("Secondary", 2, SECONDARY_TDM_RX_2),
1029         Q6AFE_TDM_PB_DAI("Secondary", 3, SECONDARY_TDM_RX_3),
1030         Q6AFE_TDM_PB_DAI("Secondary", 4, SECONDARY_TDM_RX_4),
1031         Q6AFE_TDM_PB_DAI("Secondary", 5, SECONDARY_TDM_RX_5),
1032         Q6AFE_TDM_PB_DAI("Secondary", 6, SECONDARY_TDM_RX_6),
1033         Q6AFE_TDM_PB_DAI("Secondary", 7, SECONDARY_TDM_RX_7),
1034         Q6AFE_TDM_CAP_DAI("Secondary", 0, SECONDARY_TDM_TX_0),
1035         Q6AFE_TDM_CAP_DAI("Secondary", 1, SECONDARY_TDM_TX_1),
1036         Q6AFE_TDM_CAP_DAI("Secondary", 2, SECONDARY_TDM_TX_2),
1037         Q6AFE_TDM_CAP_DAI("Secondary", 3, SECONDARY_TDM_TX_3),
1038         Q6AFE_TDM_CAP_DAI("Secondary", 4, SECONDARY_TDM_TX_4),
1039         Q6AFE_TDM_CAP_DAI("Secondary", 5, SECONDARY_TDM_TX_5),
1040         Q6AFE_TDM_CAP_DAI("Secondary", 6, SECONDARY_TDM_TX_6),
1041         Q6AFE_TDM_CAP_DAI("Secondary", 7, SECONDARY_TDM_TX_7),
1042         Q6AFE_TDM_PB_DAI("Tertiary", 0, TERTIARY_TDM_RX_0),
1043         Q6AFE_TDM_PB_DAI("Tertiary", 1, TERTIARY_TDM_RX_1),
1044         Q6AFE_TDM_PB_DAI("Tertiary", 2, TERTIARY_TDM_RX_2),
1045         Q6AFE_TDM_PB_DAI("Tertiary", 3, TERTIARY_TDM_RX_3),
1046         Q6AFE_TDM_PB_DAI("Tertiary", 4, TERTIARY_TDM_RX_4),
1047         Q6AFE_TDM_PB_DAI("Tertiary", 5, TERTIARY_TDM_RX_5),
1048         Q6AFE_TDM_PB_DAI("Tertiary", 6, TERTIARY_TDM_RX_6),
1049         Q6AFE_TDM_PB_DAI("Tertiary", 7, TERTIARY_TDM_RX_7),
1050         Q6AFE_TDM_CAP_DAI("Tertiary", 0, TERTIARY_TDM_TX_0),
1051         Q6AFE_TDM_CAP_DAI("Tertiary", 1, TERTIARY_TDM_TX_1),
1052         Q6AFE_TDM_CAP_DAI("Tertiary", 2, TERTIARY_TDM_TX_2),
1053         Q6AFE_TDM_CAP_DAI("Tertiary", 3, TERTIARY_TDM_TX_3),
1054         Q6AFE_TDM_CAP_DAI("Tertiary", 4, TERTIARY_TDM_TX_4),
1055         Q6AFE_TDM_CAP_DAI("Tertiary", 5, TERTIARY_TDM_TX_5),
1056         Q6AFE_TDM_CAP_DAI("Tertiary", 6, TERTIARY_TDM_TX_6),
1057         Q6AFE_TDM_CAP_DAI("Tertiary", 7, TERTIARY_TDM_TX_7),
1058         Q6AFE_TDM_PB_DAI("Quaternary", 0, QUATERNARY_TDM_RX_0),
1059         Q6AFE_TDM_PB_DAI("Quaternary", 1, QUATERNARY_TDM_RX_1),
1060         Q6AFE_TDM_PB_DAI("Quaternary", 2, QUATERNARY_TDM_RX_2),
1061         Q6AFE_TDM_PB_DAI("Quaternary", 3, QUATERNARY_TDM_RX_3),
1062         Q6AFE_TDM_PB_DAI("Quaternary", 4, QUATERNARY_TDM_RX_4),
1063         Q6AFE_TDM_PB_DAI("Quaternary", 5, QUATERNARY_TDM_RX_5),
1064         Q6AFE_TDM_PB_DAI("Quaternary", 6, QUATERNARY_TDM_RX_6),
1065         Q6AFE_TDM_PB_DAI("Quaternary", 7, QUATERNARY_TDM_RX_7),
1066         Q6AFE_TDM_CAP_DAI("Quaternary", 0, QUATERNARY_TDM_TX_0),
1067         Q6AFE_TDM_CAP_DAI("Quaternary", 1, QUATERNARY_TDM_TX_1),
1068         Q6AFE_TDM_CAP_DAI("Quaternary", 2, QUATERNARY_TDM_TX_2),
1069         Q6AFE_TDM_CAP_DAI("Quaternary", 3, QUATERNARY_TDM_TX_3),
1070         Q6AFE_TDM_CAP_DAI("Quaternary", 4, QUATERNARY_TDM_TX_4),
1071         Q6AFE_TDM_CAP_DAI("Quaternary", 5, QUATERNARY_TDM_TX_5),
1072         Q6AFE_TDM_CAP_DAI("Quaternary", 6, QUATERNARY_TDM_TX_6),
1073         Q6AFE_TDM_CAP_DAI("Quaternary", 7, QUATERNARY_TDM_TX_7),
1074         Q6AFE_TDM_PB_DAI("Quinary", 0, QUINARY_TDM_RX_0),
1075         Q6AFE_TDM_PB_DAI("Quinary", 1, QUINARY_TDM_RX_1),
1076         Q6AFE_TDM_PB_DAI("Quinary", 2, QUINARY_TDM_RX_2),
1077         Q6AFE_TDM_PB_DAI("Quinary", 3, QUINARY_TDM_RX_3),
1078         Q6AFE_TDM_PB_DAI("Quinary", 4, QUINARY_TDM_RX_4),
1079         Q6AFE_TDM_PB_DAI("Quinary", 5, QUINARY_TDM_RX_5),
1080         Q6AFE_TDM_PB_DAI("Quinary", 6, QUINARY_TDM_RX_6),
1081         Q6AFE_TDM_PB_DAI("Quinary", 7, QUINARY_TDM_RX_7),
1082         Q6AFE_TDM_CAP_DAI("Quinary", 0, QUINARY_TDM_TX_0),
1083         Q6AFE_TDM_CAP_DAI("Quinary", 1, QUINARY_TDM_TX_1),
1084         Q6AFE_TDM_CAP_DAI("Quinary", 2, QUINARY_TDM_TX_2),
1085         Q6AFE_TDM_CAP_DAI("Quinary", 3, QUINARY_TDM_TX_3),
1086         Q6AFE_TDM_CAP_DAI("Quinary", 4, QUINARY_TDM_TX_4),
1087         Q6AFE_TDM_CAP_DAI("Quinary", 5, QUINARY_TDM_TX_5),
1088         Q6AFE_TDM_CAP_DAI("Quinary", 6, QUINARY_TDM_TX_6),
1089         Q6AFE_TDM_CAP_DAI("Quinary", 7, QUINARY_TDM_TX_7),
1090 };
1091
1092 static int q6afe_of_xlate_dai_name(struct snd_soc_component *component,
1093                                    struct of_phandle_args *args,
1094                                    const char **dai_name)
1095 {
1096         int id = args->args[0];
1097         int ret = -EINVAL;
1098         int i;
1099
1100         for (i = 0; i  < ARRAY_SIZE(q6afe_dais); i++) {
1101                 if (q6afe_dais[i].id == id) {
1102                         *dai_name = q6afe_dais[i].name;
1103                         ret = 0;
1104                         break;
1105                 }
1106         }
1107
1108         return ret;
1109 }
1110
1111 static const struct snd_soc_dapm_widget q6afe_dai_widgets[] = {
1112         SND_SOC_DAPM_AIF_OUT("HDMI_RX", "HDMI Playback", 0, 0, 0, 0),
1113         SND_SOC_DAPM_AIF_OUT("SLIMBUS_0_RX", "Slimbus Playback", 0, 0, 0, 0),
1114         SND_SOC_DAPM_AIF_OUT("SLIMBUS_1_RX", "Slimbus1 Playback", 0, 0, 0, 0),
1115         SND_SOC_DAPM_AIF_OUT("SLIMBUS_2_RX", "Slimbus2 Playback", 0, 0, 0, 0),
1116         SND_SOC_DAPM_AIF_OUT("SLIMBUS_3_RX", "Slimbus3 Playback", 0, 0, 0, 0),
1117         SND_SOC_DAPM_AIF_OUT("SLIMBUS_4_RX", "Slimbus4 Playback", 0, 0, 0, 0),
1118         SND_SOC_DAPM_AIF_OUT("SLIMBUS_5_RX", "Slimbus5 Playback", 0, 0, 0, 0),
1119         SND_SOC_DAPM_AIF_OUT("SLIMBUS_6_RX", "Slimbus6 Playback", 0, 0, 0, 0),
1120         SND_SOC_DAPM_AIF_IN("SLIMBUS_0_TX", "Slimbus Capture", 0, 0, 0, 0),
1121         SND_SOC_DAPM_AIF_IN("SLIMBUS_1_TX", "Slimbus1 Capture", 0, 0, 0, 0),
1122         SND_SOC_DAPM_AIF_IN("SLIMBUS_2_TX", "Slimbus2 Capture", 0, 0, 0, 0),
1123         SND_SOC_DAPM_AIF_IN("SLIMBUS_3_TX", "Slimbus3 Capture", 0, 0, 0, 0),
1124         SND_SOC_DAPM_AIF_IN("SLIMBUS_4_TX", "Slimbus4 Capture", 0, 0, 0, 0),
1125         SND_SOC_DAPM_AIF_IN("SLIMBUS_5_TX", "Slimbus5 Capture", 0, 0, 0, 0),
1126         SND_SOC_DAPM_AIF_IN("SLIMBUS_6_TX", "Slimbus6 Capture", 0, 0, 0, 0),
1127         SND_SOC_DAPM_AIF_OUT("QUAT_MI2S_RX", "Quaternary MI2S Playback",
1128                                                 0, 0, 0, 0),
1129         SND_SOC_DAPM_AIF_IN("QUAT_MI2S_TX", "Quaternary MI2S Capture",
1130                                                 0, 0, 0, 0),
1131         SND_SOC_DAPM_AIF_OUT("TERT_MI2S_RX", "Tertiary MI2S Playback",
1132                                                 0, 0, 0, 0),
1133         SND_SOC_DAPM_AIF_IN("TERT_MI2S_TX", "Tertiary MI2S Capture",
1134                                                 0, 0, 0, 0),
1135         SND_SOC_DAPM_AIF_OUT("SEC_MI2S_RX", "Secondary MI2S Playback",
1136                              0, 0, 0, 0),
1137         SND_SOC_DAPM_AIF_IN("SEC_MI2S_TX", "Secondary MI2S Capture",
1138                                                 0, 0, 0, 0),
1139         SND_SOC_DAPM_AIF_OUT("SEC_MI2S_RX_SD1",
1140                         "Secondary MI2S Playback SD1",
1141                         0, 0, 0, 0),
1142         SND_SOC_DAPM_AIF_OUT("PRI_MI2S_RX", "Primary MI2S Playback",
1143                              0, 0, 0, 0),
1144         SND_SOC_DAPM_AIF_IN("PRI_MI2S_TX", "Primary MI2S Capture",
1145                                                 0, 0, 0, 0),
1146
1147         SND_SOC_DAPM_AIF_OUT("PRIMARY_TDM_RX_0", "Primary TDM0 Playback",
1148                              0, 0, 0, 0),
1149         SND_SOC_DAPM_AIF_OUT("PRIMARY_TDM_RX_1", "Primary TDM1 Playback",
1150                              0, 0, 0, 0),
1151         SND_SOC_DAPM_AIF_OUT("PRIMARY_TDM_RX_2", "Primary TDM2 Playback",
1152                              0, 0, 0, 0),
1153         SND_SOC_DAPM_AIF_OUT("PRIMARY_TDM_RX_3", "Primary TDM3 Playback",
1154                              0, 0, 0, 0),
1155         SND_SOC_DAPM_AIF_OUT("PRIMARY_TDM_RX_4", "Primary TDM4 Playback",
1156                              0, 0, 0, 0),
1157         SND_SOC_DAPM_AIF_OUT("PRIMARY_TDM_RX_5", "Primary TDM5 Playback",
1158                              0, 0, 0, 0),
1159         SND_SOC_DAPM_AIF_OUT("PRIMARY_TDM_RX_6", "Primary TDM6 Playback",
1160                              0, 0, 0, 0),
1161         SND_SOC_DAPM_AIF_OUT("PRIMARY_TDM_RX_7", "Primary TDM7 Playback",
1162                              0, 0, 0, 0),
1163         SND_SOC_DAPM_AIF_IN("PRIMARY_TDM_TX_0", "Primary TDM0 Capture",
1164                                                 0, 0, 0, 0),
1165         SND_SOC_DAPM_AIF_IN("PRIMARY_TDM_TX_1", "Primary TDM1 Capture",
1166                                                 0, 0, 0, 0),
1167         SND_SOC_DAPM_AIF_IN("PRIMARY_TDM_TX_2", "Primary TDM2 Capture",
1168                                                 0, 0, 0, 0),
1169         SND_SOC_DAPM_AIF_IN("PRIMARY_TDM_TX_3", "Primary TDM3 Capture",
1170                                                 0, 0, 0, 0),
1171         SND_SOC_DAPM_AIF_IN("PRIMARY_TDM_TX_4", "Primary TDM4 Capture",
1172                                                 0, 0, 0, 0),
1173         SND_SOC_DAPM_AIF_IN("PRIMARY_TDM_TX_5", "Primary TDM5 Capture",
1174                                                 0, 0, 0, 0),
1175         SND_SOC_DAPM_AIF_IN("PRIMARY_TDM_TX_6", "Primary TDM6 Capture",
1176                                                 0, 0, 0, 0),
1177         SND_SOC_DAPM_AIF_IN("PRIMARY_TDM_TX_7", "Primary TDM7 Capture",
1178                                                 0, 0, 0, 0),
1179
1180         SND_SOC_DAPM_AIF_OUT("SEC_TDM_RX_0", "Secondary TDM0 Playback",
1181                              0, 0, 0, 0),
1182         SND_SOC_DAPM_AIF_OUT("SEC_TDM_RX_1", "Secondary TDM1 Playback",
1183                              0, 0, 0, 0),
1184         SND_SOC_DAPM_AIF_OUT("SEC_TDM_RX_2", "Secondary TDM2 Playback",
1185                              0, 0, 0, 0),
1186         SND_SOC_DAPM_AIF_OUT("SEC_TDM_RX_3", "Secondary TDM3 Playback",
1187                              0, 0, 0, 0),
1188         SND_SOC_DAPM_AIF_OUT("SEC_TDM_RX_4", "Secondary TDM4 Playback",
1189                              0, 0, 0, 0),
1190         SND_SOC_DAPM_AIF_OUT("SEC_TDM_RX_5", "Secondary TDM5 Playback",
1191                              0, 0, 0, 0),
1192         SND_SOC_DAPM_AIF_OUT("SEC_TDM_RX_6", "Secondary TDM6 Playback",
1193                              0, 0, 0, 0),
1194         SND_SOC_DAPM_AIF_OUT("SEC_TDM_RX_7", "Secondary TDM7 Playback",
1195                              0, 0, 0, 0),
1196         SND_SOC_DAPM_AIF_IN("SEC_TDM_TX_0", "Secondary TDM0 Capture",
1197                                                 0, 0, 0, 0),
1198         SND_SOC_DAPM_AIF_IN("SEC_TDM_TX_1", "Secondary TDM1 Capture",
1199                                                 0, 0, 0, 0),
1200         SND_SOC_DAPM_AIF_IN("SEC_TDM_TX_2", "Secondary TDM2 Capture",
1201                                                 0, 0, 0, 0),
1202         SND_SOC_DAPM_AIF_IN("SEC_TDM_TX_3", "Secondary TDM3 Capture",
1203                                                 0, 0, 0, 0),
1204         SND_SOC_DAPM_AIF_IN("SEC_TDM_TX_4", "Secondary TDM4 Capture",
1205                                                 0, 0, 0, 0),
1206         SND_SOC_DAPM_AIF_IN("SEC_TDM_TX_5", "Secondary TDM5 Capture",
1207                                                 0, 0, 0, 0),
1208         SND_SOC_DAPM_AIF_IN("SEC_TDM_TX_6", "Secondary TDM6 Capture",
1209                                                 0, 0, 0, 0),
1210         SND_SOC_DAPM_AIF_IN("SEC_TDM_TX_7", "Secondary TDM7 Capture",
1211                                                 0, 0, 0, 0),
1212
1213         SND_SOC_DAPM_AIF_OUT("TERT_TDM_RX_0", "Tertiary TDM0 Playback",
1214                              0, 0, 0, 0),
1215         SND_SOC_DAPM_AIF_OUT("TERT_TDM_RX_1", "Tertiary TDM1 Playback",
1216                              0, 0, 0, 0),
1217         SND_SOC_DAPM_AIF_OUT("TERT_TDM_RX_2", "Tertiary TDM2 Playback",
1218                              0, 0, 0, 0),
1219         SND_SOC_DAPM_AIF_OUT("TERT_TDM_RX_3", "Tertiary TDM3 Playback",
1220                              0, 0, 0, 0),
1221         SND_SOC_DAPM_AIF_OUT("TERT_TDM_RX_4", "Tertiary TDM4 Playback",
1222                              0, 0, 0, 0),
1223         SND_SOC_DAPM_AIF_OUT("TERT_TDM_RX_5", "Tertiary TDM5 Playback",
1224                              0, 0, 0, 0),
1225         SND_SOC_DAPM_AIF_OUT("TERT_TDM_RX_6", "Tertiary TDM6 Playback",
1226                              0, 0, 0, 0),
1227         SND_SOC_DAPM_AIF_OUT("TERT_TDM_RX_7", "Tertiary TDM7 Playback",
1228                              0, 0, 0, 0),
1229         SND_SOC_DAPM_AIF_IN("TERT_TDM_TX_0", "Tertiary TDM0 Capture",
1230                                                 0, 0, 0, 0),
1231         SND_SOC_DAPM_AIF_IN("TERT_TDM_TX_1", "Tertiary TDM1 Capture",
1232                                                 0, 0, 0, 0),
1233         SND_SOC_DAPM_AIF_IN("TERT_TDM_TX_2", "Tertiary TDM2 Capture",
1234                                                 0, 0, 0, 0),
1235         SND_SOC_DAPM_AIF_IN("TERT_TDM_TX_3", "Tertiary TDM3 Capture",
1236                                                 0, 0, 0, 0),
1237         SND_SOC_DAPM_AIF_IN("TERT_TDM_TX_4", "Tertiary TDM4 Capture",
1238                                                 0, 0, 0, 0),
1239         SND_SOC_DAPM_AIF_IN("TERT_TDM_TX_5", "Tertiary TDM5 Capture",
1240                                                 0, 0, 0, 0),
1241         SND_SOC_DAPM_AIF_IN("TERT_TDM_TX_6", "Tertiary TDM6 Capture",
1242                                                 0, 0, 0, 0),
1243         SND_SOC_DAPM_AIF_IN("TERT_TDM_TX_7", "Tertiary TDM7 Capture",
1244                                                 0, 0, 0, 0),
1245
1246         SND_SOC_DAPM_AIF_OUT("QUAT_TDM_RX_0", "Quaternary TDM0 Playback",
1247                              0, 0, 0, 0),
1248         SND_SOC_DAPM_AIF_OUT("QUAT_TDM_RX_1", "Quaternary TDM1 Playback",
1249                              0, 0, 0, 0),
1250         SND_SOC_DAPM_AIF_OUT("QUAT_TDM_RX_2", "Quaternary TDM2 Playback",
1251                              0, 0, 0, 0),
1252         SND_SOC_DAPM_AIF_OUT("QUAT_TDM_RX_3", "Quaternary TDM3 Playback",
1253                              0, 0, 0, 0),
1254         SND_SOC_DAPM_AIF_OUT("QUAT_TDM_RX_4", "Quaternary TDM4 Playback",
1255                              0, 0, 0, 0),
1256         SND_SOC_DAPM_AIF_OUT("QUAT_TDM_RX_5", "Quaternary TDM5 Playback",
1257                              0, 0, 0, 0),
1258         SND_SOC_DAPM_AIF_OUT("QUAT_TDM_RX_6", "Quaternary TDM6 Playback",
1259                              0, 0, 0, 0),
1260         SND_SOC_DAPM_AIF_OUT("QUAT_TDM_RX_7", "Quaternary TDM7 Playback",
1261                              0, 0, 0, 0),
1262         SND_SOC_DAPM_AIF_IN("QUAT_TDM_TX_0", "Quaternary TDM0 Capture",
1263                                                 0, 0, 0, 0),
1264         SND_SOC_DAPM_AIF_IN("QUAT_TDM_TX_1", "Quaternary TDM1 Capture",
1265                                                 0, 0, 0, 0),
1266         SND_SOC_DAPM_AIF_IN("QUAT_TDM_TX_2", "Quaternary TDM2 Capture",
1267                                                 0, 0, 0, 0),
1268         SND_SOC_DAPM_AIF_IN("QUAT_TDM_TX_3", "Quaternary TDM3 Capture",
1269                                                 0, 0, 0, 0),
1270         SND_SOC_DAPM_AIF_IN("QUAT_TDM_TX_4", "Quaternary TDM4 Capture",
1271                                                 0, 0, 0, 0),
1272         SND_SOC_DAPM_AIF_IN("QUAT_TDM_TX_5", "Quaternary TDM5 Capture",
1273                                                 0, 0, 0, 0),
1274         SND_SOC_DAPM_AIF_IN("QUAT_TDM_TX_6", "Quaternary TDM6 Capture",
1275                                                 0, 0, 0, 0),
1276         SND_SOC_DAPM_AIF_IN("QUAT_TDM_TX_7", "Quaternary TDM7 Capture",
1277                                                 0, 0, 0, 0),
1278
1279         SND_SOC_DAPM_AIF_OUT("QUIN_TDM_RX_0", "Quinary TDM0 Playback",
1280                              0, 0, 0, 0),
1281         SND_SOC_DAPM_AIF_OUT("QUIN_TDM_RX_1", "Quinary TDM1 Playback",
1282                              0, 0, 0, 0),
1283         SND_SOC_DAPM_AIF_OUT("QUIN_TDM_RX_2", "Quinary TDM2 Playback",
1284                              0, 0, 0, 0),
1285         SND_SOC_DAPM_AIF_OUT("QUIN_TDM_RX_3", "Quinary TDM3 Playback",
1286                              0, 0, 0, 0),
1287         SND_SOC_DAPM_AIF_OUT("QUIN_TDM_RX_4", "Quinary TDM4 Playback",
1288                              0, 0, 0, 0),
1289         SND_SOC_DAPM_AIF_OUT("QUIN_TDM_RX_5", "Quinary TDM5 Playback",
1290                              0, 0, 0, 0),
1291         SND_SOC_DAPM_AIF_OUT("QUIN_TDM_RX_6", "Quinary TDM6 Playback",
1292                              0, 0, 0, 0),
1293         SND_SOC_DAPM_AIF_OUT("QUIN_TDM_RX_7", "Quinary TDM7 Playback",
1294                              0, 0, 0, 0),
1295         SND_SOC_DAPM_AIF_IN("QUIN_TDM_TX_0", "Quinary TDM0 Capture",
1296                                                 0, 0, 0, 0),
1297         SND_SOC_DAPM_AIF_IN("QUIN_TDM_TX_1", "Quinary TDM1 Capture",
1298                                                 0, 0, 0, 0),
1299         SND_SOC_DAPM_AIF_IN("QUIN_TDM_TX_2", "Quinary TDM2 Capture",
1300                                                 0, 0, 0, 0),
1301         SND_SOC_DAPM_AIF_IN("QUIN_TDM_TX_3", "Quinary TDM3 Capture",
1302                                                 0, 0, 0, 0),
1303         SND_SOC_DAPM_AIF_IN("QUIN_TDM_TX_4", "Quinary TDM4 Capture",
1304                                                 0, 0, 0, 0),
1305         SND_SOC_DAPM_AIF_IN("QUIN_TDM_TX_5", "Quinary TDM5 Capture",
1306                                                 0, 0, 0, 0),
1307         SND_SOC_DAPM_AIF_IN("QUIN_TDM_TX_6", "Quinary TDM6 Capture",
1308                                                 0, 0, 0, 0),
1309         SND_SOC_DAPM_AIF_IN("QUIN_TDM_TX_7", "Quinary TDM7 Capture",
1310                                                 0, 0, 0, 0),
1311 };
1312
1313 static const struct snd_soc_component_driver q6afe_dai_component = {
1314         .name           = "q6afe-dai-component",
1315         .dapm_widgets = q6afe_dai_widgets,
1316         .num_dapm_widgets = ARRAY_SIZE(q6afe_dai_widgets),
1317         .dapm_routes = q6afe_dapm_routes,
1318         .num_dapm_routes = ARRAY_SIZE(q6afe_dapm_routes),
1319         .of_xlate_dai_name = q6afe_of_xlate_dai_name,
1320
1321 };
1322
1323 static void of_q6afe_parse_dai_data(struct device *dev,
1324                                     struct q6afe_dai_data *data)
1325 {
1326         struct device_node *node;
1327         int ret;
1328
1329         for_each_child_of_node(dev->of_node, node) {
1330                 unsigned int lines[Q6AFE_MAX_MI2S_LINES];
1331                 struct q6afe_dai_priv_data *priv;
1332                 int id, i, num_lines;
1333
1334                 ret = of_property_read_u32(node, "reg", &id);
1335                 if (ret || id > AFE_PORT_MAX) {
1336                         dev_err(dev, "valid dai id not found:%d\n", ret);
1337                         continue;
1338                 }
1339
1340                 switch (id) {
1341                 /* MI2S specific properties */
1342                 case PRIMARY_MI2S_RX ... QUATERNARY_MI2S_TX:
1343                         priv = &data->priv[id];
1344                         ret = of_property_read_variable_u32_array(node,
1345                                                         "qcom,sd-lines",
1346                                                         lines, 0,
1347                                                         Q6AFE_MAX_MI2S_LINES);
1348                         if (ret < 0)
1349                                 num_lines = 0;
1350                         else
1351                                 num_lines = ret;
1352
1353                         priv->sd_line_mask = 0;
1354
1355                         for (i = 0; i < num_lines; i++)
1356                                 priv->sd_line_mask |= BIT(lines[i]);
1357
1358                         break;
1359                 case PRIMARY_TDM_RX_0 ... QUINARY_TDM_TX_7:
1360                         priv = &data->priv[id];
1361                         ret = of_property_read_u32(node, "qcom,tdm-sync-mode",
1362                                                    &priv->sync_mode);
1363                         if (ret) {
1364                                 dev_err(dev, "No Sync mode from DT\n");
1365                                 break;
1366                         }
1367                         ret = of_property_read_u32(node, "qcom,tdm-sync-src",
1368                                                    &priv->sync_src);
1369                         if (ret) {
1370                                 dev_err(dev, "No Sync Src from DT\n");
1371                                 break;
1372                         }
1373                         ret = of_property_read_u32(node, "qcom,tdm-data-out",
1374                                                    &priv->data_out_enable);
1375                         if (ret) {
1376                                 dev_err(dev, "No Data out enable from DT\n");
1377                                 break;
1378                         }
1379                         ret = of_property_read_u32(node, "qcom,tdm-invert-sync",
1380                                                    &priv->invert_sync);
1381                         if (ret) {
1382                                 dev_err(dev, "No Invert sync from DT\n");
1383                                 break;
1384                         }
1385                         ret = of_property_read_u32(node, "qcom,tdm-data-delay",
1386                                                    &priv->data_delay);
1387                         if (ret) {
1388                                 dev_err(dev, "No Data Delay from DT\n");
1389                                 break;
1390                         }
1391                         ret = of_property_read_u32(node, "qcom,tdm-data-align",
1392                                                    &priv->data_align);
1393                         if (ret) {
1394                                 dev_err(dev, "No Data align from DT\n");
1395                                 break;
1396                         }
1397                         break;
1398                 default:
1399                         break;
1400                 }
1401         }
1402 }
1403
1404 static int q6afe_dai_dev_probe(struct platform_device *pdev)
1405 {
1406         struct q6afe_dai_data *dai_data;
1407         struct device *dev = &pdev->dev;
1408
1409         dai_data = devm_kzalloc(dev, sizeof(*dai_data), GFP_KERNEL);
1410         if (!dai_data)
1411                 return -ENOMEM;
1412
1413         dev_set_drvdata(dev, dai_data);
1414
1415         of_q6afe_parse_dai_data(dev, dai_data);
1416
1417         return devm_snd_soc_register_component(dev, &q6afe_dai_component,
1418                                           q6afe_dais, ARRAY_SIZE(q6afe_dais));
1419 }
1420
1421 static const struct of_device_id q6afe_dai_device_id[] = {
1422         { .compatible = "qcom,q6afe-dais" },
1423         {},
1424 };
1425 MODULE_DEVICE_TABLE(of, q6afe_dai_device_id);
1426
1427 static struct platform_driver q6afe_dai_platform_driver = {
1428         .driver = {
1429                 .name = "q6afe-dai",
1430                 .of_match_table = of_match_ptr(q6afe_dai_device_id),
1431         },
1432         .probe = q6afe_dai_dev_probe,
1433 };
1434 module_platform_driver(q6afe_dai_platform_driver);
1435
1436 MODULE_DESCRIPTION("Q6 Audio Fronend dai driver");
1437 MODULE_LICENSE("GPL v2");