From nobody Thu Nov 14 04:48:16 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 D141947A6B; Wed, 13 Mar 2024 11:02:22 +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=1710327744; cv=none; b=lu+Uj/J4qcsMn77GPnEY8eV4gHkdyAOFx2SN/h1m370AC2YLJRyRXXKHWzLAP4JoS6A17OLYVSsNZGTEGS3F6YXQ3lyrjcq1hdPyf0N+xnUhAK6LkpmLKbyq8yQwjBwO4ntTERBHU10Gk7sVBMwnG5wloMCXk/GviseKzzzHTo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327744; c=relaxed/simple; bh=tyW0dHFJqhZx31YjrVqMPVuC6uJ5oRn4lN6PlFhgJZU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eOfaBxKJtZfbTXP7VCLkCJqDPdphdOOTKW0kPbrGSlOTSqCO4YwP6ZDAUg3KLkg72O8x9tKLIoaPntQ7UVvwEanKZvTl9EFi7uyWCCWDMPBGAToMSlAyhTwJYlpUu8P7PSu7fmNWzEjcCNxNuIci38gREJ+00EpCQ2TQuNP6vIU= 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=tUXyrAXi; 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="tUXyrAXi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1710327741; bh=tyW0dHFJqhZx31YjrVqMPVuC6uJ5oRn4lN6PlFhgJZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tUXyrAXius6cTWUL9j4REyRDta2hDhNbGKaf/Ixkm5JoARxQBWiNP46FK+IlB3xU7 bkr2oBa5oWWU5/e/0GJhyWpn3j2OaFRL2E74xkwiTqmxrsOrWEvpzcwNZbwelbShF7 TH45oBsurm+hcbW/rE/TNo8Au+nhnU84dR3MlgckUfH6gStt3zzhV+UkmUaKDeurYH 2LIj1C0JSUdSFwyj7Gy3JXd45+149tJWXlM231FPsdINPkHb8nc8w9qOCnTRucqim1 xekC/OUorG/2JJufkl5S/YnikWrAuH7+YXxGriAz+cC/BUjzSV6sGXMU1LUhQ87Gal 0sqNLhtjU03PA== 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 1E05237820C6; Wed, 13 Mar 2024 11:02:19 +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 v3 10/22] ASoC: mediatek: mt8186: Migrate to mtk_soundcard_common_probe Date: Wed, 13 Mar 2024 12:01:35 +0100 Message-ID: <20240313110147.1267793-11-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313110147.1267793-1-angelogioacchino.delregno@collabora.com> References: <20240313110147.1267793-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 --- .../mt8186/mt8186-mt6366-rt1019-rt5682s.c | 220 ++++++++---------- 1 file changed, 96 insertions(+), 124 deletions(-) diff --git a/sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c b/sou= nd/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c index afb361e5101b..66e15b883f54 100644 --- a/sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c +++ b/sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c @@ -21,6 +21,7 @@ #include "../common/mtk-afe-platform-driver.h" #include "../common/mtk-dsp-sof-common.h" #include "../common/mtk-soc-card.h" +#include "../common/mtk-soundcard-driver.h" #include "mt8186-afe-common.h" #include "mt8186-afe-clk.h" #include "mt8186-afe-gpio.h" @@ -38,11 +39,16 @@ #define SOF_DMA_UL2 "SOF_DMA_UL2" =20 struct mt8186_mt6366_rt1019_rt5682s_priv { - struct snd_soc_jack headset_jack, hdmi_jack; struct gpio_desc *dmic_sel; int dmic_switch; }; =20 +enum mt8186_jacks { + MT8186_JACK_HEADSET, + MT8186_JACK_HDMI, + MT8186_JACK_MAX, +}; + /* Headset jack detection DAPM pins */ static struct snd_soc_jack_pin mt8186_jack_pins[] =3D { { @@ -165,8 +171,7 @@ static int mt8186_rt5682s_init(struct snd_soc_pcm_runti= me *rtd) struct mtk_base_afe *afe =3D snd_soc_component_get_drvdata(cmpnt_afe); struct mtk_soc_card_data *soc_card_data =3D snd_soc_card_get_drvdata(rtd->card); - struct mt8186_mt6366_rt1019_rt5682s_priv *priv =3D soc_card_data->mach_pr= iv; - struct snd_soc_jack *jack =3D &priv->headset_jack; + struct snd_soc_jack *jack =3D &soc_card_data->card_data->jacks[MT8186_JAC= K_HEADSET]; struct snd_soc_component *cmpnt_codec =3D snd_soc_rtd_to_codec(rtd, 0)->component; int ret; @@ -257,7 +262,7 @@ static int mt8186_mt6366_rt1019_rt5682s_hdmi_init(struc= t snd_soc_pcm_runtime *rt snd_soc_rtd_to_codec(rtd, 0)->component; struct mtk_soc_card_data *soc_card_data =3D snd_soc_card_get_drvdata(rtd->card); - struct mt8186_mt6366_rt1019_rt5682s_priv *priv =3D soc_card_data->mach_pr= iv; + struct snd_soc_jack *jack =3D &soc_card_data->card_data->jacks[MT8186_JAC= K_HDMI]; int ret; =20 ret =3D mt8186_dai_i2s_set_share(afe, "I2S2", "I2S3"); @@ -266,13 +271,13 @@ static int mt8186_mt6366_rt1019_rt5682s_hdmi_init(str= uct snd_soc_pcm_runtime *rt return 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 mt8186_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, @@ -1134,166 +1139,133 @@ static struct snd_soc_card mt8186_mt6366_rt5650_s= oc_card =3D { .num_configs =3D ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf), }; =20 -static int mt8186_mt6366_rt1019_rt5682s_dev_probe(struct platform_device *= pdev) +static int mt8186_mt6366_legacy_probe(struct mtk_soc_card_data *soc_card_d= ata) { - struct snd_soc_card *card; + 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 snd_soc_dai_link *dai_link; - struct mtk_soc_card_data *soc_card_data; - struct mt8186_mt6366_rt1019_rt5682s_priv *mach_priv; - struct device_node *platform_node, *headset_codec, *playback_codec, *adsp= _node; - int sof_on =3D 0; + struct device_node *headset_codec, *playback_codec; int ret, i; =20 - card =3D (struct snd_soc_card *)device_get_match_data(&pdev->dev); - if (!card) - return -EINVAL; - card->dev =3D &pdev->dev; - - soc_card_data =3D devm_kzalloc(&pdev->dev, sizeof(*soc_card_data), GFP_KE= RNEL); - if (!soc_card_data) - return -ENOMEM; - mach_priv =3D devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL); - if (!mach_priv) - return -ENOMEM; - - soc_card_data->mach_priv =3D mach_priv; - - mach_priv->dmic_sel =3D devm_gpiod_get_optional(&pdev->dev, - "dmic", GPIOD_OUT_LOW); - if (IS_ERR(mach_priv->dmic_sel)) { - dev_err(&pdev->dev, "DMIC gpio failed err=3D%ld\n", - PTR_ERR(mach_priv->dmic_sel)); - return PTR_ERR(mach_priv->dmic_sel); - } - - adsp_node =3D of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); - if (adsp_node) { - struct mtk_sof_priv *sof_priv; + playback_codec =3D of_get_child_by_name(dev->of_node, "playback-codecs"); + if (!playback_codec) + return dev_err_probe(dev, -EINVAL, + "Property 'playback-codecs' missing or invalid\n"); =20 - sof_priv =3D devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); - if (!sof_priv) { - ret =3D -ENOMEM; - goto err_adsp_node; - } - sof_priv->conn_streams =3D g_sof_conn_streams; - sof_priv->num_streams =3D ARRAY_SIZE(g_sof_conn_streams); - sof_priv->sof_dai_link_fixup =3D mt8186_sof_dai_link_fixup; - soc_card_data->sof_priv =3D sof_priv; - card->probe =3D mtk_sof_card_probe; - card->late_probe =3D mtk_sof_card_late_probe; - if (!card->topology_shortname_created) { - snprintf(card->topology_shortname, 32, "sof-%s", card->name); - card->topology_shortname_created =3D true; - } - card->name =3D card->topology_shortname; - sof_on =3D 1; - } else { - dev_dbg(&pdev->dev, "Probe without adsp\n"); - } - - if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { - ret =3D mtk_sof_dailink_parse_of(card, pdev->dev.of_node, - "mediatek,dai-link", - mt8186_mt6366_rt1019_rt5682s_dai_links, - ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links)); - if (ret) { - dev_dbg(&pdev->dev, "Parse dai-link fail\n"); - goto err_adsp_node; - } - } else { - if (!sof_on) - card->num_links =3D ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links) - - ARRAY_SIZE(g_sof_conn_streams); - } - - 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; - } - - playback_codec =3D of_get_child_by_name(pdev->dev.of_node, "playback-code= cs"); - if (!playback_codec) { - ret =3D -EINVAL; - dev_err_probe(&pdev->dev, ret, "Property 'playback-codecs' missing or in= valid\n"); - goto err_playback_codec; - } - - 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"); - goto err_headset_codec; + of_node_put(playback_codec); + return dev_err_probe(dev, -EINVAL, + "Property 'headset-codec' missing or invalid\n"); } =20 for_each_card_prelinks(card, i, dai_link) { ret =3D mt8186_mt6366_card_set_be_link(card, dai_link, playback_codec, "= I2S3"); if (ret) { - dev_err_probe(&pdev->dev, ret, "%s set playback_codec fail\n", + dev_err_probe(dev, ret, "%s set playback_codec fail\n", dai_link->name); - goto err_probe; + break; } =20 ret =3D mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I= 2S0"); 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 mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I= 2S1"); 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; } + } + of_node_put(headset_codec); + of_node_put(playback_codec); =20 - if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on) - dai_link->platforms->of_node =3D adsp_node; + return ret; +} =20 - if (!dai_link->platforms->name && !dai_link->platforms->of_node) - dai_link->platforms->of_node =3D platform_node; - } +static int mt8186_mt6366_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; + struct mt8186_mt6366_rt1019_rt5682s_priv *mach_priv; + int ret; =20 - snd_soc_card_set_drvdata(card, soc_card_data); + mach_priv =3D devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL); + if (!mach_priv) + return -ENOMEM; =20 - ret =3D mt8186_afe_gpio_init(&pdev->dev); - if (ret) { - dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__); - goto err_probe; + soc_card_data->mach_priv =3D mach_priv; + + mach_priv->dmic_sel =3D devm_gpiod_get_optional(card->dev, + "dmic", GPIOD_OUT_LOW); + if (IS_ERR(mach_priv->dmic_sel)) + return dev_err_probe(card->dev, PTR_ERR(mach_priv->dmic_sel), + "DMIC gpio failed\n"); + + if (legacy) { + ret =3D mt8186_mt6366_legacy_probe(soc_card_data); + if (ret) + return ret; } =20 - ret =3D devm_snd_soc_register_card(&pdev->dev, card); + ret =3D mt8186_afe_gpio_init(card->dev); if (ret) - dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func= __); + return dev_err_probe(card->dev, ret, "init AFE gpio error\n"); =20 -err_probe: - of_node_put(headset_codec); -err_headset_codec: - of_node_put(playback_codec); -err_playback_codec: - of_node_put(platform_node); -err_platform_node: -err_adsp_node: - of_node_put(adsp_node); - - return ret; + return 0; } =20 +static const struct mtk_sof_priv mt8186_sof_priv =3D { + .conn_streams =3D g_sof_conn_streams, + .num_streams =3D ARRAY_SIZE(g_sof_conn_streams), + .sof_dai_link_fixup =3D mt8186_sof_dai_link_fixup +}; + +static const struct mtk_soundcard_pdata mt8186_mt6366_rt1019_rt5682s_pdata= =3D { + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8186_mt6366_rt1019_rt5682s_soc_card, + .num_jacks =3D MT8186_JACK_MAX, + }, + .sof_priv =3D &mt8186_sof_priv, + .soc_probe =3D mt8186_mt6366_soc_card_probe +}; + +static const struct mtk_soundcard_pdata mt8186_mt6366_rt5682s_max98360_pda= ta =3D { + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8186_mt6366_rt5682s_max98360_soc_card, + .num_jacks =3D MT8186_JACK_MAX, + }, + .sof_priv =3D &mt8186_sof_priv, + .soc_probe =3D mt8186_mt6366_soc_card_probe +}; + +static const struct mtk_soundcard_pdata mt8186_mt6366_rt5650_pdata =3D { + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8186_mt6366_rt5650_soc_card, + .num_jacks =3D MT8186_JACK_MAX, + }, + .sof_priv =3D &mt8186_sof_priv, + .soc_probe =3D mt8186_mt6366_soc_card_probe +}; + #if IS_ENABLED(CONFIG_OF) static const struct of_device_id mt8186_mt6366_rt1019_rt5682s_dt_match[] = =3D { { .compatible =3D "mediatek,mt8186-mt6366-rt1019-rt5682s-sound", - .data =3D &mt8186_mt6366_rt1019_rt5682s_soc_card, + .data =3D &mt8186_mt6366_rt1019_rt5682s_pdata, }, { .compatible =3D "mediatek,mt8186-mt6366-rt5682s-max98360-sound", - .data =3D &mt8186_mt6366_rt5682s_max98360_soc_card, + .data =3D &mt8186_mt6366_rt5682s_max98360_pdata, }, { .compatible =3D "mediatek,mt8186-mt6366-rt5650-sound", - .data =3D &mt8186_mt6366_rt5650_soc_card, + .data =3D &mt8186_mt6366_rt5650_pdata, }, {} }; @@ -1308,7 +1280,7 @@ static struct platform_driver mt8186_mt6366_rt1019_rt= 5682s_driver =3D { #endif .pm =3D &snd_soc_pm_ops, }, - .probe =3D mt8186_mt6366_rt1019_rt5682s_dev_probe, + .probe =3D mtk_soundcard_common_probe, }; =20 module_platform_driver(mt8186_mt6366_rt1019_rt5682s_driver); --=20 2.44.0