blob: f097f4a143a10d775e59b2d267aa5be044308b41 [file] [log] [blame]
developer5d148cb2023-06-02 13:08:11 +08001From 35cc92b8996980021f881a202b8e1233ca41eb0d Mon Sep 17 00:00:00 2001
2From: Sam Shih <sam.shih@mediatek.com>
3Date: Fri, 2 Jun 2023 13:06:08 +0800
4Subject: [PATCH]
5 [slow-speed-io][999-2151-sound-refine-hw-params-and-hw-prepare.patch]
6
7---
8 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 143 +++++++++++----------
9 1 file changed, 77 insertions(+), 66 deletions(-)
10
11diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
12index 309dc1ef6..e761cb66b 100644
developerbe797a32021-12-16 16:56:09 +080013--- a/sound/soc/mediatek/common/mtk-afe-fe-dai.c
14+++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
15@@ -6,11 +6,13 @@
16 * Author: Garlic Tseng <garlic.tseng@mediatek.com>
17 */
18
19+#include <linux/io.h>
20 #include <linux/module.h>
21 #include <linux/pm_runtime.h>
22 #include <linux/regmap.h>
23 #include <sound/soc.h>
24 #include "mtk-afe-platform-driver.h"
25+#include <sound/pcm_params.h>
26 #include "mtk-afe-fe-dai.h"
27 #include "mtk-base-afe.h"
28
developer5d148cb2023-06-02 13:08:11 +080029@@ -120,50 +122,64 @@ int mtk_afe_fe_hw_params(struct snd_pcm_substream *substream,
developerbe797a32021-12-16 16:56:09 +080030 {
31 struct snd_soc_pcm_runtime *rtd = substream->private_data;
32 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
33- struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
34- int msb_at_bit33 = 0;
35- int ret, fs = 0;
36+ int id = rtd->cpu_dai->id;
37+ struct mtk_base_afe_memif *memif = &afe->memif[id];
38+ int ret;
39+ unsigned int channels = params_channels(params);
40+ unsigned int rate = params_rate(params);
41+ snd_pcm_format_t format = params_format(params);
42
43 ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
44 if (ret < 0)
45 return ret;
46
47- msb_at_bit33 = upper_32_bits(substream->runtime->dma_addr) ? 1 : 0;
48- memif->phys_buf_addr = lower_32_bits(substream->runtime->dma_addr);
49- memif->buffer_size = substream->runtime->dma_bytes;
50-
51- /* start */
52- mtk_regmap_write(afe->regmap, memif->data->reg_ofs_base,
53- memif->phys_buf_addr);
54- /* end */
55- mtk_regmap_write(afe->regmap,
56- memif->data->reg_ofs_base + AFE_BASE_END_OFFSET,
57- memif->phys_buf_addr + memif->buffer_size - 1);
58-
59- /* set MSB to 33-bit */
60- mtk_regmap_update_bits(afe->regmap, memif->data->msb_reg,
61- 1, msb_at_bit33, memif->data->msb_shift);
62+ if (afe->request_dram_resource)
63+ afe->request_dram_resource(afe->dev);
developer5d148cb2023-06-02 13:08:11 +080064+
developerbe797a32021-12-16 16:56:09 +080065+ dev_dbg(afe->dev, "%s(), %s, ch %d, rate %d, fmt %d, dma_addr %pad, dma_area %p, dma_bytes 0x%zx\n",
66+ __func__, memif->data->name,
67+ channels, rate, format,
68+ &substream->runtime->dma_addr,
69+ substream->runtime->dma_area,
70+ substream->runtime->dma_bytes);
71+
72+ memset_io(substream->runtime->dma_area, 0,
73+ substream->runtime->dma_bytes);
74+
75+ /* set addr */
76+ ret = mtk_memif_set_addr(afe, id,
77+ substream->runtime->dma_area,
78+ substream->runtime->dma_addr,
79+ substream->runtime->dma_bytes);
80+ if (ret) {
81+ dev_err(afe->dev, "%s(), error, id %d, set addr, ret %d\n",
82+ __func__, id, ret);
83+ return ret;
84+ }
85
developer5d148cb2023-06-02 13:08:11 +080086 /* set channel */
87- if (memif->data->mono_shift >= 0) {
88- unsigned int mono = (params_channels(params) == 1) ? 1 : 0;
89-
developerbe797a32021-12-16 16:56:09 +080090- mtk_regmap_update_bits(afe->regmap, memif->data->mono_reg,
91- 1, mono, memif->data->mono_shift);
developerbe797a32021-12-16 16:56:09 +080092+ ret = mtk_memif_set_channel(afe, id, channels);
93+ if (ret) {
94+ dev_err(afe->dev, "%s(), error, id %d, set channel %d, ret %d\n",
95+ __func__, id, channels, ret);
96+ return ret;
97 }
98
99 /* set rate */
100- if (memif->data->fs_shift < 0)
101- return 0;
102-
103- fs = afe->memif_fs(substream, params_rate(params));
104-
105- if (fs < 0)
106- return -EINVAL;
107+ ret = mtk_memif_set_rate_substream(substream, id, rate);
108+ if (ret) {
109+ dev_err(afe->dev, "%s(), error, id %d, set rate %d, ret %d\n",
110+ __func__, id, rate, ret);
111+ return ret;
112+ }
113
114- mtk_regmap_update_bits(afe->regmap, memif->data->fs_reg,
115- memif->data->fs_maskbit, fs,
116- memif->data->fs_shift);
117+ /* set format */
118+ ret = mtk_memif_set_format(afe, id, format);
119+ if (ret) {
120+ dev_err(afe->dev, "%s(), error, id %d, set format %d, ret %d\n",
121+ __func__, id, format, ret);
122+ return ret;
123+ }
124
125 return 0;
126 }
developer5d148cb2023-06-02 13:08:11 +0800127@@ -172,6 +188,11 @@ EXPORT_SYMBOL_GPL(mtk_afe_fe_hw_params);
developerbe797a32021-12-16 16:56:09 +0800128 int mtk_afe_fe_hw_free(struct snd_pcm_substream *substream,
129 struct snd_soc_dai *dai)
130 {
131+ struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
132+
133+ if (afe->release_dram_resource)
134+ afe->release_dram_resource(afe->dev);
135+
136 return snd_pcm_lib_free_pages(substream);
137 }
138 EXPORT_SYMBOL_GPL(mtk_afe_fe_hw_free);
developer5d148cb2023-06-02 13:08:11 +0800139@@ -182,20 +203,25 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,
developerbe797a32021-12-16 16:56:09 +0800140 struct snd_soc_pcm_runtime *rtd = substream->private_data;
141 struct snd_pcm_runtime * const runtime = substream->runtime;
142 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
143- struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
144+ int id = rtd->cpu_dai->id;
145+ struct mtk_base_afe_memif *memif = &afe->memif[id];
146 struct mtk_base_afe_irq *irqs = &afe->irqs[memif->irq_usage];
147 const struct mtk_base_irq_data *irq_data = irqs->irq_data;
148 unsigned int counter = runtime->period_size;
149 int fs;
150+ int ret;
151
152 dev_dbg(afe->dev, "%s %s cmd=%d\n", __func__, memif->data->name, cmd);
153
154 switch (cmd) {
155 case SNDRV_PCM_TRIGGER_START:
156 case SNDRV_PCM_TRIGGER_RESUME:
157- mtk_regmap_update_bits(afe->regmap,
158- memif->data->enable_reg,
159- 1, 1, memif->data->enable_shift);
160+ ret = mtk_memif_set_enable(afe, id);
161+ if (ret) {
162+ dev_err(afe->dev, "%s(), error, id %d, memif enable, ret %d\n",
163+ __func__, id, ret);
164+ return ret;
165+ }
166
167 /* set irq counter */
168 mtk_regmap_update_bits(afe->regmap, irq_data->irq_cnt_reg,
developer5d148cb2023-06-02 13:08:11 +0800169@@ -219,15 +245,19 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,
developerbe797a32021-12-16 16:56:09 +0800170 return 0;
171 case SNDRV_PCM_TRIGGER_STOP:
172 case SNDRV_PCM_TRIGGER_SUSPEND:
173- mtk_regmap_update_bits(afe->regmap, memif->data->enable_reg,
174- 1, 0, memif->data->enable_shift);
175+ ret = mtk_memif_set_disable(afe, id);
176+ if (ret) {
177+ dev_err(afe->dev, "%s(), error, id %d, memif enable, ret %d\n",
178+ __func__, id, ret);
179+ }
180+
181 /* disable interrupt */
182 mtk_regmap_update_bits(afe->regmap, irq_data->irq_en_reg,
183 1, 0, irq_data->irq_en_shift);
184 /* and clear pending IRQ */
185 mtk_regmap_write(afe->regmap, irq_data->irq_clr_reg,
186 1 << irq_data->irq_clr_shift);
187- return 0;
188+ return ret;
189 default:
190 return -EINVAL;
191 }
developer5d148cb2023-06-02 13:08:11 +0800192@@ -239,34 +269,15 @@ int mtk_afe_fe_prepare(struct snd_pcm_substream *substream,
developerbe797a32021-12-16 16:56:09 +0800193 {
194 struct snd_soc_pcm_runtime *rtd = substream->private_data;
195 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
196- struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
197- int hd_audio = 0;
198- int hd_align = 0;
199+ int id = rtd->cpu_dai->id;
200+ int pbuf_size;
201
202- /* set hd mode */
203- switch (substream->runtime->format) {
204- case SNDRV_PCM_FORMAT_S16_LE:
205- hd_audio = 0;
206- break;
207- case SNDRV_PCM_FORMAT_S32_LE:
208- hd_audio = 1;
209- hd_align = 1;
210- break;
211- case SNDRV_PCM_FORMAT_S24_LE:
212- hd_audio = 1;
213- break;
214- default:
215- dev_err(afe->dev, "%s() error: unsupported format %d\n",
216- __func__, substream->runtime->format);
217- break;
218+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
219+ if (afe->get_memif_pbuf_size) {
220+ pbuf_size = afe->get_memif_pbuf_size(substream);
221+ mtk_memif_set_pbuf_size(afe, id, pbuf_size);
222+ }
223 }
224-
225- mtk_regmap_update_bits(afe->regmap, memif->data->hd_reg,
226- 1, hd_audio, memif->data->hd_shift);
227-
228- mtk_regmap_update_bits(afe->regmap, memif->data->hd_align_reg,
229- 1, hd_align, memif->data->hd_align_mshift);
230-
231 return 0;
232 }
233 EXPORT_SYMBOL_GPL(mtk_afe_fe_prepare);
developer5d148cb2023-06-02 13:08:11 +0800234--
2352.34.1
236