From nobody Wed Nov 13 01:23:49 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 9F27E12C81F; Thu, 7 Mar 2024 11:45:11 +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=1709811913; cv=none; b=MlBoKB7DugKQ7lSQvFs2fdc+HaRJnFj+jE636tIRvnjwfmrwq3PteTmM1OO2XbpD4aY7OsFqJ5LW8clD9PRLn8yS4F45h/FC20W1XnkUQZwOiulgRr+Ihb65GtvMewrT6UsaHNlf6TkiYsgfNuKEY51m2uU0jnRkTgCTByQbzVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709811913; c=relaxed/simple; bh=B+vp4Uw62xZRdn2O7lnJ5cXiKQOHqoydOc/koaWZkvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P/4eXDEXKoyMiZZD+vKqGCKkBmQoiLXF7hxlLl69Af8ZcduIsdK1s1E9qrFnQBBMgXTvCYxXHu/mJu93kXbBHcnFG9+v8xqWinsMXJTJEzb1YtKX/t+FbcKB49JyRsd3g4TQ5FhW5Nh8YLdqqkMDlVJSGpS1fauySVF0sCPWi10= 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=dl+ywjEb; 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="dl+ywjEb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709811909; bh=B+vp4Uw62xZRdn2O7lnJ5cXiKQOHqoydOc/koaWZkvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dl+ywjEbjHUHuyMbMLcHVm0DFQvWMWyMSURrxOE7n0VRlWKSWGmzWPhnli2fI5Ckc Er4NU0si8QFXpg5tv7PIb7ssQ5q7sjOJj8tSK07vIX/bCY6ycerdQSrmEew8+c7C1/ 53Jd3vfYhjXL8hzYqsQz/THfQk3DC/1nqvnN8Bc3ht/cG/Du9LkbfI0bUGD9KTMVJt u0fHFTa1g5rrVzHGzA0ffmEmZc8Dk6HO+2jlv2IKR2X0v3fBopSWGY1IuhIo1QgTB1 NYEz5UE2gs8DYJM+dprXVa7ppP+/qBf2egV26rJj+VNTLbTlmwEOJ16LnaH8iwR06S y5A3pf2fkgZcg== 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 9510437820EF; Thu, 7 Mar 2024 11:45:07 +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 07/22] ASoC: mediatek: mt8188: Migrate to mtk_soundcard_common_probe Date: Thu, 7 Mar 2024 12:44:30 +0100 Message-ID: <20240307114445.196981-8-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. Signed-off-by: AngeloGioacchino Del Regno --- sound/soc/mediatek/mt8188/mt8188-mt6359.c | 203 +++++++--------------- 1 file changed, 64 insertions(+), 139 deletions(-) diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek= /mt8188/mt8188-mt6359.c index a391066ab204..f629fc6bbb53 100644 --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c @@ -236,11 +236,11 @@ static const struct sof_conn_stream g_sof_conn_stream= s[] =3D { }, }; =20 -struct mt8188_mt6359_priv { - struct snd_soc_jack dp_jack; - struct snd_soc_jack hdmi_jack; - struct snd_soc_jack headset_jack; - void *private_data; +enum mt8188_jacks { + MT8188_JACK_HEADSET, + MT8188_JACK_DP, + MT8188_JACK_HDMI, + MT8188_JACK_MAX, }; =20 static struct snd_soc_jack_pin mt8188_hdmi_jack_pins[] =3D { @@ -268,11 +268,6 @@ static struct snd_soc_jack_pin nau8825_jack_pins[] =3D= { }, }; =20 -struct mt8188_card_data { - const char *name; - unsigned long quirk; -}; - static const struct snd_kcontrol_new mt8188_dumb_spk_controls[] =3D { SOC_DAPM_PIN_SWITCH("Ext Spk"), }; @@ -590,12 +585,12 @@ static int mt8188_dptx_hw_params_fixup(struct snd_soc= _pcm_runtime *rtd, static int mt8188_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) { struct mtk_soc_card_data *soc_card_data =3D snd_soc_card_get_drvdata(rtd-= >card); - struct mt8188_mt6359_priv *priv =3D soc_card_data->mach_priv; + struct snd_soc_jack *jack =3D &soc_card_data->card_data->jacks[MT8188_JAC= K_HDMI]; struct snd_soc_component *component =3D snd_soc_rtd_to_codec(rtd, 0)->com= ponent; int ret =3D 0; =20 ret =3D snd_soc_card_jack_new_pins(rtd->card, "HDMI Jack", - SND_JACK_LINEOUT, &priv->hdmi_jack, + SND_JACK_LINEOUT, jack, mt8188_hdmi_jack_pins, ARRAY_SIZE(mt8188_hdmi_jack_pins)); if (ret) { @@ -603,7 +598,7 @@ static int mt8188_hdmi_codec_init(struct snd_soc_pcm_ru= ntime *rtd) return ret; } =20 - ret =3D snd_soc_component_set_jack(component, &priv->hdmi_jack, NULL); + ret =3D snd_soc_component_set_jack(component, jack, NULL); if (ret) { dev_err(rtd->dev, "%s, set jack failed on %s (ret=3D%d)\n", __func__, component->name, ret); @@ -616,19 +611,19 @@ static int mt8188_hdmi_codec_init(struct snd_soc_pcm_= runtime *rtd) static int mt8188_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) { struct mtk_soc_card_data *soc_card_data =3D snd_soc_card_get_drvdata(rtd-= >card); - struct mt8188_mt6359_priv *priv =3D soc_card_data->mach_priv; + struct snd_soc_jack *jack =3D &soc_card_data->card_data->jacks[MT8188_JAC= K_DP]; struct snd_soc_component *component =3D snd_soc_rtd_to_codec(rtd, 0)->com= ponent; int ret =3D 0; =20 ret =3D snd_soc_card_jack_new_pins(rtd->card, "DP Jack", SND_JACK_LINEOUT, - &priv->dp_jack, mt8188_dp_jack_pins, + jack, mt8188_dp_jack_pins, ARRAY_SIZE(mt8188_dp_jack_pins)); if (ret) { dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret); return ret; } =20 - ret =3D snd_soc_component_set_jack(component, &priv->dp_jack, NULL); + ret =3D snd_soc_component_set_jack(component, jack, NULL); if (ret) { dev_err(rtd->dev, "%s, set jack failed on %s (ret=3D%d)\n", __func__, component->name, ret); @@ -736,10 +731,9 @@ static int mt8188_max98390_codec_init(struct snd_soc_p= cm_runtime *rtd) static int mt8188_headset_codec_init(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_card *card =3D rtd->card; - struct mtk_soc_card_data *soc_card_data =3D snd_soc_card_get_drvdata(card= ); - struct mt8188_mt6359_priv *priv =3D soc_card_data->mach_priv; + 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[MT8188_JAC= K_HEADSET]; struct snd_soc_component *component =3D snd_soc_rtd_to_codec(rtd, 0)->com= ponent; - struct snd_soc_jack *jack =3D &priv->headset_jack; int ret; =20 ret =3D snd_soc_dapm_new_controls(&card->dapm, mt8188_nau8825_widgets, @@ -1224,11 +1218,10 @@ static struct snd_soc_dai_link mt8188_mt6359_dai_li= nks[] =3D { static void mt8188_fixup_controls(struct snd_soc_card *card) { struct mtk_soc_card_data *soc_card_data =3D snd_soc_card_get_drvdata(card= ); - struct mt8188_mt6359_priv *priv =3D soc_card_data->mach_priv; - struct mt8188_card_data *card_data =3D (struct mt8188_card_data *)priv->p= rivate_data; + struct mtk_platform_card_data *card_data =3D soc_card_data->card_data; struct snd_kcontrol *kctl; =20 - if (card_data->quirk & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_= HS_PRESENT)) { + if (card_data->flags & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_= HS_PRESENT)) { struct snd_soc_dapm_widget *w, *next_w; =20 for_each_card_widgets_safe(card, w, next_w) { @@ -1259,14 +1252,10 @@ static struct snd_soc_card mt8188_mt6359_soc_card = =3D { .fixup_controls =3D mt8188_fixup_controls, }; =20 -static int mt8188_mt6359_dev_probe(struct platform_device *pdev) +static int mt8188_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card= _data, bool legacy) { - struct snd_soc_card *card =3D &mt8188_mt6359_soc_card; - struct device_node *platform_node; - struct device_node *adsp_node; - struct mtk_soc_card_data *soc_card_data; - struct mt8188_mt6359_priv *priv; - struct mt8188_card_data *card_data; + struct mtk_platform_card_data *card_data =3D soc_card_data->card_data; + struct snd_soc_card *card =3D soc_card_data->card_data->card; struct snd_soc_dai_link *dai_link; bool init_mt6359 =3D false; bool init_es8326 =3D false; @@ -1274,91 +1263,12 @@ static int mt8188_mt6359_dev_probe(struct platform_= device *pdev) bool init_rt5682s =3D false; bool init_max98390 =3D false; bool init_dumb =3D false; - int ret, i; - - card_data =3D (struct mt8188_card_data *)of_device_get_match_data(&pdev->= dev); - card->dev =3D &pdev->dev; - - ret =3D snd_soc_of_parse_card_name(card, "model"); - if (ret) - return dev_err_probe(&pdev->dev, ret, "%s new card name parsing error\n", - __func__); - - if (!card->name) - card->name =3D card_data->name; - - if (of_property_read_bool(pdev->dev.of_node, "audio-routing")) { - ret =3D snd_soc_of_parse_audio_routing(card, "audio-routing"); - if (ret) - return ret; - } - - priv =3D devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - - soc_card_data =3D devm_kzalloc(&pdev->dev, sizeof(*card_data), GFP_KERNEL= ); - if (!soc_card_data) - return -ENOMEM; - - soc_card_data->mach_priv =3D priv; - - adsp_node =3D of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); - if (adsp_node) { - struct mtk_sof_priv *sof_priv; - - 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); - 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; - } - - 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", - mt8188_mt6359_dai_links, - ARRAY_SIZE(mt8188_mt6359_dai_links)); - if (ret) { - dev_err_probe(&pdev->dev, ret, "Parse dai-link fail\n"); - goto err_adsp_node; - } - } else { - if (!adsp_node) - card->num_links =3D DAI_LINK_REGULAR_NUM; - } - - platform_node =3D of_parse_phandle(pdev->dev.of_node, - "mediatek,platform", 0); - if (!platform_node) { - ret =3D dev_err_probe(&pdev->dev, -EINVAL, - "Property 'platform' missing or invalid\n"); - goto err_adsp_node; - - } + int i; =20 - ret =3D parse_dai_link_info(card); - if (ret) - goto err; + if (legacy) + return -EINVAL; =20 for_each_card_prelinks(card, i, dai_link) { - if (!dai_link->platforms->name) { - if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && adsp_node) - dai_link->platforms->of_node =3D adsp_node; - else - dai_link->platforms->of_node =3D platform_node; - } - if (strcmp(dai_link->name, "DPTX_BE") =3D=3D 0) { if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) dai_link->init =3D mt8188_dptx_codec_init; @@ -1381,7 +1291,7 @@ static int mt8188_mt6359_dev_probe(struct platform_de= vice *pdev) * mt8188_max98390_ops. Two amps is I2S mode, * SOC and codec don't require TDM settings. */ - if (!(card_data->quirk & MAX98390_TWO_AMP)) { + if (!(card_data->flags & MAX98390_TWO_AMP)) { dai_link->ops =3D &mt8188_max98390_ops; } if (!init_max98390) { @@ -1420,40 +1330,55 @@ static int mt8188_mt6359_dev_probe(struct platform_= device *pdev) } } =20 - priv->private_data =3D card_data; - snd_soc_card_set_drvdata(card, soc_card_data); - - 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: - of_node_put(platform_node); - clean_card_reference(card); - -err_adsp_node: - of_node_put(adsp_node); - - return ret; + return 0; } =20 -static struct mt8188_card_data mt8188_evb_card =3D { - .name =3D "mt8188_mt6359", +static const struct mtk_sof_priv mt8188_sof_priv =3D { + .conn_streams =3D g_sof_conn_streams, + .num_streams =3D ARRAY_SIZE(g_sof_conn_streams), +}; + +static const struct mtk_soundcard_pdata mt8188_evb_card =3D { + .card_name =3D "mt8188_mt6359", + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8188_mt6359_soc_card, + .num_jacks =3D MT8188_JACK_MAX, + }, + .sof_priv =3D &mt8188_sof_priv, + .soc_probe =3D mt8188_mt6359_soc_card_probe, }; =20 -static struct mt8188_card_data mt8188_nau8825_card =3D { - .name =3D "mt8188_nau8825", - .quirk =3D NAU8825_HS_PRESENT, +static const struct mtk_soundcard_pdata mt8188_nau8825_card =3D { + .card_name =3D "mt8188_nau8825", + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8188_mt6359_soc_card, + .num_jacks =3D MT8188_JACK_MAX, + .flags =3D NAU8825_HS_PRESENT + }, + .sof_priv =3D &mt8188_sof_priv, + .soc_probe =3D mt8188_mt6359_soc_card_probe, }; =20 -static struct mt8188_card_data mt8188_rt5682s_card =3D { - .name =3D "mt8188_rt5682s", - .quirk =3D RT5682S_HS_PRESENT | MAX98390_TWO_AMP, +static const struct mtk_soundcard_pdata mt8188_rt5682s_card =3D { + .card_name =3D "mt8188_rt5682s", + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8188_mt6359_soc_card, + .num_jacks =3D MT8188_JACK_MAX, + .flags =3D RT5682S_HS_PRESENT | MAX98390_TWO_AMP + }, + .sof_priv =3D &mt8188_sof_priv, + .soc_probe =3D mt8188_mt6359_soc_card_probe, }; =20 -static struct mt8188_card_data mt8188_es8326_card =3D { - .name =3D "mt8188_es8326", - .quirk =3D ES8326_HS_PRESENT | MAX98390_TWO_AMP, +static const struct mtk_soundcard_pdata mt8188_es8326_card =3D { + .card_name =3D "mt8188_es8326", + .card_data =3D &(struct mtk_platform_card_data) { + .card =3D &mt8188_mt6359_soc_card, + .num_jacks =3D MT8188_JACK_MAX, + .flags =3D ES8326_HS_PRESENT | MAX98390_TWO_AMP + }, + .sof_priv =3D &mt8188_sof_priv, + .soc_probe =3D mt8188_mt6359_soc_card_probe, }; =20 static const struct of_device_id mt8188_mt6359_dt_match[] =3D { @@ -1471,7 +1396,7 @@ static struct platform_driver mt8188_mt6359_driver = =3D { .of_match_table =3D mt8188_mt6359_dt_match, .pm =3D &snd_soc_pm_ops, }, - .probe =3D mt8188_mt6359_dev_probe, + .probe =3D mtk_soundcard_common_probe, }; =20 module_platform_driver(mt8188_mt6359_driver); --=20 2.44.0