1 // SPDX-License-Identifier: GPL-2.0
3 // MediaTek ALSA SoC Audio Control
5 // Copyright (c) 2020 MediaTek Inc.
6 // Author: Shane Chien <shane.chien@mediatek.com>
9 #include <linux/pm_runtime.h>
11 #include "mt8192-afe-common.h"
17 MTK_AFE_RATE_384K
= 3,
21 MTK_AFE_RATE_352K
= 7,
24 MTK_AFE_RATE_48K
= 10,
25 MTK_AFE_RATE_88K
= 11,
26 MTK_AFE_RATE_96K
= 12,
27 MTK_AFE_RATE_176K
= 13,
28 MTK_AFE_RATE_192K
= 14,
29 MTK_AFE_RATE_260K
= 15,
33 MTK_AFE_DAI_MEMIF_RATE_8K
= 0,
34 MTK_AFE_DAI_MEMIF_RATE_16K
= 1,
35 MTK_AFE_DAI_MEMIF_RATE_32K
= 2,
36 MTK_AFE_DAI_MEMIF_RATE_48K
= 3,
40 MTK_AFE_PCM_RATE_8K
= 0,
41 MTK_AFE_PCM_RATE_16K
= 1,
42 MTK_AFE_PCM_RATE_32K
= 2,
43 MTK_AFE_PCM_RATE_48K
= 3,
46 unsigned int mt8192_general_rate_transform(struct device
*dev
,
51 return MTK_AFE_RATE_8K
;
53 return MTK_AFE_RATE_11K
;
55 return MTK_AFE_RATE_12K
;
57 return MTK_AFE_RATE_16K
;
59 return MTK_AFE_RATE_22K
;
61 return MTK_AFE_RATE_24K
;
63 return MTK_AFE_RATE_32K
;
65 return MTK_AFE_RATE_44K
;
67 return MTK_AFE_RATE_48K
;
69 return MTK_AFE_RATE_88K
;
71 return MTK_AFE_RATE_96K
;
73 return MTK_AFE_RATE_176K
;
75 return MTK_AFE_RATE_192K
;
77 return MTK_AFE_RATE_260K
;
79 return MTK_AFE_RATE_352K
;
81 return MTK_AFE_RATE_384K
;
83 dev_warn(dev
, "%s(), rate %u invalid, use %d!!!\n",
85 rate
, MTK_AFE_RATE_48K
);
86 return MTK_AFE_RATE_48K
;
90 static unsigned int dai_memif_rate_transform(struct device
*dev
,
95 return MTK_AFE_DAI_MEMIF_RATE_8K
;
97 return MTK_AFE_DAI_MEMIF_RATE_16K
;
99 return MTK_AFE_DAI_MEMIF_RATE_32K
;
101 return MTK_AFE_DAI_MEMIF_RATE_48K
;
103 dev_warn(dev
, "%s(), rate %u invalid, use %d!!!\n",
105 rate
, MTK_AFE_DAI_MEMIF_RATE_16K
);
106 return MTK_AFE_DAI_MEMIF_RATE_16K
;
110 static unsigned int pcm_rate_transform(struct device
*dev
,
115 return MTK_AFE_PCM_RATE_8K
;
117 return MTK_AFE_PCM_RATE_16K
;
119 return MTK_AFE_PCM_RATE_32K
;
121 return MTK_AFE_PCM_RATE_48K
;
123 dev_warn(dev
, "%s(), rate %u invalid, use %d!!!\n",
125 rate
, MTK_AFE_PCM_RATE_32K
);
126 return MTK_AFE_PCM_RATE_32K
;
130 unsigned int mt8192_rate_transform(struct device
*dev
,
131 unsigned int rate
, int aud_blk
)
134 case MT8192_MEMIF_DAI
:
135 case MT8192_MEMIF_MOD_DAI
:
136 return dai_memif_rate_transform(dev
, rate
);
137 case MT8192_DAI_PCM_1
:
138 case MT8192_DAI_PCM_2
:
139 return pcm_rate_transform(dev
, rate
);
141 return mt8192_general_rate_transform(dev
, rate
);
145 int mt8192_dai_set_priv(struct mtk_base_afe
*afe
, int id
,
146 int priv_size
, const void *priv_data
)
148 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
151 temp_data
= devm_kzalloc(afe
->dev
,
158 memcpy(temp_data
, priv_data
, priv_size
);
160 afe_priv
->dai_priv
[id
] = temp_data
;