Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: mediatek: mt8192: Migrate to mtk_soundcard_common_probe

Add mtk_soundcard_pdata platform data for the MediaTek common sound card
probe mechanism, including a driver/soc-specific probe extension (used
for bits that cannot be commonized hence specific to this driver), and
change the probe function to mtk_soundcard_common_probe.

This is also adding the possibility of specifying the links and routing
with the audio-routing property and (x)-dai-link nodes in device trees
to stop hardcoding machine specific links in the card driver assupported
by the common probe function, but support for legacy device trees is
retained with a legacy_probe function, which is used only in case the
new properties are not found.

Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20240416071410.75620-6-angelogioacchino.delregno@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

AngeloGioacchino Del Regno and committed by
Mark Brown
2d72cbb5 6718e1ed

+91 -73
+91 -73
sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
··· 20 20 #include "../../codecs/rt1015.h" 21 21 #include "../../codecs/rt5682.h" 22 22 #include "../common/mtk-afe-platform-driver.h" 23 + #include "../common/mtk-soc-card.h" 24 + #include "../common/mtk-soundcard-driver.h" 23 25 #include "mt8192-afe-common.h" 24 26 #include "mt8192-afe-clk.h" 25 27 #include "mt8192-afe-gpio.h" ··· 40 38 #define RT1015P_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682" 41 39 #define RT1015P_RT5682S_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682s" 42 40 43 - struct mt8192_mt6359_priv { 44 - struct snd_soc_jack headset_jack; 45 - struct snd_soc_jack hdmi_jack; 41 + enum mt8192_jacks { 42 + MT8192_JACK_HEADSET, 43 + MT8192_JACK_HDMI, 44 + MT8192_JACK_MAX, 46 45 }; 47 46 48 47 /* Headset jack detection DAPM pins */ ··· 326 323 327 324 static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd) 328 325 { 326 + struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 327 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8192_JACK_HEADSET]; 329 328 struct snd_soc_component *cmpnt_afe = 330 329 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 331 330 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 332 331 struct snd_soc_component *cmpnt_codec = 333 332 snd_soc_rtd_to_codec(rtd, 0)->component; 334 - struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card); 335 - struct snd_soc_jack *jack = &priv->headset_jack; 336 333 int ret; 337 334 338 335 ret = mt8192_dai_i2s_set_share(afe, "I2S8", "I2S9"); ··· 362 359 363 360 static int mt8192_mt6359_hdmi_init(struct snd_soc_pcm_runtime *rtd) 364 361 { 362 + struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 363 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8192_JACK_HDMI]; 365 364 struct snd_soc_component *cmpnt_codec = 366 365 snd_soc_rtd_to_codec(rtd, 0)->component; 367 - struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card); 368 366 int ret; 369 367 370 - ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, 371 - &priv->hdmi_jack); 368 + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack); 372 369 if (ret) { 373 370 dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); 374 371 return ret; 375 372 } 376 373 377 - return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); 374 + return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 378 375 } 379 376 380 377 static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, ··· 1139 1136 return 0; 1140 1137 } 1141 1138 1142 - static int mt8192_mt6359_dev_probe(struct platform_device *pdev) 1139 + static int mt8192_mt6359_legacy_probe(struct mtk_soc_card_data *soc_card_data) 1143 1140 { 1144 - struct snd_soc_card *card; 1145 - struct device_node *platform_node, *hdmi_codec, *headset_codec, *speaker_codec; 1146 - int ret, i; 1141 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1142 + struct snd_soc_card *card = card_data->card; 1143 + struct device *dev = card->dev; 1144 + struct device_node *hdmi_codec, *headset_codec, *speaker_codec; 1147 1145 struct snd_soc_dai_link *dai_link; 1148 - struct mt8192_mt6359_priv *priv; 1146 + int ret, i; 1149 1147 1150 - card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev); 1151 - if (!card) 1152 - return -EINVAL; 1153 - card->dev = &pdev->dev; 1154 - 1155 - if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682_OF_NAME)) 1156 - card->name = RT1015P_RT5682_CARD_NAME; 1157 - else if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682S_OF_NAME)) 1158 - card->name = RT1015P_RT5682S_CARD_NAME; 1159 - else 1160 - dev_dbg(&pdev->dev, "No need to set card name\n"); 1161 - 1162 - hdmi_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,hdmi-codec", 0); 1148 + hdmi_codec = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0); 1163 1149 if (!hdmi_codec) 1164 - dev_dbg(&pdev->dev, "The machine has no hdmi-codec\n"); 1150 + dev_dbg(dev, "The machine has no hdmi-codec\n"); 1165 1151 1166 - platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0); 1167 - if (!platform_node) { 1168 - ret = -EINVAL; 1169 - dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n"); 1170 - goto err_platform_node; 1171 - } 1172 - 1173 - speaker_codec = of_get_child_by_name(pdev->dev.of_node, "speaker-codecs"); 1152 + speaker_codec = of_get_child_by_name(dev->of_node, "speaker-codecs"); 1174 1153 if (!speaker_codec) { 1175 1154 ret = -EINVAL; 1176 - dev_err_probe(&pdev->dev, ret, "Property 'speaker-codecs' missing or invalid\n"); 1155 + dev_err_probe(dev, ret, "Property 'speaker-codecs' missing or invalid\n"); 1177 1156 goto err_speaker_codec; 1178 1157 } 1179 1158 1180 - headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec"); 1159 + headset_codec = of_get_child_by_name(dev->of_node, "headset-codec"); 1181 1160 if (!headset_codec) { 1182 1161 ret = -EINVAL; 1183 - dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n"); 1162 + dev_err_probe(dev, ret, "Property 'headset-codec' missing or invalid\n"); 1184 1163 goto err_headset_codec; 1185 1164 } 1186 1165 1187 1166 for_each_card_prelinks(card, i, dai_link) { 1188 1167 ret = mt8192_mt6359_card_set_be_link(card, dai_link, speaker_codec, "I2S3"); 1189 1168 if (ret) { 1190 - dev_err_probe(&pdev->dev, ret, "%s set speaker_codec fail\n", 1169 + dev_err_probe(dev, ret, "%s set speaker_codec fail\n", 1191 1170 dai_link->name); 1192 - goto err_probe; 1171 + break; 1193 1172 } 1194 1173 1195 1174 ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S8"); 1196 1175 if (ret) { 1197 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1176 + dev_err_probe(dev, ret, "%s set headset_codec fail\n", 1198 1177 dai_link->name); 1199 - goto err_probe; 1178 + break; 1200 1179 } 1201 1180 1202 1181 ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S9"); 1203 1182 if (ret) { 1204 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1183 + dev_err_probe(dev, ret, "%s set headset_codec fail\n", 1205 1184 dai_link->name); 1206 - goto err_probe; 1185 + break; 1207 1186 } 1208 1187 1209 1188 if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) { ··· 1196 1211 if (dai_link->num_codecs && dai_link->codecs[0].dai_name && 1197 1212 strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0) 1198 1213 dai_link->ops = &mt8192_rt1015_i2s_ops; 1199 - 1200 - if (!dai_link->platforms->name) 1201 - dai_link->platforms->of_node = platform_node; 1202 1214 } 1203 1215 1204 - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 1205 - if (!priv) { 1206 - ret = -ENOMEM; 1207 - goto err_probe; 1208 - } 1209 - snd_soc_card_set_drvdata(card, priv); 1210 - 1211 - ret = mt8192_afe_gpio_init(&pdev->dev); 1212 - if (ret) { 1213 - dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__); 1214 - goto err_probe; 1215 - } 1216 - 1217 - ret = devm_snd_soc_register_card(&pdev->dev, card); 1218 - if (ret) 1219 - dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__); 1220 - 1221 - err_probe: 1222 1216 of_node_put(headset_codec); 1223 1217 err_headset_codec: 1224 1218 of_node_put(speaker_codec); 1225 1219 err_speaker_codec: 1226 - of_node_put(platform_node); 1227 - err_platform_node: 1228 - of_node_put(hdmi_codec); 1220 + if (hdmi_codec) 1221 + of_node_put(hdmi_codec); 1222 + 1229 1223 return ret; 1230 1224 } 1225 + 1226 + static int mt8192_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) 1227 + { 1228 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1229 + struct snd_soc_card *card = card_data->card; 1230 + int ret; 1231 + 1232 + if (legacy) { 1233 + ret = mt8192_mt6359_legacy_probe(soc_card_data); 1234 + if (ret) 1235 + return ret; 1236 + } else { 1237 + struct snd_soc_dai_link *dai_link; 1238 + int i; 1239 + 1240 + for_each_card_prelinks(card, i, dai_link) 1241 + if (dai_link->num_codecs && dai_link->codecs[0].dai_name && 1242 + strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0) 1243 + dai_link->ops = &mt8192_rt1015_i2s_ops; 1244 + } 1245 + 1246 + ret = mt8192_afe_gpio_init(card->dev); 1247 + if (ret) 1248 + return dev_err_probe(card->dev, ret, "%s init gpio error\n", __func__); 1249 + 1250 + return 0; 1251 + } 1252 + 1253 + static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015_rt5682_pdata = { 1254 + .card_name = RT1015_RT5682_CARD_NAME, 1255 + .card_data = &(struct mtk_platform_card_data) { 1256 + .card = &mt8192_mt6359_rt1015_rt5682_card, 1257 + .num_jacks = MT8192_JACK_MAX, 1258 + }, 1259 + .soc_probe = mt8192_mt6359_soc_card_probe 1260 + }; 1261 + 1262 + static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015p_rt5682_pdata = { 1263 + .card_name = RT1015P_RT5682_CARD_NAME, 1264 + .card_data = &(struct mtk_platform_card_data) { 1265 + .card = &mt8192_mt6359_rt1015p_rt5682x_card, 1266 + .num_jacks = MT8192_JACK_MAX, 1267 + }, 1268 + .soc_probe = mt8192_mt6359_soc_card_probe 1269 + }; 1270 + 1271 + static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015p_rt5682s_pdata = { 1272 + .card_name = RT1015P_RT5682S_CARD_NAME, 1273 + .card_data = &(struct mtk_platform_card_data) { 1274 + .card = &mt8192_mt6359_rt1015p_rt5682x_card, 1275 + .num_jacks = MT8192_JACK_MAX, 1276 + }, 1277 + .soc_probe = mt8192_mt6359_soc_card_probe 1278 + }; 1231 1279 1232 1280 #ifdef CONFIG_OF 1233 1281 static const struct of_device_id mt8192_mt6359_dt_match[] = { 1234 1282 { 1235 1283 .compatible = RT1015_RT5682_OF_NAME, 1236 - .data = &mt8192_mt6359_rt1015_rt5682_card, 1284 + .data = &mt8192_mt6359_rt1015_rt5682_pdata, 1237 1285 }, 1238 1286 { 1239 1287 .compatible = RT1015P_RT5682_OF_NAME, 1240 - .data = &mt8192_mt6359_rt1015p_rt5682x_card, 1288 + .data = &mt8192_mt6359_rt1015p_rt5682_pdata, 1241 1289 }, 1242 1290 { 1243 1291 .compatible = RT1015P_RT5682S_OF_NAME, 1244 - .data = &mt8192_mt6359_rt1015p_rt5682x_card, 1292 + .data = &mt8192_mt6359_rt1015p_rt5682s_pdata, 1245 1293 }, 1246 1294 {} 1247 1295 }; ··· 1294 1276 #endif 1295 1277 .pm = &mt8192_mt6359_pm_ops, 1296 1278 }, 1297 - .probe = mt8192_mt6359_dev_probe, 1279 + .probe = mtk_soundcard_common_probe, 1298 1280 }; 1299 1281 1300 1282 module_platform_driver(mt8192_mt6359_driver);