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: mt8186: 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-7-angelogioacchino.delregno@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

AngeloGioacchino Del Regno and committed by
Mark Brown
44a53c8e 2d72cbb5

+99 -127
+99 -127
sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c
··· 21 21 #include "../common/mtk-afe-platform-driver.h" 22 22 #include "../common/mtk-dsp-sof-common.h" 23 23 #include "../common/mtk-soc-card.h" 24 + #include "../common/mtk-soundcard-driver.h" 24 25 #include "mt8186-afe-common.h" 25 26 #include "mt8186-afe-clk.h" 26 27 #include "mt8186-afe-gpio.h" ··· 39 38 #define SOF_DMA_UL2 "SOF_DMA_UL2" 40 39 41 40 struct mt8186_mt6366_rt1019_rt5682s_priv { 42 - struct snd_soc_jack headset_jack, hdmi_jack; 43 41 struct gpio_desc *dmic_sel; 44 42 int dmic_switch; 43 + }; 44 + 45 + enum mt8186_jacks { 46 + MT8186_JACK_HEADSET, 47 + MT8186_JACK_HDMI, 48 + MT8186_JACK_MAX, 45 49 }; 46 50 47 51 /* Headset jack detection DAPM pins */ ··· 171 165 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 172 166 struct mtk_soc_card_data *soc_card_data = 173 167 snd_soc_card_get_drvdata(rtd->card); 174 - struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 175 - struct snd_soc_jack *jack = &priv->headset_jack; 168 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8186_JACK_HEADSET]; 176 169 struct snd_soc_component *cmpnt_codec = 177 170 snd_soc_rtd_to_codec(rtd, 0)->component; 178 171 int ret; ··· 262 257 snd_soc_rtd_to_codec(rtd, 0)->component; 263 258 struct mtk_soc_card_data *soc_card_data = 264 259 snd_soc_card_get_drvdata(rtd->card); 265 - struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 260 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8186_JACK_HDMI]; 266 261 int ret; 267 262 268 263 ret = mt8186_dai_i2s_set_share(afe, "I2S2", "I2S3"); ··· 271 266 return ret; 272 267 } 273 268 274 - ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, &priv->hdmi_jack); 269 + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack); 275 270 if (ret) { 276 271 dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); 277 272 return ret; 278 273 } 279 274 280 - return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); 275 + return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 281 276 } 282 277 283 278 static int mt8186_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, ··· 1139 1134 .num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf), 1140 1135 }; 1141 1136 1142 - static int mt8186_mt6366_rt1019_rt5682s_dev_probe(struct platform_device *pdev) 1137 + static int mt8186_mt6366_legacy_probe(struct mtk_soc_card_data *soc_card_data) 1143 1138 { 1144 - struct snd_soc_card *card; 1139 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1140 + struct snd_soc_card *card = card_data->card; 1141 + struct device *dev = card->dev; 1145 1142 struct snd_soc_dai_link *dai_link; 1146 - struct mtk_soc_card_data *soc_card_data; 1147 - struct mt8186_mt6366_rt1019_rt5682s_priv *mach_priv; 1148 - struct device_node *platform_node, *headset_codec, *playback_codec, *adsp_node; 1149 - int sof_on = 0; 1143 + struct device_node *headset_codec, *playback_codec; 1150 1144 int ret, i; 1151 1145 1152 - card = (struct snd_soc_card *)device_get_match_data(&pdev->dev); 1153 - if (!card) 1154 - return -EINVAL; 1155 - card->dev = &pdev->dev; 1146 + playback_codec = of_get_child_by_name(dev->of_node, "playback-codecs"); 1147 + if (!playback_codec) 1148 + return dev_err_probe(dev, -EINVAL, 1149 + "Property 'playback-codecs' missing or invalid\n"); 1156 1150 1157 - soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*soc_card_data), GFP_KERNEL); 1158 - if (!soc_card_data) 1159 - return -ENOMEM; 1160 - mach_priv = devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL); 1161 - if (!mach_priv) 1162 - return -ENOMEM; 1163 - 1164 - soc_card_data->mach_priv = mach_priv; 1165 - 1166 - mach_priv->dmic_sel = devm_gpiod_get_optional(&pdev->dev, 1167 - "dmic", GPIOD_OUT_LOW); 1168 - if (IS_ERR(mach_priv->dmic_sel)) { 1169 - dev_err(&pdev->dev, "DMIC gpio failed err=%ld\n", 1170 - PTR_ERR(mach_priv->dmic_sel)); 1171 - return PTR_ERR(mach_priv->dmic_sel); 1172 - } 1173 - 1174 - adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); 1175 - if (adsp_node) { 1176 - struct mtk_sof_priv *sof_priv; 1177 - 1178 - sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); 1179 - if (!sof_priv) { 1180 - ret = -ENOMEM; 1181 - goto err_adsp_node; 1182 - } 1183 - sof_priv->conn_streams = g_sof_conn_streams; 1184 - sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams); 1185 - sof_priv->sof_dai_link_fixup = mt8186_sof_dai_link_fixup; 1186 - soc_card_data->sof_priv = sof_priv; 1187 - card->probe = mtk_sof_card_probe; 1188 - card->late_probe = mtk_sof_card_late_probe; 1189 - if (!card->topology_shortname_created) { 1190 - snprintf(card->topology_shortname, 32, "sof-%s", card->name); 1191 - card->topology_shortname_created = true; 1192 - } 1193 - card->name = card->topology_shortname; 1194 - sof_on = 1; 1195 - } else { 1196 - dev_dbg(&pdev->dev, "Probe without adsp\n"); 1197 - } 1198 - 1199 - if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { 1200 - ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, 1201 - "mediatek,dai-link", 1202 - mt8186_mt6366_rt1019_rt5682s_dai_links, 1203 - ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links)); 1204 - if (ret) { 1205 - dev_dbg(&pdev->dev, "Parse dai-link fail\n"); 1206 - goto err_adsp_node; 1207 - } 1208 - } else { 1209 - if (!sof_on) 1210 - card->num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links) 1211 - - ARRAY_SIZE(g_sof_conn_streams); 1212 - } 1213 - 1214 - platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0); 1215 - if (!platform_node) { 1216 - ret = -EINVAL; 1217 - dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n"); 1218 - goto err_platform_node; 1219 - } 1220 - 1221 - playback_codec = of_get_child_by_name(pdev->dev.of_node, "playback-codecs"); 1222 - if (!playback_codec) { 1223 - ret = -EINVAL; 1224 - dev_err_probe(&pdev->dev, ret, "Property 'playback-codecs' missing or invalid\n"); 1225 - goto err_playback_codec; 1226 - } 1227 - 1228 - headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec"); 1151 + headset_codec = of_get_child_by_name(dev->of_node, "headset-codec"); 1229 1152 if (!headset_codec) { 1230 - ret = -EINVAL; 1231 - dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n"); 1232 - goto err_headset_codec; 1153 + of_node_put(playback_codec); 1154 + return dev_err_probe(dev, -EINVAL, 1155 + "Property 'headset-codec' missing or invalid\n"); 1233 1156 } 1234 1157 1235 1158 for_each_card_prelinks(card, i, dai_link) { 1236 1159 ret = mt8186_mt6366_card_set_be_link(card, dai_link, playback_codec, "I2S3"); 1237 1160 if (ret) { 1238 - dev_err_probe(&pdev->dev, ret, "%s set playback_codec fail\n", 1161 + dev_err_probe(dev, ret, "%s set playback_codec fail\n", 1239 1162 dai_link->name); 1240 - goto err_probe; 1163 + break; 1241 1164 } 1242 1165 1243 1166 ret = mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I2S0"); 1244 1167 if (ret) { 1245 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1168 + dev_err_probe(dev, ret, "%s set headset_codec fail\n", 1246 1169 dai_link->name); 1247 - goto err_probe; 1170 + break; 1248 1171 } 1249 1172 1250 1173 ret = mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I2S1"); 1251 1174 if (ret) { 1252 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1175 + dev_err_probe(dev, ret, "%s set headset_codec fail\n", 1253 1176 dai_link->name); 1254 - goto err_probe; 1177 + break; 1255 1178 } 1256 - 1257 - if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on) 1258 - dai_link->platforms->of_node = adsp_node; 1259 - 1260 - if (!dai_link->platforms->name && !dai_link->platforms->of_node) 1261 - dai_link->platforms->of_node = platform_node; 1262 1179 } 1263 - 1264 - snd_soc_card_set_drvdata(card, soc_card_data); 1265 - 1266 - ret = mt8186_afe_gpio_init(&pdev->dev); 1267 - if (ret) { 1268 - dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__); 1269 - goto err_probe; 1270 - } 1271 - 1272 - ret = devm_snd_soc_register_card(&pdev->dev, card); 1273 - if (ret) 1274 - dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__); 1275 - 1276 - err_probe: 1277 1180 of_node_put(headset_codec); 1278 - err_headset_codec: 1279 1181 of_node_put(playback_codec); 1280 - err_playback_codec: 1281 - of_node_put(platform_node); 1282 - err_platform_node: 1283 - err_adsp_node: 1284 - of_node_put(adsp_node); 1285 1182 1286 1183 return ret; 1287 1184 } 1185 + 1186 + static int mt8186_mt6366_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) 1187 + { 1188 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1189 + struct snd_soc_card *card = card_data->card; 1190 + struct mt8186_mt6366_rt1019_rt5682s_priv *mach_priv; 1191 + int ret; 1192 + 1193 + mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL); 1194 + if (!mach_priv) 1195 + return -ENOMEM; 1196 + 1197 + soc_card_data->mach_priv = mach_priv; 1198 + 1199 + mach_priv->dmic_sel = devm_gpiod_get_optional(card->dev, 1200 + "dmic", GPIOD_OUT_LOW); 1201 + if (IS_ERR(mach_priv->dmic_sel)) 1202 + return dev_err_probe(card->dev, PTR_ERR(mach_priv->dmic_sel), 1203 + "DMIC gpio failed\n"); 1204 + 1205 + if (legacy) { 1206 + ret = mt8186_mt6366_legacy_probe(soc_card_data); 1207 + if (ret) 1208 + return ret; 1209 + } 1210 + 1211 + ret = mt8186_afe_gpio_init(card->dev); 1212 + if (ret) 1213 + return dev_err_probe(card->dev, ret, "init AFE gpio error\n"); 1214 + 1215 + return 0; 1216 + } 1217 + 1218 + static const struct mtk_sof_priv mt8186_sof_priv = { 1219 + .conn_streams = g_sof_conn_streams, 1220 + .num_streams = ARRAY_SIZE(g_sof_conn_streams), 1221 + .sof_dai_link_fixup = mt8186_sof_dai_link_fixup 1222 + }; 1223 + 1224 + static const struct mtk_soundcard_pdata mt8186_mt6366_rt1019_rt5682s_pdata = { 1225 + .card_data = &(struct mtk_platform_card_data) { 1226 + .card = &mt8186_mt6366_rt1019_rt5682s_soc_card, 1227 + .num_jacks = MT8186_JACK_MAX, 1228 + }, 1229 + .sof_priv = &mt8186_sof_priv, 1230 + .soc_probe = mt8186_mt6366_soc_card_probe 1231 + }; 1232 + 1233 + static const struct mtk_soundcard_pdata mt8186_mt6366_rt5682s_max98360_pdata = { 1234 + .card_data = &(struct mtk_platform_card_data) { 1235 + .card = &mt8186_mt6366_rt5682s_max98360_soc_card, 1236 + .num_jacks = MT8186_JACK_MAX, 1237 + }, 1238 + .sof_priv = &mt8186_sof_priv, 1239 + .soc_probe = mt8186_mt6366_soc_card_probe 1240 + }; 1241 + 1242 + static const struct mtk_soundcard_pdata mt8186_mt6366_rt5650_pdata = { 1243 + .card_data = &(struct mtk_platform_card_data) { 1244 + .card = &mt8186_mt6366_rt5650_soc_card, 1245 + .num_jacks = MT8186_JACK_MAX, 1246 + }, 1247 + .sof_priv = &mt8186_sof_priv, 1248 + .soc_probe = mt8186_mt6366_soc_card_probe 1249 + }; 1288 1250 1289 1251 #if IS_ENABLED(CONFIG_OF) 1290 1252 static const struct of_device_id mt8186_mt6366_rt1019_rt5682s_dt_match[] = { 1291 1253 { 1292 1254 .compatible = "mediatek,mt8186-mt6366-rt1019-rt5682s-sound", 1293 - .data = &mt8186_mt6366_rt1019_rt5682s_soc_card, 1255 + .data = &mt8186_mt6366_rt1019_rt5682s_pdata, 1294 1256 }, 1295 1257 { 1296 1258 .compatible = "mediatek,mt8186-mt6366-rt5682s-max98360-sound", 1297 - .data = &mt8186_mt6366_rt5682s_max98360_soc_card, 1259 + .data = &mt8186_mt6366_rt5682s_max98360_pdata, 1298 1260 }, 1299 1261 { 1300 1262 .compatible = "mediatek,mt8186-mt6366-rt5650-sound", 1301 - .data = &mt8186_mt6366_rt5650_soc_card, 1263 + .data = &mt8186_mt6366_rt5650_pdata, 1302 1264 }, 1303 1265 {} 1304 1266 }; ··· 1280 1308 #endif 1281 1309 .pm = &snd_soc_pm_ops, 1282 1310 }, 1283 - .probe = mt8186_mt6366_rt1019_rt5682s_dev_probe, 1311 + .probe = mtk_soundcard_common_probe, 1284 1312 }; 1285 1313 1286 1314 module_platform_driver(mt8186_mt6366_rt1019_rt5682s_driver);