Skip to content

Commit 8c2d238

Browse files
committed
ASoC: mediatek: Remove redundant code and add
Merge series from Maso Huang <maso.huang@mediatek.com>: Add support for sample rate checking on the MT7986.
2 parents 91e174f + 0e20929 commit 8c2d238

2 files changed

Lines changed: 31 additions & 35 deletions

File tree

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,27 @@ static int mtk_dai_etdm_hw_params(struct snd_pcm_substream *substream,
237237
struct snd_pcm_hw_params *params,
238238
struct snd_soc_dai *dai)
239239
{
240+
unsigned int rate = params_rate(params);
240241
struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
241242

242-
mtk_dai_etdm_config(afe, params, dai, SNDRV_PCM_STREAM_PLAYBACK);
243-
mtk_dai_etdm_config(afe, params, dai, SNDRV_PCM_STREAM_CAPTURE);
244-
245-
return 0;
243+
switch (rate) {
244+
case 8000:
245+
case 12000:
246+
case 16000:
247+
case 24000:
248+
case 32000:
249+
case 48000:
250+
case 96000:
251+
case 192000:
252+
mtk_dai_etdm_config(afe, params, dai, SNDRV_PCM_STREAM_PLAYBACK);
253+
mtk_dai_etdm_config(afe, params, dai, SNDRV_PCM_STREAM_CAPTURE);
254+
return 0;
255+
default:
256+
dev_err(afe->dev,
257+
"Sample rate %d invalid. Supported rates: 8/12/16/24/32/48/96/192 kHz\n",
258+
rate);
259+
return -EINVAL;
260+
}
246261
}
247262

248263
static int mtk_dai_etdm_trigger(struct snd_pcm_substream *substream, int cmd,

sound/soc/mediatek/mt7986/mt7986-wm8960.c

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
#include "mt7986-afe-common.h"
1414

15-
struct mt7986_wm8960_priv {
16-
struct device_node *platform_node;
17-
struct device_node *codec_node;
18-
};
19-
2015
static const struct snd_soc_dapm_widget mt7986_wm8960_widgets[] = {
2116
SND_SOC_DAPM_HP("Headphone", NULL),
2217
SND_SOC_DAPM_MIC("AMIC", NULL),
@@ -92,20 +87,18 @@ static int mt7986_wm8960_machine_probe(struct platform_device *pdev)
9287
struct snd_soc_card *card = &mt7986_wm8960_card;
9388
struct snd_soc_dai_link *dai_link;
9489
struct device_node *platform, *codec;
95-
struct mt7986_wm8960_priv *priv;
90+
struct device_node *platform_dai_node, *codec_dai_node;
9691
int ret, i;
9792

98-
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
99-
if (!priv)
100-
return -ENOMEM;
93+
card->dev = &pdev->dev;
10194

10295
platform = of_get_child_by_name(pdev->dev.of_node, "platform");
10396

10497
if (platform) {
105-
priv->platform_node = of_parse_phandle(platform, "sound-dai", 0);
98+
platform_dai_node = of_parse_phandle(platform, "sound-dai", 0);
10699
of_node_put(platform);
107100

108-
if (!priv->platform_node) {
101+
if (!platform_dai_node) {
109102
dev_err(&pdev->dev, "Failed to parse platform/sound-dai property\n");
110103
return -EINVAL;
111104
}
@@ -117,32 +110,30 @@ static int mt7986_wm8960_machine_probe(struct platform_device *pdev)
117110
for_each_card_prelinks(card, i, dai_link) {
118111
if (dai_link->platforms->name)
119112
continue;
120-
dai_link->platforms->of_node = priv->platform_node;
113+
dai_link->platforms->of_node = platform_dai_node;
121114
}
122115

123-
card->dev = &pdev->dev;
124-
125116
codec = of_get_child_by_name(pdev->dev.of_node, "codec");
126117

127118
if (codec) {
128-
priv->codec_node = of_parse_phandle(codec, "sound-dai", 0);
119+
codec_dai_node = of_parse_phandle(codec, "sound-dai", 0);
129120
of_node_put(codec);
130121

131-
if (!priv->codec_node) {
132-
of_node_put(priv->platform_node);
122+
if (!codec_dai_node) {
123+
of_node_put(platform_dai_node);
133124
dev_err(&pdev->dev, "Failed to parse codec/sound-dai property\n");
134125
return -EINVAL;
135126
}
136127
} else {
137-
of_node_put(priv->platform_node);
128+
of_node_put(platform_dai_node);
138129
dev_err(&pdev->dev, "Property 'codec' missing or invalid\n");
139130
return -EINVAL;
140131
}
141132

142133
for_each_card_prelinks(card, i, dai_link) {
143134
if (dai_link->codecs->name)
144135
continue;
145-
dai_link->codecs->of_node = priv->codec_node;
136+
dai_link->codecs->of_node = codec_dai_node;
146137
}
147138

148139
ret = snd_soc_of_parse_audio_routing(card, "audio-routing");
@@ -158,20 +149,11 @@ static int mt7986_wm8960_machine_probe(struct platform_device *pdev)
158149
}
159150

160151
err_of_node_put:
161-
of_node_put(priv->codec_node);
162-
of_node_put(priv->platform_node);
152+
of_node_put(platform_dai_node);
153+
of_node_put(codec_dai_node);
163154
return ret;
164155
}
165156

166-
static void mt7986_wm8960_machine_remove(struct platform_device *pdev)
167-
{
168-
struct snd_soc_card *card = platform_get_drvdata(pdev);
169-
struct mt7986_wm8960_priv *priv = snd_soc_card_get_drvdata(card);
170-
171-
of_node_put(priv->codec_node);
172-
of_node_put(priv->platform_node);
173-
}
174-
175157
static const struct of_device_id mt7986_wm8960_machine_dt_match[] = {
176158
{.compatible = "mediatek,mt7986-wm8960-sound"},
177159
{ /* sentinel */ }
@@ -184,7 +166,6 @@ static struct platform_driver mt7986_wm8960_machine = {
184166
.of_match_table = mt7986_wm8960_machine_dt_match,
185167
},
186168
.probe = mt7986_wm8960_machine_probe,
187-
.remove_new = mt7986_wm8960_machine_remove,
188169
};
189170

190171
module_platform_driver(mt7986_wm8960_machine);

0 commit comments

Comments
 (0)