From nobody Sun Nov 10 05:41:48 2024 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8F7F12CDAF; Thu, 7 Mar 2024 11:45:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709811917; cv=none; b=ombOsi6qPO6gyYnQa4Jdqn/1AbZkdXiZntTUVu2VePOWys0JcHC2QYyu9I8DvVrKa/5ymz46ymHGxPaaREOBpZSTJORpjpwTBcCC25HaOP1jWyTo+i/zxLVwiu7BMmH8aBG+ChyQNvYcKnsMrAgKITXDne8yfN9nZxj5Ly0VGDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709811917; c=relaxed/simple; bh=5l6ixT/QJSwR/7ij5ouRmnGQrpg9lKNtekqp8cQZN/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UiwtnS+0uM6wLNjNyiVUAfPf8KhgbePeeJk0x8HVO1BZO8EEFhklsfsdP45y3zIv7X3jgKkcZ5cnjWEPoB3WrIN0UYzT6+4T5GUt03oNalhBtWQWF8ay6N1oKUtUm6MykNbgfzZPBlOkGRdJKWrOWIY8iJUNu1gXBhDqVob+G0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=XE5KHrwA; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="XE5KHrwA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709811914; bh=5l6ixT/QJSwR/7ij5ouRmnGQrpg9lKNtekqp8cQZN/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XE5KHrwAtvh2CbEIpfUMBJQr58Z9w5PRNVtK39aR/vZ4Lcd23uJXR4I2hqqJulzAP /hLHars4gJT/Y/NtXJV5oZGHFX3565siPMLwhhaHb7Fo/o2/bRJ05dqbjlAFamlpk9 Lpl1yxEn00T5RW501gmBofeFZLb2DiIGdIckaB8vjgM79zP6SstHSKRsbg8SwvGrVQ toRLVzFKQF41nYmB4/l0i+bSlayNQh3JCkmdqhG21BoSS3l03tqCNyscNsronRoFiW /2mODwTF2EGyiP4het8pesU+Xd961BsJHt8P14gVxt/r6z0Dt5mCApNJgFtelGcknN laZVc76CJBesA== Received: from IcarusMOD.eternityproject.eu (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 5996D37820ED; Thu, 7 Mar 2024 11:45:12 +0000 (UTC) From: AngeloGioacchino Del Regno To: broonie@kernel.org Cc: wenst@chromium.org, lgirdwood@gmail.com, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, matthias.bgg@gmail.com, perex@perex.cz, tiwai@suse.com, trevor.wu@mediatek.com, maso.huang@mediatek.com, xiazhengqiao@huaqin.corp-partner.google.com, arnd@arndb.de, kuninori.morimoto.gx@renesas.com, shraash@google.com, amergnat@baylibre.com, nicolas.ferre@microchip.com, u.kleine-koenig@pengutronix.de, dianders@chromium.org, frank.li@vivo.com, allen-kh.cheng@mediatek.com, eugen.hristev@collabora.com, claudiu.beznea@tuxon.dev, jarkko.nikula@bitmer.com, jiaxin.yu@mediatek.com, alpernebiyasak@gmail.com, ckeepax@opensource.cirrus.com, zhourui@huaqin.corp-partner.google.com, nfraprado@collabora.com, alsa-devel@alsa-project.org, shane.chien@mediatek.com, linux-sound@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, AngeloGioacchino Del Regno Subject: [PATCH v2 09/22] ASoC: mediatek: mt8192: Migrate to mtk_soundcard_common_probe Date: Thu, 7 Mar 2024 12:44:32 +0100 Message-ID: <20240307114445.196981-10-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240307114445.196981-1-angelogioacchino.delregno@collabora.com> References: <20240307114445.196981-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: AngeloGioacchino Del Regno --- .../mt8192/mt8192-mt6359-rt1015-rt5682.c | 164 ++++++++++-------- 1 file changed, 91 insertions(+), 73 deletions(-) diff --git a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c b/soun= d/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c index bfcb2c486c39..645bc1aa67c7 100644 --- a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c +++ b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c @@ -20,6 +20,8 @@ #include "../../codecs/rt1015.h" #include "../../codecs/rt5682.h" #include "../common/mtk-afe-platform-driver.h" +#include "../common/mtk-soc-card.h" +#include "../common/mtk-soundcard-driver.h" #include "mt8192-afe-common.h" #include "mt8192-afe-clk.h" #include "mt8192-afe-gpio.h" @@ -38,9 +40,10 @@ #define RT1015P_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682" #define RT1015P_RT5682S_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682s" =20 -struct mt8192_mt6359_priv { - struct snd_soc_jack headset_jack; - struct snd_soc_jack hdmi_jack; +enum mt8192_jacks { + MT8192_JACK_HEADSET, + MT8192_JACK_HDMI, + MT8192_JACK_MAX, }; =20 /* Headset jack detection DAPM pins */ @@ -323,13 +326,13 @@ static int mt8192_mt6359_init(struct snd_soc_pcm_runt= ime *rtd) =20 static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd) { + struct mtk_soc_card_data *soc_card_data =3D snd_soc_card_get_drvdata(rtd-= >card); + struct snd_soc_jack *jack =3D &soc_card_data->card_data->jacks[MT8192_JAC= K_HEADSET]; struct snd_soc_component *cmpnt_afe =3D snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); struct mtk_base_afe *afe =3D snd_soc_component_get_drvdata(cmpnt_afe); struct snd_soc_component *cmpnt_codec =3D snd_soc_rtd_to_codec(rtd, 0)->component; - struct mt8192_mt6359_priv *priv =3D snd_soc_card_get_drvdata(rtd->card); - struct snd_soc_jack *jack =3D &priv->headset_jack; int ret; =20 ret =3D mt8192_dai_i2s_set_share(afe, "I2S8", "I2S9"); @@ -359,19 +362,19 @@ static int mt8192_rt5682_init(struct snd_soc_pcm_runt= ime *rtd) =20 static int mt8192_mt6359_hdmi_init(struct snd_soc_pcm_runtime *rtd) { + struct mtk_soc_card_data *soc_card_data =3D snd_soc_card_get_drvdata(rtd-= >card); + struct snd_soc_jack *jack =3D &soc_card_data->card_data->jacks[MT8192_JAC= K_HDMI]; struct snd_soc_component *cmpnt_codec =3D snd_soc_rtd_to_codec(rtd, 0)->component; - struct mt8192_mt6359_priv *priv =3D snd_soc_card_get_drvdata(rtd->card); int ret; =20 - ret =3D snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, - &priv->hdmi_jack); + ret =3D snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, j= ack); if (ret) { dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); return ret; } =20 - return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); + return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); } =20 static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, @@ -1136,71 +1139,53 @@ static int mt8192_mt6359_card_set_be_link(struct sn= d_soc_card *card, return 0; } =20 -static int mt8192_mt6359_dev_probe(struct platform_device *pdev) +static int mt8192_mt6359_legacy_probe(struct mtk_soc_card_data *soc_card_d= ata) { - struct snd_soc_card *card; - struct device_node *platform_node, *hdmi_codec, *headset_codec, *speaker_= codec; - int ret, i; + struct mtk_platform_card_data *card_data =3D soc_card_data->card_data; + struct snd_soc_card *card =3D card_data->card; + struct device *dev =3D card->dev; + struct device_node *hdmi_codec, *headset_codec, *speaker_codec; struct snd_soc_dai_link *dai_link; - struct mt8192_mt6359_priv *priv; - - card =3D (struct snd_soc_card *)of_device_get_match_data(&pdev->dev); - if (!card) - return -EINVAL; - card->dev =3D &pdev->dev; - - if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682_OF_NAME)) - card->name =3D RT1015P_RT5682_CARD_NAME; - else if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682S_OF_NA= ME)) - card->name =3D RT1015P_RT5682S_CARD_NAME; - else - dev_dbg(&pdev->dev, "No need to set card name\n"); + int ret, i; =20 - hdmi_codec =3D of_parse_phandle(pdev->dev.of_node, "mediatek,hdmi-codec",= 0); + hdmi_codec =3D of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0); if (!hdmi_codec) - dev_dbg(&pdev->dev, "The machine has no hdmi-codec\n"); + dev_dbg(dev, "The machine has no hdmi-codec\n"); =20 - platform_node =3D of_parse_phandle(pdev->dev.of_node, "mediatek,platform"= , 0); - if (!platform_node) { - ret =3D -EINVAL; - dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n= "); - goto err_platform_node; - } - - speaker_codec =3D of_get_child_by_name(pdev->dev.of_node, "speaker-codecs= "); + speaker_codec =3D of_get_child_by_name(dev->of_node, "speaker-codecs"); if (!speaker_codec) { ret =3D -EINVAL; - dev_err_probe(&pdev->dev, ret, "Property 'speaker-codecs' missing or inv= alid\n"); + dev_err_probe(dev, ret, "Property 'speaker-codecs' missing or invalid\n"= ); goto err_speaker_codec; } =20 - headset_codec =3D of_get_child_by_name(pdev->dev.of_node, "headset-codec"= ); + headset_codec =3D of_get_child_by_name(dev->of_node, "headset-codec"); if (!headset_codec) { ret =3D -EINVAL; - dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or inva= lid\n"); + dev_err_probe(dev, ret, "Property 'headset-codec' missing or invalid\n"); goto err_headset_codec; } =20 for_each_card_prelinks(card, i, dai_link) { ret =3D mt8192_mt6359_card_set_be_link(card, dai_link, speaker_codec, "I= 2S3"); if (ret) { - dev_err_probe(&pdev->dev, ret, "%s set speaker_codec fail\n", + dev_err_probe(dev, ret, "%s set speaker_codec fail\n", dai_link->name); - goto err_probe; + break; } =20 ret =3D mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I= 2S8"); if (ret) { - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", + dev_err_probe(dev, ret, "%s set headset_codec fail\n", dai_link->name); - goto err_probe; + break; } =20 ret =3D mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I= 2S9"); if (ret) { - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", + dev_err_probe(dev, ret, "%s set headset_codec fail\n", dai_link->name); - goto err_probe; + break; } =20 if (hdmi_codec && strcmp(dai_link->name, "TDM") =3D=3D 0) { @@ -1211,52 +1196,85 @@ static int mt8192_mt6359_dev_probe(struct platform_= device *pdev) if (dai_link->num_codecs && dai_link->codecs[0].dai_name && strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) =3D=3D 0) dai_link->ops =3D &mt8192_rt1015_i2s_ops; - - if (!dai_link->platforms->name) - dai_link->platforms->of_node =3D platform_node; - } - - priv =3D devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) { - ret =3D -ENOMEM; - goto err_probe; - } - snd_soc_card_set_drvdata(card, priv); - - ret =3D mt8192_afe_gpio_init(&pdev->dev); - if (ret) { - dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__); - goto err_probe; } =20 - ret =3D devm_snd_soc_register_card(&pdev->dev, card); - if (ret) - dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func= __); - -err_probe: of_node_put(headset_codec); err_headset_codec: of_node_put(speaker_codec); err_speaker_codec: - of_node_put(platform_node); -err_platform_node: - of_node_put(hdmi_codec); + if (hdmi_codec) + of_node_put(hdmi_codec); + return ret; } =20 +static int mt8192_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card= _data, bool legacy) +{ + struct mtk_platform_card_data *card_data =3D soc_card_data->card_data; + struct snd_soc_card *card =3D card_data->card; + int ret; + + if (legacy) { + ret =3D mt8192_mt6359_legacy_probe(soc_card_data); + if (ret) + return ret; + } else { + struct snd_soc_dai_link *dai_link; + int i; + + for_each_card_prelinks(card, i, dai_link) + if (dai_link->num_codecs && dai_link->codecs[0].dai_name && + strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) =3D=3D 0) + dai_link->ops =3D &mt8192_rt1015_i2s_ops; + } + + ret =3D mt8192_afe_gpio_init(card->dev); + if (ret) + return dev_err_probe(card->dev, ret, "%s init gpio error\n", __func__); + + return 0; +} + +static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015_rt5682_pdata = =3D { + .card_name =3D RT1015_RT5682_CARD_NAME, + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8192_mt6359_rt1015_rt5682_card, + .num_jacks =3D MT8192_JACK_MAX, + }, + .soc_probe =3D mt8192_mt6359_soc_card_probe +}; + +static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015p_rt5682_pdata= =3D { + .card_name =3D RT1015P_RT5682_CARD_NAME, + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8192_mt6359_rt1015p_rt5682x_card, + .num_jacks =3D MT8192_JACK_MAX, + }, + .soc_probe =3D mt8192_mt6359_soc_card_probe +}; + +static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015p_rt5682s_pdat= a =3D { + .card_name =3D RT1015P_RT5682S_CARD_NAME, + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8192_mt6359_rt1015p_rt5682x_card, + .num_jacks =3D MT8192_JACK_MAX, + }, + .soc_probe =3D mt8192_mt6359_soc_card_probe +}; + #ifdef CONFIG_OF static const struct of_device_id mt8192_mt6359_dt_match[] =3D { { .compatible =3D RT1015_RT5682_OF_NAME, - .data =3D &mt8192_mt6359_rt1015_rt5682_card, + .data =3D &mt8192_mt6359_rt1015_rt5682_pdata, }, { .compatible =3D RT1015P_RT5682_OF_NAME, - .data =3D &mt8192_mt6359_rt1015p_rt5682x_card, + .data =3D &mt8192_mt6359_rt1015p_rt5682_pdata, }, { .compatible =3D RT1015P_RT5682S_OF_NAME, - .data =3D &mt8192_mt6359_rt1015p_rt5682x_card, + .data =3D &mt8192_mt6359_rt1015p_rt5682s_pdata, }, {} }; @@ -1276,7 +1294,7 @@ static struct platform_driver mt8192_mt6359_driver = =3D { #endif .pm =3D &mt8192_mt6359_pm_ops, }, - .probe =3D mt8192_mt6359_dev_probe, + .probe =3D mtk_soundcard_common_probe, }; =20 module_platform_driver(mt8192_mt6359_driver); --=20 2.44.0