1 // SPDX-License-Identifier: GPL-2.0
3 * Mediatek ALSA SoC AFE platform driver for 2701
5 * Copyright (c) 2016 MediaTek Inc.
6 * Author: Garlic Tseng <garlic.tseng@mediatek.com>
7 * Ir Lian <ir.lian@mediatek.com>
8 * Ryder Lee <ryder.lee@mediatek.com>
11 #include <linux/delay.h>
12 #include <linux/module.h>
13 #include <linux/mfd/syscon.h>
15 #include <linux/pm_runtime.h>
17 #include "mt2701-afe-common.h"
18 #include "mt2701-afe-clock-ctrl.h"
19 #include "../common/mtk-afe-platform-driver.h"
20 #include "../common/mtk-afe-fe-dai.h"
22 static const struct snd_pcm_hardware mt2701_afe_hardware
= {
23 .info
= SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
24 | SNDRV_PCM_INFO_RESUME
| SNDRV_PCM_INFO_MMAP_VALID
,
25 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
26 | SNDRV_PCM_FMTBIT_S32_LE
,
27 .period_bytes_min
= 1024,
28 .period_bytes_max
= 1024 * 256,
31 .buffer_bytes_max
= 1024 * 1024,
35 struct mt2701_afe_rate
{
37 unsigned int regvalue
;
40 static const struct mt2701_afe_rate mt2701_afe_i2s_rates
[] = {
41 { .rate
= 8000, .regvalue
= 0 },
42 { .rate
= 12000, .regvalue
= 1 },
43 { .rate
= 16000, .regvalue
= 2 },
44 { .rate
= 24000, .regvalue
= 3 },
45 { .rate
= 32000, .regvalue
= 4 },
46 { .rate
= 48000, .regvalue
= 5 },
47 { .rate
= 96000, .regvalue
= 6 },
48 { .rate
= 192000, .regvalue
= 7 },
49 { .rate
= 384000, .regvalue
= 8 },
50 { .rate
= 7350, .regvalue
= 16 },
51 { .rate
= 11025, .regvalue
= 17 },
52 { .rate
= 14700, .regvalue
= 18 },
53 { .rate
= 22050, .regvalue
= 19 },
54 { .rate
= 29400, .regvalue
= 20 },
55 { .rate
= 44100, .regvalue
= 21 },
56 { .rate
= 88200, .regvalue
= 22 },
57 { .rate
= 176400, .regvalue
= 23 },
58 { .rate
= 352800, .regvalue
= 24 },
61 static const unsigned int mt2701_afe_backup_list
[] = {
82 static int mt2701_dai_num_to_i2s(struct mtk_base_afe
*afe
, int num
)
84 struct mt2701_afe_private
*afe_priv
= afe
->platform_priv
;
85 int val
= num
- MT2701_IO_I2S
;
87 if (val
< 0 || val
>= afe_priv
->soc
->i2s_num
) {
88 dev_err(afe
->dev
, "%s, num not available, num %d, val %d\n",
95 static int mt2701_afe_i2s_fs(unsigned int sample_rate
)
99 for (i
= 0; i
< ARRAY_SIZE(mt2701_afe_i2s_rates
); i
++)
100 if (mt2701_afe_i2s_rates
[i
].rate
== sample_rate
)
101 return mt2701_afe_i2s_rates
[i
].regvalue
;
106 static int mt2701_afe_i2s_startup(struct snd_pcm_substream
*substream
,
107 struct snd_soc_dai
*dai
)
109 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
110 struct mt2701_afe_private
*afe_priv
= afe
->platform_priv
;
111 int i2s_num
= mt2701_dai_num_to_i2s(afe
, dai
->id
);
112 bool mode
= afe_priv
->soc
->has_one_heart_mode
;
117 return mt2701_afe_enable_mclk(afe
, mode
? 1 : i2s_num
);
120 static int mt2701_afe_i2s_path_disable(struct mtk_base_afe
*afe
,
121 struct mt2701_i2s_path
*i2s_path
,
124 const struct mt2701_i2s_data
*i2s_data
= i2s_path
->i2s_data
[stream_dir
];
126 if (--i2s_path
->on
[stream_dir
] < 0)
127 i2s_path
->on
[stream_dir
] = 0;
129 if (i2s_path
->on
[stream_dir
])
133 regmap_update_bits(afe
->regmap
, i2s_data
->i2s_ctrl_reg
,
134 ASYS_I2S_CON_I2S_EN
, 0);
136 mt2701_afe_disable_i2s(afe
, i2s_path
, stream_dir
);
141 static void mt2701_afe_i2s_shutdown(struct snd_pcm_substream
*substream
,
142 struct snd_soc_dai
*dai
)
144 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
145 struct mt2701_afe_private
*afe_priv
= afe
->platform_priv
;
146 int i2s_num
= mt2701_dai_num_to_i2s(afe
, dai
->id
);
147 struct mt2701_i2s_path
*i2s_path
;
148 bool mode
= afe_priv
->soc
->has_one_heart_mode
;
153 i2s_path
= &afe_priv
->i2s_path
[i2s_num
];
155 if (i2s_path
->occupied
[substream
->stream
])
156 i2s_path
->occupied
[substream
->stream
] = 0;
160 mt2701_afe_i2s_path_disable(afe
, i2s_path
, substream
->stream
);
162 /* need to disable i2s-out path when disable i2s-in */
163 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
164 mt2701_afe_i2s_path_disable(afe
, i2s_path
, !substream
->stream
);
168 mt2701_afe_disable_mclk(afe
, mode
? 1 : i2s_num
);
171 static int mt2701_i2s_path_enable(struct mtk_base_afe
*afe
,
172 struct mt2701_i2s_path
*i2s_path
,
173 int stream_dir
, int rate
)
175 const struct mt2701_i2s_data
*i2s_data
= i2s_path
->i2s_data
[stream_dir
];
176 struct mt2701_afe_private
*afe_priv
= afe
->platform_priv
;
177 int reg
, fs
, w_len
= 1; /* now we support bck 64bits only */
178 unsigned int mask
, val
;
180 /* no need to enable if already done */
181 if (++i2s_path
->on
[stream_dir
] != 1)
184 fs
= mt2701_afe_i2s_fs(rate
);
186 mask
= ASYS_I2S_CON_FS
|
187 ASYS_I2S_CON_I2S_COUPLE_MODE
| /* 0 */
188 ASYS_I2S_CON_I2S_MODE
|
189 ASYS_I2S_CON_WIDE_MODE
;
191 val
= ASYS_I2S_CON_FS_SET(fs
) |
192 ASYS_I2S_CON_I2S_MODE
|
193 ASYS_I2S_CON_WIDE_MODE_SET(w_len
);
195 if (stream_dir
== SNDRV_PCM_STREAM_CAPTURE
) {
196 mask
|= ASYS_I2S_IN_PHASE_FIX
;
197 val
|= ASYS_I2S_IN_PHASE_FIX
;
198 reg
= ASMI_TIMING_CON1
;
200 if (afe_priv
->soc
->has_one_heart_mode
) {
201 mask
|= ASYS_I2S_CON_ONE_HEART_MODE
;
202 val
|= ASYS_I2S_CON_ONE_HEART_MODE
;
204 reg
= ASMO_TIMING_CON1
;
207 regmap_update_bits(afe
->regmap
, i2s_data
->i2s_ctrl_reg
, mask
, val
);
209 regmap_update_bits(afe
->regmap
, reg
,
210 i2s_data
->i2s_asrc_fs_mask
211 << i2s_data
->i2s_asrc_fs_shift
,
212 fs
<< i2s_data
->i2s_asrc_fs_shift
);
215 mt2701_afe_enable_i2s(afe
, i2s_path
, stream_dir
);
217 /* reset i2s hw status before enable */
218 regmap_update_bits(afe
->regmap
, i2s_data
->i2s_ctrl_reg
,
219 ASYS_I2S_CON_RESET
, ASYS_I2S_CON_RESET
);
221 regmap_update_bits(afe
->regmap
, i2s_data
->i2s_ctrl_reg
,
222 ASYS_I2S_CON_RESET
, 0);
224 regmap_update_bits(afe
->regmap
, i2s_data
->i2s_ctrl_reg
,
225 ASYS_I2S_CON_I2S_EN
, ASYS_I2S_CON_I2S_EN
);
229 static int mt2701_afe_i2s_prepare(struct snd_pcm_substream
*substream
,
230 struct snd_soc_dai
*dai
)
232 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
233 struct mt2701_afe_private
*afe_priv
= afe
->platform_priv
;
234 int ret
, i2s_num
= mt2701_dai_num_to_i2s(afe
, dai
->id
);
235 struct mt2701_i2s_path
*i2s_path
;
236 bool mode
= afe_priv
->soc
->has_one_heart_mode
;
241 i2s_path
= &afe_priv
->i2s_path
[i2s_num
];
243 if (i2s_path
->occupied
[substream
->stream
])
246 ret
= mt2701_mclk_configuration(afe
, mode
? 1 : i2s_num
);
250 i2s_path
->occupied
[substream
->stream
] = 1;
252 /* need to enable i2s-out path when enable i2s-in */
253 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
254 mt2701_i2s_path_enable(afe
, i2s_path
, !substream
->stream
,
255 substream
->runtime
->rate
);
257 mt2701_i2s_path_enable(afe
, i2s_path
, substream
->stream
,
258 substream
->runtime
->rate
);
263 static int mt2701_afe_i2s_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
264 unsigned int freq
, int dir
)
266 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
267 struct mt2701_afe_private
*afe_priv
= afe
->platform_priv
;
268 int i2s_num
= mt2701_dai_num_to_i2s(afe
, dai
->id
);
269 bool mode
= afe_priv
->soc
->has_one_heart_mode
;
275 if (dir
== SND_SOC_CLOCK_IN
) {
276 dev_warn(dai
->dev
, "The SoCs doesn't support mclk input\n");
280 afe_priv
->i2s_path
[mode
? 1 : i2s_num
].mclk_rate
= freq
;
285 static int mt2701_btmrg_startup(struct snd_pcm_substream
*substream
,
286 struct snd_soc_dai
*dai
)
288 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
289 struct mt2701_afe_private
*afe_priv
= afe
->platform_priv
;
292 ret
= mt2701_enable_btmrg_clk(afe
);
296 afe_priv
->mrg_enable
[substream
->stream
] = 1;
301 static int mt2701_btmrg_hw_params(struct snd_pcm_substream
*substream
,
302 struct snd_pcm_hw_params
*params
,
303 struct snd_soc_dai
*dai
)
305 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
309 stream_fs
= params_rate(params
);
311 if (stream_fs
!= 8000 && stream_fs
!= 16000) {
312 dev_err(afe
->dev
, "unsupported rate %d\n", stream_fs
);
316 regmap_update_bits(afe
->regmap
, AFE_MRGIF_CON
,
317 AFE_MRGIF_CON_I2S_MODE_MASK
,
318 AFE_MRGIF_CON_I2S_MODE_32K
);
320 val
= AFE_DAIBT_CON0_BT_FUNC_EN
| AFE_DAIBT_CON0_BT_FUNC_RDY
321 | AFE_DAIBT_CON0_MRG_USE
;
324 if (stream_fs
== 16000)
325 val
|= AFE_DAIBT_CON0_BT_WIDE_MODE_EN
;
327 msk
|= AFE_DAIBT_CON0_BT_WIDE_MODE_EN
;
329 regmap_update_bits(afe
->regmap
, AFE_DAIBT_CON0
, msk
, val
);
331 regmap_update_bits(afe
->regmap
, AFE_DAIBT_CON0
,
332 AFE_DAIBT_CON0_DAIBT_EN
,
333 AFE_DAIBT_CON0_DAIBT_EN
);
334 regmap_update_bits(afe
->regmap
, AFE_MRGIF_CON
,
335 AFE_MRGIF_CON_MRG_I2S_EN
,
336 AFE_MRGIF_CON_MRG_I2S_EN
);
337 regmap_update_bits(afe
->regmap
, AFE_MRGIF_CON
,
338 AFE_MRGIF_CON_MRG_EN
,
339 AFE_MRGIF_CON_MRG_EN
);
343 static void mt2701_btmrg_shutdown(struct snd_pcm_substream
*substream
,
344 struct snd_soc_dai
*dai
)
346 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
347 struct mt2701_afe_private
*afe_priv
= afe
->platform_priv
;
349 /* if the other direction stream is not occupied */
350 if (!afe_priv
->mrg_enable
[!substream
->stream
]) {
351 regmap_update_bits(afe
->regmap
, AFE_DAIBT_CON0
,
352 AFE_DAIBT_CON0_DAIBT_EN
, 0);
353 regmap_update_bits(afe
->regmap
, AFE_MRGIF_CON
,
354 AFE_MRGIF_CON_MRG_EN
, 0);
355 regmap_update_bits(afe
->regmap
, AFE_MRGIF_CON
,
356 AFE_MRGIF_CON_MRG_I2S_EN
, 0);
357 mt2701_disable_btmrg_clk(afe
);
360 afe_priv
->mrg_enable
[substream
->stream
] = 0;
363 static int mt2701_simple_fe_startup(struct snd_pcm_substream
*substream
,
364 struct snd_soc_dai
*dai
)
366 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
367 struct mtk_base_afe_memif
*memif_tmp
;
368 int stream_dir
= substream
->stream
;
370 /* can't run single DL & DLM at the same time */
371 if (stream_dir
== SNDRV_PCM_STREAM_PLAYBACK
) {
372 memif_tmp
= &afe
->memif
[MT2701_MEMIF_DLM
];
373 if (memif_tmp
->substream
) {
374 dev_warn(afe
->dev
, "memif is not available");
379 return mtk_afe_fe_startup(substream
, dai
);
382 static int mt2701_simple_fe_hw_params(struct snd_pcm_substream
*substream
,
383 struct snd_pcm_hw_params
*params
,
384 struct snd_soc_dai
*dai
)
386 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
387 int stream_dir
= substream
->stream
;
389 /* single DL use PAIR_INTERLEAVE */
390 if (stream_dir
== SNDRV_PCM_STREAM_PLAYBACK
)
391 regmap_update_bits(afe
->regmap
,
393 AFE_MEMIF_PBUF_SIZE_DLM_MASK
,
394 AFE_MEMIF_PBUF_SIZE_PAIR_INTERLEAVE
);
396 return mtk_afe_fe_hw_params(substream
, params
, dai
);
399 static int mt2701_dlm_fe_startup(struct snd_pcm_substream
*substream
,
400 struct snd_soc_dai
*dai
)
402 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
403 struct mtk_base_afe_memif
*memif_tmp
;
404 const struct mtk_base_memif_data
*memif_data
;
407 for (i
= MT2701_MEMIF_DL1
; i
< MT2701_MEMIF_DL_SINGLE_NUM
; ++i
) {
408 memif_tmp
= &afe
->memif
[i
];
409 if (memif_tmp
->substream
)
413 /* enable agent for all signal DL (due to hw design) */
414 for (i
= MT2701_MEMIF_DL1
; i
< MT2701_MEMIF_DL_SINGLE_NUM
; ++i
) {
415 memif_data
= afe
->memif
[i
].data
;
416 regmap_update_bits(afe
->regmap
,
417 memif_data
->agent_disable_reg
,
418 1 << memif_data
->agent_disable_shift
,
419 0 << memif_data
->agent_disable_shift
);
422 return mtk_afe_fe_startup(substream
, dai
);
425 static void mt2701_dlm_fe_shutdown(struct snd_pcm_substream
*substream
,
426 struct snd_soc_dai
*dai
)
428 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
429 const struct mtk_base_memif_data
*memif_data
;
432 for (i
= MT2701_MEMIF_DL1
; i
< MT2701_MEMIF_DL_SINGLE_NUM
; ++i
) {
433 memif_data
= afe
->memif
[i
].data
;
434 regmap_update_bits(afe
->regmap
,
435 memif_data
->agent_disable_reg
,
436 1 << memif_data
->agent_disable_shift
,
437 1 << memif_data
->agent_disable_shift
);
440 return mtk_afe_fe_shutdown(substream
, dai
);
443 static int mt2701_dlm_fe_hw_params(struct snd_pcm_substream
*substream
,
444 struct snd_pcm_hw_params
*params
,
445 struct snd_soc_dai
*dai
)
447 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
448 int channels
= params_channels(params
);
450 regmap_update_bits(afe
->regmap
,
452 AFE_MEMIF_PBUF_SIZE_DLM_MASK
,
453 AFE_MEMIF_PBUF_SIZE_FULL_INTERLEAVE
);
454 regmap_update_bits(afe
->regmap
,
456 AFE_MEMIF_PBUF_SIZE_DLM_BYTE_MASK
,
457 AFE_MEMIF_PBUF_SIZE_DLM_32BYTES
);
458 regmap_update_bits(afe
->regmap
,
460 AFE_MEMIF_PBUF_SIZE_DLM_CH_MASK
,
461 AFE_MEMIF_PBUF_SIZE_DLM_CH(channels
));
463 return mtk_afe_fe_hw_params(substream
, params
, dai
);
466 static int mt2701_dlm_fe_trigger(struct snd_pcm_substream
*substream
,
467 int cmd
, struct snd_soc_dai
*dai
)
469 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
470 struct mtk_base_afe_memif
*memif_tmp
= &afe
->memif
[MT2701_MEMIF_DL1
];
473 case SNDRV_PCM_TRIGGER_START
:
474 case SNDRV_PCM_TRIGGER_RESUME
:
475 regmap_update_bits(afe
->regmap
, memif_tmp
->data
->enable_reg
,
476 1 << memif_tmp
->data
->enable_shift
,
477 1 << memif_tmp
->data
->enable_shift
);
478 mtk_afe_fe_trigger(substream
, cmd
, dai
);
480 case SNDRV_PCM_TRIGGER_STOP
:
481 case SNDRV_PCM_TRIGGER_SUSPEND
:
482 mtk_afe_fe_trigger(substream
, cmd
, dai
);
483 regmap_update_bits(afe
->regmap
, memif_tmp
->data
->enable_reg
,
484 1 << memif_tmp
->data
->enable_shift
, 0);
492 static int mt2701_memif_fs(struct snd_pcm_substream
*substream
,
495 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
498 if (snd_soc_rtd_to_cpu(rtd
, 0)->id
!= MT2701_MEMIF_ULBT
)
499 fs
= mt2701_afe_i2s_fs(rate
);
501 fs
= (rate
== 16000 ? 1 : 0);
506 static int mt2701_irq_fs(struct snd_pcm_substream
*substream
, unsigned int rate
)
508 return mt2701_afe_i2s_fs(rate
);
512 static const struct snd_soc_dai_ops mt2701_single_memif_dai_ops
= {
513 .startup
= mt2701_simple_fe_startup
,
514 .shutdown
= mtk_afe_fe_shutdown
,
515 .hw_params
= mt2701_simple_fe_hw_params
,
516 .hw_free
= mtk_afe_fe_hw_free
,
517 .prepare
= mtk_afe_fe_prepare
,
518 .trigger
= mtk_afe_fe_trigger
,
521 static const struct snd_soc_dai_ops mt2701_dlm_memif_dai_ops
= {
522 .startup
= mt2701_dlm_fe_startup
,
523 .shutdown
= mt2701_dlm_fe_shutdown
,
524 .hw_params
= mt2701_dlm_fe_hw_params
,
525 .hw_free
= mtk_afe_fe_hw_free
,
526 .prepare
= mtk_afe_fe_prepare
,
527 .trigger
= mt2701_dlm_fe_trigger
,
531 static const struct snd_soc_dai_ops mt2701_afe_i2s_ops
= {
532 .startup
= mt2701_afe_i2s_startup
,
533 .shutdown
= mt2701_afe_i2s_shutdown
,
534 .prepare
= mt2701_afe_i2s_prepare
,
535 .set_sysclk
= mt2701_afe_i2s_set_sysclk
,
539 static const struct snd_soc_dai_ops mt2701_btmrg_ops
= {
540 .startup
= mt2701_btmrg_startup
,
541 .shutdown
= mt2701_btmrg_shutdown
,
542 .hw_params
= mt2701_btmrg_hw_params
,
545 static struct snd_soc_dai_driver mt2701_afe_pcm_dais
[] = {
546 /* FE DAIs: memory intefaces to CPU */
549 .id
= MT2701_MEMIF_DL1
,
551 .stream_name
= "DL1",
554 .rates
= SNDRV_PCM_RATE_8000_192000
,
555 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
556 | SNDRV_PCM_FMTBIT_S24_LE
557 | SNDRV_PCM_FMTBIT_S32_LE
)
559 .ops
= &mt2701_single_memif_dai_ops
,
563 .id
= MT2701_MEMIF_DLM
,
565 .stream_name
= "DLM",
568 .rates
= SNDRV_PCM_RATE_8000_192000
,
569 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
570 | SNDRV_PCM_FMTBIT_S24_LE
571 | SNDRV_PCM_FMTBIT_S32_LE
)
574 .ops
= &mt2701_dlm_memif_dai_ops
,
578 .id
= MT2701_MEMIF_UL1
,
580 .stream_name
= "UL1",
583 .rates
= SNDRV_PCM_RATE_8000_48000
,
584 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
585 | SNDRV_PCM_FMTBIT_S24_LE
586 | SNDRV_PCM_FMTBIT_S32_LE
)
588 .ops
= &mt2701_single_memif_dai_ops
,
592 .id
= MT2701_MEMIF_UL2
,
594 .stream_name
= "UL2",
597 .rates
= SNDRV_PCM_RATE_8000_192000
,
598 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
599 | SNDRV_PCM_FMTBIT_S24_LE
600 | SNDRV_PCM_FMTBIT_S32_LE
)
603 .ops
= &mt2701_single_memif_dai_ops
,
607 .id
= MT2701_MEMIF_DLBT
,
609 .stream_name
= "DLBT",
612 .rates
= (SNDRV_PCM_RATE_8000
613 | SNDRV_PCM_RATE_16000
),
614 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
616 .ops
= &mt2701_single_memif_dai_ops
,
620 .id
= MT2701_MEMIF_ULBT
,
622 .stream_name
= "ULBT",
625 .rates
= (SNDRV_PCM_RATE_8000
626 | SNDRV_PCM_RATE_16000
),
627 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
629 .ops
= &mt2701_single_memif_dai_ops
,
636 .stream_name
= "I2S0 Playback",
639 .rates
= SNDRV_PCM_RATE_8000_192000
,
640 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
641 | SNDRV_PCM_FMTBIT_S24_LE
642 | SNDRV_PCM_FMTBIT_S32_LE
)
646 .stream_name
= "I2S0 Capture",
649 .rates
= SNDRV_PCM_RATE_8000_192000
,
650 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
651 | SNDRV_PCM_FMTBIT_S24_LE
652 | SNDRV_PCM_FMTBIT_S32_LE
)
655 .ops
= &mt2701_afe_i2s_ops
,
660 .id
= MT2701_IO_2ND_I2S
,
662 .stream_name
= "I2S1 Playback",
665 .rates
= SNDRV_PCM_RATE_8000_192000
,
666 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
667 | SNDRV_PCM_FMTBIT_S24_LE
668 | SNDRV_PCM_FMTBIT_S32_LE
)
671 .stream_name
= "I2S1 Capture",
674 .rates
= SNDRV_PCM_RATE_8000_192000
,
675 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
676 | SNDRV_PCM_FMTBIT_S24_LE
677 | SNDRV_PCM_FMTBIT_S32_LE
)
679 .ops
= &mt2701_afe_i2s_ops
,
684 .id
= MT2701_IO_3RD_I2S
,
686 .stream_name
= "I2S2 Playback",
689 .rates
= SNDRV_PCM_RATE_8000_192000
,
690 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
691 | SNDRV_PCM_FMTBIT_S24_LE
692 | SNDRV_PCM_FMTBIT_S32_LE
)
695 .stream_name
= "I2S2 Capture",
698 .rates
= SNDRV_PCM_RATE_8000_192000
,
699 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
700 | SNDRV_PCM_FMTBIT_S24_LE
701 | SNDRV_PCM_FMTBIT_S32_LE
)
703 .ops
= &mt2701_afe_i2s_ops
,
708 .id
= MT2701_IO_4TH_I2S
,
710 .stream_name
= "I2S3 Playback",
713 .rates
= SNDRV_PCM_RATE_8000_192000
,
714 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
715 | SNDRV_PCM_FMTBIT_S24_LE
716 | SNDRV_PCM_FMTBIT_S32_LE
)
719 .stream_name
= "I2S3 Capture",
722 .rates
= SNDRV_PCM_RATE_8000_192000
,
723 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
724 | SNDRV_PCM_FMTBIT_S24_LE
725 | SNDRV_PCM_FMTBIT_S32_LE
)
727 .ops
= &mt2701_afe_i2s_ops
,
734 .stream_name
= "BT Playback",
737 .rates
= (SNDRV_PCM_RATE_8000
738 | SNDRV_PCM_RATE_16000
),
739 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
742 .stream_name
= "BT Capture",
745 .rates
= (SNDRV_PCM_RATE_8000
746 | SNDRV_PCM_RATE_16000
),
747 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
749 .ops
= &mt2701_btmrg_ops
,
754 static const struct snd_kcontrol_new mt2701_afe_o00_mix
[] = {
755 SOC_DAPM_SINGLE_AUTODISABLE("I00 Switch", AFE_CONN0
, 0, 1, 0),
758 static const struct snd_kcontrol_new mt2701_afe_o01_mix
[] = {
759 SOC_DAPM_SINGLE_AUTODISABLE("I01 Switch", AFE_CONN1
, 1, 1, 0),
762 static const struct snd_kcontrol_new mt2701_afe_o02_mix
[] = {
763 SOC_DAPM_SINGLE_AUTODISABLE("I02 Switch", AFE_CONN2
, 2, 1, 0),
766 static const struct snd_kcontrol_new mt2701_afe_o03_mix
[] = {
767 SOC_DAPM_SINGLE_AUTODISABLE("I03 Switch", AFE_CONN3
, 3, 1, 0),
770 static const struct snd_kcontrol_new mt2701_afe_o14_mix
[] = {
771 SOC_DAPM_SINGLE_AUTODISABLE("I26 Switch", AFE_CONN14
, 26, 1, 0),
774 static const struct snd_kcontrol_new mt2701_afe_o15_mix
[] = {
775 SOC_DAPM_SINGLE_AUTODISABLE("I12 Switch", AFE_CONN15
, 12, 1, 0),
778 static const struct snd_kcontrol_new mt2701_afe_o16_mix
[] = {
779 SOC_DAPM_SINGLE_AUTODISABLE("I13 Switch", AFE_CONN16
, 13, 1, 0),
782 static const struct snd_kcontrol_new mt2701_afe_o17_mix
[] = {
783 SOC_DAPM_SINGLE_AUTODISABLE("I14 Switch", AFE_CONN17
, 14, 1, 0),
786 static const struct snd_kcontrol_new mt2701_afe_o18_mix
[] = {
787 SOC_DAPM_SINGLE_AUTODISABLE("I15 Switch", AFE_CONN18
, 15, 1, 0),
790 static const struct snd_kcontrol_new mt2701_afe_o19_mix
[] = {
791 SOC_DAPM_SINGLE_AUTODISABLE("I16 Switch", AFE_CONN19
, 16, 1, 0),
794 static const struct snd_kcontrol_new mt2701_afe_o20_mix
[] = {
795 SOC_DAPM_SINGLE_AUTODISABLE("I17 Switch", AFE_CONN20
, 17, 1, 0),
798 static const struct snd_kcontrol_new mt2701_afe_o21_mix
[] = {
799 SOC_DAPM_SINGLE_AUTODISABLE("I18 Switch", AFE_CONN21
, 18, 1, 0),
802 static const struct snd_kcontrol_new mt2701_afe_o22_mix
[] = {
803 SOC_DAPM_SINGLE_AUTODISABLE("I19 Switch", AFE_CONN22
, 19, 1, 0),
806 static const struct snd_kcontrol_new mt2701_afe_o31_mix
[] = {
807 SOC_DAPM_SINGLE_AUTODISABLE("I35 Switch", AFE_CONN41
, 9, 1, 0),
810 static const struct snd_kcontrol_new mt2701_afe_i02_mix
[] = {
811 SOC_DAPM_SINGLE("I2S0 Switch", SND_SOC_NOPM
, 0, 1, 0),
814 static const struct snd_kcontrol_new mt2701_afe_multi_ch_out_i2s0
[] = {
815 SOC_DAPM_SINGLE_AUTODISABLE("Multich I2S0 Out Switch",
816 ASYS_I2SO1_CON
, 26, 1, 0),
819 static const struct snd_kcontrol_new mt2701_afe_multi_ch_out_i2s1
[] = {
820 SOC_DAPM_SINGLE_AUTODISABLE("Multich I2S1 Out Switch",
821 ASYS_I2SO2_CON
, 26, 1, 0),
824 static const struct snd_kcontrol_new mt2701_afe_multi_ch_out_i2s2
[] = {
825 SOC_DAPM_SINGLE_AUTODISABLE("Multich I2S2 Out Switch",
826 PWR2_TOP_CON
, 17, 1, 0),
829 static const struct snd_kcontrol_new mt2701_afe_multi_ch_out_i2s3
[] = {
830 SOC_DAPM_SINGLE_AUTODISABLE("Multich I2S3 Out Switch",
831 PWR2_TOP_CON
, 18, 1, 0),
834 static const struct snd_soc_dapm_widget mt2701_afe_pcm_widgets
[] = {
835 /* inter-connections */
836 SND_SOC_DAPM_MIXER("I00", SND_SOC_NOPM
, 0, 0, NULL
, 0),
837 SND_SOC_DAPM_MIXER("I01", SND_SOC_NOPM
, 0, 0, NULL
, 0),
838 SND_SOC_DAPM_MIXER("I02", SND_SOC_NOPM
, 0, 0, mt2701_afe_i02_mix
,
839 ARRAY_SIZE(mt2701_afe_i02_mix
)),
840 SND_SOC_DAPM_MIXER("I03", SND_SOC_NOPM
, 0, 0, NULL
, 0),
841 SND_SOC_DAPM_MIXER("I12", SND_SOC_NOPM
, 0, 0, NULL
, 0),
842 SND_SOC_DAPM_MIXER("I13", SND_SOC_NOPM
, 0, 0, NULL
, 0),
843 SND_SOC_DAPM_MIXER("I14", SND_SOC_NOPM
, 0, 0, NULL
, 0),
844 SND_SOC_DAPM_MIXER("I15", SND_SOC_NOPM
, 0, 0, NULL
, 0),
845 SND_SOC_DAPM_MIXER("I16", SND_SOC_NOPM
, 0, 0, NULL
, 0),
846 SND_SOC_DAPM_MIXER("I17", SND_SOC_NOPM
, 0, 0, NULL
, 0),
847 SND_SOC_DAPM_MIXER("I18", SND_SOC_NOPM
, 0, 0, NULL
, 0),
848 SND_SOC_DAPM_MIXER("I19", SND_SOC_NOPM
, 0, 0, NULL
, 0),
849 SND_SOC_DAPM_MIXER("I26", SND_SOC_NOPM
, 0, 0, NULL
, 0),
850 SND_SOC_DAPM_MIXER("I35", SND_SOC_NOPM
, 0, 0, NULL
, 0),
852 SND_SOC_DAPM_MIXER("O00", SND_SOC_NOPM
, 0, 0, mt2701_afe_o00_mix
,
853 ARRAY_SIZE(mt2701_afe_o00_mix
)),
854 SND_SOC_DAPM_MIXER("O01", SND_SOC_NOPM
, 0, 0, mt2701_afe_o01_mix
,
855 ARRAY_SIZE(mt2701_afe_o01_mix
)),
856 SND_SOC_DAPM_MIXER("O02", SND_SOC_NOPM
, 0, 0, mt2701_afe_o02_mix
,
857 ARRAY_SIZE(mt2701_afe_o02_mix
)),
858 SND_SOC_DAPM_MIXER("O03", SND_SOC_NOPM
, 0, 0, mt2701_afe_o03_mix
,
859 ARRAY_SIZE(mt2701_afe_o03_mix
)),
860 SND_SOC_DAPM_MIXER("O14", SND_SOC_NOPM
, 0, 0, mt2701_afe_o14_mix
,
861 ARRAY_SIZE(mt2701_afe_o14_mix
)),
862 SND_SOC_DAPM_MIXER("O15", SND_SOC_NOPM
, 0, 0, mt2701_afe_o15_mix
,
863 ARRAY_SIZE(mt2701_afe_o15_mix
)),
864 SND_SOC_DAPM_MIXER("O16", SND_SOC_NOPM
, 0, 0, mt2701_afe_o16_mix
,
865 ARRAY_SIZE(mt2701_afe_o16_mix
)),
866 SND_SOC_DAPM_MIXER("O17", SND_SOC_NOPM
, 0, 0, mt2701_afe_o17_mix
,
867 ARRAY_SIZE(mt2701_afe_o17_mix
)),
868 SND_SOC_DAPM_MIXER("O18", SND_SOC_NOPM
, 0, 0, mt2701_afe_o18_mix
,
869 ARRAY_SIZE(mt2701_afe_o18_mix
)),
870 SND_SOC_DAPM_MIXER("O19", SND_SOC_NOPM
, 0, 0, mt2701_afe_o19_mix
,
871 ARRAY_SIZE(mt2701_afe_o19_mix
)),
872 SND_SOC_DAPM_MIXER("O20", SND_SOC_NOPM
, 0, 0, mt2701_afe_o20_mix
,
873 ARRAY_SIZE(mt2701_afe_o20_mix
)),
874 SND_SOC_DAPM_MIXER("O21", SND_SOC_NOPM
, 0, 0, mt2701_afe_o21_mix
,
875 ARRAY_SIZE(mt2701_afe_o21_mix
)),
876 SND_SOC_DAPM_MIXER("O22", SND_SOC_NOPM
, 0, 0, mt2701_afe_o22_mix
,
877 ARRAY_SIZE(mt2701_afe_o22_mix
)),
878 SND_SOC_DAPM_MIXER("O31", SND_SOC_NOPM
, 0, 0, mt2701_afe_o31_mix
,
879 ARRAY_SIZE(mt2701_afe_o31_mix
)),
881 SND_SOC_DAPM_MIXER("I12I13", SND_SOC_NOPM
, 0, 0,
882 mt2701_afe_multi_ch_out_i2s0
,
883 ARRAY_SIZE(mt2701_afe_multi_ch_out_i2s0
)),
884 SND_SOC_DAPM_MIXER("I14I15", SND_SOC_NOPM
, 0, 0,
885 mt2701_afe_multi_ch_out_i2s1
,
886 ARRAY_SIZE(mt2701_afe_multi_ch_out_i2s1
)),
887 SND_SOC_DAPM_MIXER("I16I17", SND_SOC_NOPM
, 0, 0,
888 mt2701_afe_multi_ch_out_i2s2
,
889 ARRAY_SIZE(mt2701_afe_multi_ch_out_i2s2
)),
890 SND_SOC_DAPM_MIXER("I18I19", SND_SOC_NOPM
, 0, 0,
891 mt2701_afe_multi_ch_out_i2s3
,
892 ARRAY_SIZE(mt2701_afe_multi_ch_out_i2s3
)),
895 static const struct snd_soc_dapm_route mt2701_afe_pcm_routes
[] = {
896 {"I12", NULL
, "DL1"},
897 {"I13", NULL
, "DL1"},
898 {"I35", NULL
, "DLBT"},
900 {"I2S0 Playback", NULL
, "O15"},
901 {"I2S0 Playback", NULL
, "O16"},
902 {"I2S1 Playback", NULL
, "O17"},
903 {"I2S1 Playback", NULL
, "O18"},
904 {"I2S2 Playback", NULL
, "O19"},
905 {"I2S2 Playback", NULL
, "O20"},
906 {"I2S3 Playback", NULL
, "O21"},
907 {"I2S3 Playback", NULL
, "O22"},
908 {"BT Playback", NULL
, "O31"},
910 {"UL1", NULL
, "O00"},
911 {"UL1", NULL
, "O01"},
912 {"UL2", NULL
, "O02"},
913 {"UL2", NULL
, "O03"},
914 {"ULBT", NULL
, "O14"},
916 {"I00", NULL
, "I2S0 Capture"},
917 {"I01", NULL
, "I2S0 Capture"},
918 {"I02", NULL
, "I2S1 Capture"},
919 {"I03", NULL
, "I2S1 Capture"},
920 /* I02,03 link to UL2, also need to open I2S0 */
921 {"I02", "I2S0 Switch", "I2S0 Capture"},
923 {"I26", NULL
, "BT Capture"},
925 {"I12I13", "Multich I2S0 Out Switch", "DLM"},
926 {"I14I15", "Multich I2S1 Out Switch", "DLM"},
927 {"I16I17", "Multich I2S2 Out Switch", "DLM"},
928 {"I18I19", "Multich I2S3 Out Switch", "DLM"},
930 { "I12", NULL
, "I12I13" },
931 { "I13", NULL
, "I12I13" },
932 { "I14", NULL
, "I14I15" },
933 { "I15", NULL
, "I14I15" },
934 { "I16", NULL
, "I16I17" },
935 { "I17", NULL
, "I16I17" },
936 { "I18", NULL
, "I18I19" },
937 { "I19", NULL
, "I18I19" },
939 { "O00", "I00 Switch", "I00" },
940 { "O01", "I01 Switch", "I01" },
941 { "O02", "I02 Switch", "I02" },
942 { "O03", "I03 Switch", "I03" },
943 { "O14", "I26 Switch", "I26" },
944 { "O15", "I12 Switch", "I12" },
945 { "O16", "I13 Switch", "I13" },
946 { "O17", "I14 Switch", "I14" },
947 { "O18", "I15 Switch", "I15" },
948 { "O19", "I16 Switch", "I16" },
949 { "O20", "I17 Switch", "I17" },
950 { "O21", "I18 Switch", "I18" },
951 { "O22", "I19 Switch", "I19" },
952 { "O31", "I35 Switch", "I35" },
955 static int mt2701_afe_pcm_probe(struct snd_soc_component
*component
)
957 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(component
);
959 snd_soc_component_init_regmap(component
, afe
->regmap
);
964 static const struct snd_soc_component_driver mt2701_afe_pcm_dai_component
= {
965 .probe
= mt2701_afe_pcm_probe
,
966 .name
= "mt2701-afe-pcm-dai",
967 .dapm_widgets
= mt2701_afe_pcm_widgets
,
968 .num_dapm_widgets
= ARRAY_SIZE(mt2701_afe_pcm_widgets
),
969 .dapm_routes
= mt2701_afe_pcm_routes
,
970 .num_dapm_routes
= ARRAY_SIZE(mt2701_afe_pcm_routes
),
971 .suspend
= mtk_afe_suspend
,
972 .resume
= mtk_afe_resume
,
975 static const struct mtk_base_memif_data memif_data_array
[MT2701_MEMIF_NUM
] = {
978 .id
= MT2701_MEMIF_DL1
,
979 .reg_ofs_base
= AFE_DL1_BASE
,
980 .reg_ofs_cur
= AFE_DL1_CUR
,
981 .fs_reg
= AFE_DAC_CON1
,
984 .mono_reg
= AFE_DAC_CON3
,
986 .enable_reg
= AFE_DAC_CON0
,
988 .hd_reg
= AFE_MEMIF_HD_CON0
,
990 .agent_disable_reg
= AUDIO_TOP_CON5
,
991 .agent_disable_shift
= 6,
996 .id
= MT2701_MEMIF_DL2
,
997 .reg_ofs_base
= AFE_DL2_BASE
,
998 .reg_ofs_cur
= AFE_DL2_CUR
,
999 .fs_reg
= AFE_DAC_CON1
,
1002 .mono_reg
= AFE_DAC_CON3
,
1004 .enable_reg
= AFE_DAC_CON0
,
1006 .hd_reg
= AFE_MEMIF_HD_CON0
,
1008 .agent_disable_reg
= AUDIO_TOP_CON5
,
1009 .agent_disable_shift
= 7,
1014 .id
= MT2701_MEMIF_DL3
,
1015 .reg_ofs_base
= AFE_DL3_BASE
,
1016 .reg_ofs_cur
= AFE_DL3_CUR
,
1017 .fs_reg
= AFE_DAC_CON1
,
1020 .mono_reg
= AFE_DAC_CON3
,
1022 .enable_reg
= AFE_DAC_CON0
,
1024 .hd_reg
= AFE_MEMIF_HD_CON0
,
1026 .agent_disable_reg
= AUDIO_TOP_CON5
,
1027 .agent_disable_shift
= 8,
1032 .id
= MT2701_MEMIF_DL4
,
1033 .reg_ofs_base
= AFE_DL4_BASE
,
1034 .reg_ofs_cur
= AFE_DL4_CUR
,
1035 .fs_reg
= AFE_DAC_CON1
,
1038 .mono_reg
= AFE_DAC_CON3
,
1040 .enable_reg
= AFE_DAC_CON0
,
1042 .hd_reg
= AFE_MEMIF_HD_CON0
,
1044 .agent_disable_reg
= AUDIO_TOP_CON5
,
1045 .agent_disable_shift
= 9,
1050 .id
= MT2701_MEMIF_DL5
,
1051 .reg_ofs_base
= AFE_DL5_BASE
,
1052 .reg_ofs_cur
= AFE_DL5_CUR
,
1053 .fs_reg
= AFE_DAC_CON1
,
1056 .mono_reg
= AFE_DAC_CON3
,
1058 .enable_reg
= AFE_DAC_CON0
,
1060 .hd_reg
= AFE_MEMIF_HD_CON0
,
1062 .agent_disable_reg
= AUDIO_TOP_CON5
,
1063 .agent_disable_shift
= 10,
1068 .id
= MT2701_MEMIF_DLM
,
1069 .reg_ofs_base
= AFE_DLMCH_BASE
,
1070 .reg_ofs_cur
= AFE_DLMCH_CUR
,
1071 .fs_reg
= AFE_DAC_CON1
,
1076 .enable_reg
= AFE_DAC_CON0
,
1078 .hd_reg
= AFE_MEMIF_PBUF_SIZE
,
1080 .agent_disable_reg
= AUDIO_TOP_CON5
,
1081 .agent_disable_shift
= 12,
1086 .id
= MT2701_MEMIF_UL1
,
1087 .reg_ofs_base
= AFE_VUL_BASE
,
1088 .reg_ofs_cur
= AFE_VUL_CUR
,
1089 .fs_reg
= AFE_DAC_CON2
,
1092 .mono_reg
= AFE_DAC_CON4
,
1094 .enable_reg
= AFE_DAC_CON0
,
1096 .hd_reg
= AFE_MEMIF_HD_CON1
,
1098 .agent_disable_reg
= AUDIO_TOP_CON5
,
1099 .agent_disable_shift
= 0,
1104 .id
= MT2701_MEMIF_UL2
,
1105 .reg_ofs_base
= AFE_UL2_BASE
,
1106 .reg_ofs_cur
= AFE_UL2_CUR
,
1107 .fs_reg
= AFE_DAC_CON2
,
1110 .mono_reg
= AFE_DAC_CON4
,
1112 .enable_reg
= AFE_DAC_CON0
,
1114 .hd_reg
= AFE_MEMIF_HD_CON1
,
1116 .agent_disable_reg
= AUDIO_TOP_CON5
,
1117 .agent_disable_shift
= 1,
1122 .id
= MT2701_MEMIF_UL3
,
1123 .reg_ofs_base
= AFE_UL3_BASE
,
1124 .reg_ofs_cur
= AFE_UL3_CUR
,
1125 .fs_reg
= AFE_DAC_CON2
,
1128 .mono_reg
= AFE_DAC_CON4
,
1130 .enable_reg
= AFE_DAC_CON0
,
1132 .hd_reg
= AFE_MEMIF_HD_CON0
,
1134 .agent_disable_reg
= AUDIO_TOP_CON5
,
1135 .agent_disable_shift
= 2,
1140 .id
= MT2701_MEMIF_UL4
,
1141 .reg_ofs_base
= AFE_UL4_BASE
,
1142 .reg_ofs_cur
= AFE_UL4_CUR
,
1143 .fs_reg
= AFE_DAC_CON2
,
1146 .mono_reg
= AFE_DAC_CON4
,
1148 .enable_reg
= AFE_DAC_CON0
,
1150 .hd_reg
= AFE_MEMIF_HD_CON0
,
1152 .agent_disable_reg
= AUDIO_TOP_CON5
,
1153 .agent_disable_shift
= 3,
1158 .id
= MT2701_MEMIF_UL5
,
1159 .reg_ofs_base
= AFE_UL5_BASE
,
1160 .reg_ofs_cur
= AFE_UL5_CUR
,
1161 .fs_reg
= AFE_DAC_CON2
,
1163 .mono_reg
= AFE_DAC_CON4
,
1166 .enable_reg
= AFE_DAC_CON0
,
1168 .hd_reg
= AFE_MEMIF_HD_CON0
,
1170 .agent_disable_reg
= AUDIO_TOP_CON5
,
1171 .agent_disable_shift
= 4,
1176 .id
= MT2701_MEMIF_DLBT
,
1177 .reg_ofs_base
= AFE_ARB1_BASE
,
1178 .reg_ofs_cur
= AFE_ARB1_CUR
,
1179 .fs_reg
= AFE_DAC_CON3
,
1182 .mono_reg
= AFE_DAC_CON3
,
1184 .enable_reg
= AFE_DAC_CON0
,
1186 .hd_reg
= AFE_MEMIF_HD_CON0
,
1188 .agent_disable_reg
= AUDIO_TOP_CON5
,
1189 .agent_disable_shift
= 13,
1194 .id
= MT2701_MEMIF_ULBT
,
1195 .reg_ofs_base
= AFE_DAI_BASE
,
1196 .reg_ofs_cur
= AFE_DAI_CUR
,
1197 .fs_reg
= AFE_DAC_CON2
,
1202 .enable_reg
= AFE_DAC_CON0
,
1204 .hd_reg
= AFE_MEMIF_HD_CON1
,
1206 .agent_disable_reg
= AUDIO_TOP_CON5
,
1207 .agent_disable_shift
= 16,
1212 static const struct mtk_base_irq_data irq_data
[MT2701_IRQ_ASYS_END
] = {
1214 .id
= MT2701_IRQ_ASYS_IRQ1
,
1215 .irq_cnt_reg
= ASYS_IRQ1_CON
,
1217 .irq_cnt_maskbit
= 0xffffff,
1218 .irq_fs_reg
= ASYS_IRQ1_CON
,
1220 .irq_fs_maskbit
= 0x1f,
1221 .irq_en_reg
= ASYS_IRQ1_CON
,
1223 .irq_clr_reg
= ASYS_IRQ_CLR
,
1227 .id
= MT2701_IRQ_ASYS_IRQ2
,
1228 .irq_cnt_reg
= ASYS_IRQ2_CON
,
1230 .irq_cnt_maskbit
= 0xffffff,
1231 .irq_fs_reg
= ASYS_IRQ2_CON
,
1233 .irq_fs_maskbit
= 0x1f,
1234 .irq_en_reg
= ASYS_IRQ2_CON
,
1236 .irq_clr_reg
= ASYS_IRQ_CLR
,
1240 .id
= MT2701_IRQ_ASYS_IRQ3
,
1241 .irq_cnt_reg
= ASYS_IRQ3_CON
,
1243 .irq_cnt_maskbit
= 0xffffff,
1244 .irq_fs_reg
= ASYS_IRQ3_CON
,
1246 .irq_fs_maskbit
= 0x1f,
1247 .irq_en_reg
= ASYS_IRQ3_CON
,
1249 .irq_clr_reg
= ASYS_IRQ_CLR
,
1254 static const struct mt2701_i2s_data mt2701_i2s_data
[][2] = {
1256 { ASYS_I2SO1_CON
, 0, 0x1f },
1257 { ASYS_I2SIN1_CON
, 0, 0x1f },
1260 { ASYS_I2SO2_CON
, 5, 0x1f },
1261 { ASYS_I2SIN2_CON
, 5, 0x1f },
1264 { ASYS_I2SO3_CON
, 10, 0x1f },
1265 { ASYS_I2SIN3_CON
, 10, 0x1f },
1268 { ASYS_I2SO4_CON
, 15, 0x1f },
1269 { ASYS_I2SIN4_CON
, 15, 0x1f },
1271 /* TODO - extend control registers supported by newer SoCs */
1274 static irqreturn_t
mt2701_asys_isr(int irq_id
, void *dev
)
1277 struct mtk_base_afe
*afe
= dev
;
1278 struct mtk_base_afe_memif
*memif
;
1279 struct mtk_base_afe_irq
*irq
;
1282 regmap_read(afe
->regmap
, ASYS_IRQ_STATUS
, &status
);
1283 regmap_write(afe
->regmap
, ASYS_IRQ_CLR
, status
);
1285 for (id
= 0; id
< MT2701_MEMIF_NUM
; ++id
) {
1286 memif
= &afe
->memif
[id
];
1287 if (memif
->irq_usage
< 0)
1290 irq
= &afe
->irqs
[memif
->irq_usage
];
1291 if (status
& 1 << irq
->irq_data
->irq_clr_shift
)
1292 snd_pcm_period_elapsed(memif
->substream
);
1298 static int mt2701_afe_runtime_suspend(struct device
*dev
)
1300 struct mtk_base_afe
*afe
= dev_get_drvdata(dev
);
1302 return mt2701_afe_disable_clock(afe
);
1305 static int mt2701_afe_runtime_resume(struct device
*dev
)
1307 struct mtk_base_afe
*afe
= dev_get_drvdata(dev
);
1309 return mt2701_afe_enable_clock(afe
);
1312 static int mt2701_afe_pcm_dev_probe(struct platform_device
*pdev
)
1314 struct mtk_base_afe
*afe
;
1315 struct mt2701_afe_private
*afe_priv
;
1319 afe
= devm_kzalloc(&pdev
->dev
, sizeof(*afe
), GFP_KERNEL
);
1323 afe
->platform_priv
= devm_kzalloc(&pdev
->dev
, sizeof(*afe_priv
),
1325 if (!afe
->platform_priv
)
1328 afe_priv
= afe
->platform_priv
;
1329 afe_priv
->soc
= of_device_get_match_data(&pdev
->dev
);
1330 afe
->dev
= &pdev
->dev
;
1333 afe_priv
->i2s_path
= devm_kcalloc(dev
,
1334 afe_priv
->soc
->i2s_num
,
1335 sizeof(struct mt2701_i2s_path
),
1337 if (!afe_priv
->i2s_path
)
1340 irq_id
= platform_get_irq_byname(pdev
, "asys");
1344 ret
= devm_request_irq(dev
, irq_id
, mt2701_asys_isr
,
1345 IRQF_TRIGGER_NONE
, "asys-isr", (void *)afe
);
1347 dev_err(dev
, "could not request_irq for asys-isr\n");
1351 afe
->regmap
= syscon_node_to_regmap(dev
->parent
->of_node
);
1352 if (IS_ERR(afe
->regmap
)) {
1353 dev_err(dev
, "could not get regmap from parent\n");
1354 return PTR_ERR(afe
->regmap
);
1357 mutex_init(&afe
->irq_alloc_lock
);
1359 /* memif initialize */
1360 afe
->memif_size
= MT2701_MEMIF_NUM
;
1361 afe
->memif
= devm_kcalloc(dev
, afe
->memif_size
, sizeof(*afe
->memif
),
1366 for (i
= 0; i
< afe
->memif_size
; i
++) {
1367 afe
->memif
[i
].data
= &memif_data_array
[i
];
1368 afe
->memif
[i
].irq_usage
= -1;
1371 /* irq initialize */
1372 afe
->irqs_size
= MT2701_IRQ_ASYS_END
;
1373 afe
->irqs
= devm_kcalloc(dev
, afe
->irqs_size
, sizeof(*afe
->irqs
),
1378 for (i
= 0; i
< afe
->irqs_size
; i
++)
1379 afe
->irqs
[i
].irq_data
= &irq_data
[i
];
1381 /* I2S initialize */
1382 for (i
= 0; i
< afe_priv
->soc
->i2s_num
; i
++) {
1383 afe_priv
->i2s_path
[i
].i2s_data
[SNDRV_PCM_STREAM_PLAYBACK
] =
1384 &mt2701_i2s_data
[i
][SNDRV_PCM_STREAM_PLAYBACK
];
1385 afe_priv
->i2s_path
[i
].i2s_data
[SNDRV_PCM_STREAM_CAPTURE
] =
1386 &mt2701_i2s_data
[i
][SNDRV_PCM_STREAM_CAPTURE
];
1389 afe
->mtk_afe_hardware
= &mt2701_afe_hardware
;
1390 afe
->memif_fs
= mt2701_memif_fs
;
1391 afe
->irq_fs
= mt2701_irq_fs
;
1392 afe
->reg_back_up_list
= mt2701_afe_backup_list
;
1393 afe
->reg_back_up_list_num
= ARRAY_SIZE(mt2701_afe_backup_list
);
1394 afe
->runtime_resume
= mt2701_afe_runtime_resume
;
1395 afe
->runtime_suspend
= mt2701_afe_runtime_suspend
;
1397 /* initial audio related clock */
1398 ret
= mt2701_init_clock(afe
);
1400 dev_err(dev
, "init clock error\n");
1404 platform_set_drvdata(pdev
, afe
);
1406 pm_runtime_enable(dev
);
1407 if (!pm_runtime_enabled(dev
)) {
1408 ret
= mt2701_afe_runtime_resume(dev
);
1410 goto err_pm_disable
;
1412 pm_runtime_get_sync(dev
);
1414 ret
= devm_snd_soc_register_component(&pdev
->dev
, &mtk_afe_pcm_platform
,
1417 dev_warn(dev
, "err_platform\n");
1421 ret
= devm_snd_soc_register_component(&pdev
->dev
,
1422 &mt2701_afe_pcm_dai_component
,
1423 mt2701_afe_pcm_dais
,
1424 ARRAY_SIZE(mt2701_afe_pcm_dais
));
1426 dev_warn(dev
, "err_dai_component\n");
1433 pm_runtime_put_sync(dev
);
1435 pm_runtime_disable(dev
);
1440 static void mt2701_afe_pcm_dev_remove(struct platform_device
*pdev
)
1442 pm_runtime_put_sync(&pdev
->dev
);
1443 pm_runtime_disable(&pdev
->dev
);
1444 if (!pm_runtime_status_suspended(&pdev
->dev
))
1445 mt2701_afe_runtime_suspend(&pdev
->dev
);
1448 static const struct mt2701_soc_variants mt2701_soc_v1
= {
1452 static const struct mt2701_soc_variants mt2701_soc_v2
= {
1453 .has_one_heart_mode
= true,
1457 static const struct of_device_id mt2701_afe_pcm_dt_match
[] = {
1458 { .compatible
= "mediatek,mt2701-audio", .data
= &mt2701_soc_v1
},
1459 { .compatible
= "mediatek,mt7622-audio", .data
= &mt2701_soc_v2
},
1462 MODULE_DEVICE_TABLE(of
, mt2701_afe_pcm_dt_match
);
1464 static const struct dev_pm_ops mt2701_afe_pm_ops
= {
1465 SET_RUNTIME_PM_OPS(mt2701_afe_runtime_suspend
,
1466 mt2701_afe_runtime_resume
, NULL
)
1469 static struct platform_driver mt2701_afe_pcm_driver
= {
1471 .name
= "mt2701-audio",
1472 .of_match_table
= mt2701_afe_pcm_dt_match
,
1473 .pm
= &mt2701_afe_pm_ops
,
1475 .probe
= mt2701_afe_pcm_dev_probe
,
1476 .remove
= mt2701_afe_pcm_dev_remove
,
1479 module_platform_driver(mt2701_afe_pcm_driver
);
1481 MODULE_DESCRIPTION("Mediatek ALSA SoC AFE platform driver for 2701");
1482 MODULE_AUTHOR("Garlic Tseng <garlic.tseng@mediatek.com>");
1483 MODULE_LICENSE("GPL v2");