1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * MediaTek ALSA SoC Audio DAI ADDA Common
4 *
5 * Copyright (c) 2021 MediaTek Inc.
6 * Copyright (c) 2024 Collabora Ltd.
7 * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
8 */
9
10 #include <linux/delay.h>
11 #include <linux/dev_printk.h>
12
13 #include "mtk-base-afe.h"
14 #include "mtk-dai-adda-common.h"
15
mtk_adda_dl_rate_transform(struct mtk_base_afe * afe,u32 rate)16 unsigned int mtk_adda_dl_rate_transform(struct mtk_base_afe *afe, u32 rate)
17 {
18 switch (rate) {
19 case 8000:
20 return MTK_AFE_ADDA_DL_RATE_8K;
21 case 11025:
22 return MTK_AFE_ADDA_DL_RATE_11K;
23 case 12000:
24 return MTK_AFE_ADDA_DL_RATE_12K;
25 case 16000:
26 return MTK_AFE_ADDA_DL_RATE_16K;
27 case 22050:
28 return MTK_AFE_ADDA_DL_RATE_22K;
29 case 24000:
30 return MTK_AFE_ADDA_DL_RATE_24K;
31 case 32000:
32 return MTK_AFE_ADDA_DL_RATE_32K;
33 case 44100:
34 return MTK_AFE_ADDA_DL_RATE_44K;
35 case 48000:
36 return MTK_AFE_ADDA_DL_RATE_48K;
37 case 96000:
38 return MTK_AFE_ADDA_DL_RATE_96K;
39 case 192000:
40 return MTK_AFE_ADDA_DL_RATE_192K;
41 default:
42 dev_info(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n",
43 __func__, rate);
44 return MTK_AFE_ADDA_DL_RATE_48K;
45 }
46 }
47 EXPORT_SYMBOL_GPL(mtk_adda_dl_rate_transform);
48
mtk_adda_ul_rate_transform(struct mtk_base_afe * afe,u32 rate)49 unsigned int mtk_adda_ul_rate_transform(struct mtk_base_afe *afe, u32 rate)
50 {
51 switch (rate) {
52 case 8000:
53 return MTK_AFE_ADDA_UL_RATE_8K;
54 case 16000:
55 return MTK_AFE_ADDA_UL_RATE_16K;
56 case 32000:
57 return MTK_AFE_ADDA_UL_RATE_32K;
58 case 48000:
59 return MTK_AFE_ADDA_UL_RATE_48K;
60 case 96000:
61 return MTK_AFE_ADDA_UL_RATE_96K;
62 case 192000:
63 return MTK_AFE_ADDA_UL_RATE_192K;
64 default:
65 dev_info(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n",
66 __func__, rate);
67 return MTK_AFE_ADDA_UL_RATE_48K;
68 }
69 }
70 EXPORT_SYMBOL_GPL(mtk_adda_ul_rate_transform);
71