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