Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp500748lqi; Thu, 7 Mar 2024 03:48:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUs/uYqYy+rzZyC0kyMC6L8WMVUprbFwPEZwhk1YVK3GPvEUse3i+VetIvMZ4uF+qvBc8fztmBSRtNXE6yY0pREgZv35SemyJ/Ehp1niA== X-Google-Smtp-Source: AGHT+IGDTZSTdMfKpHqFirCWirrmmShZ1qYmE2Q4jfc3eRqwXXmqI4tVo7nd2uTJq5IAL/6+gHMe X-Received: by 2002:a50:85c6:0:b0:565:9fff:6046 with SMTP id q6-20020a5085c6000000b005659fff6046mr13679311edh.3.1709812130508; Thu, 07 Mar 2024 03:48:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709812130; cv=pass; d=google.com; s=arc-20160816; b=kfij/sBHzOmuT7c8yBcev6r91KYLFnxFt7NClvJ7eiem6BF6CXZaxb87H1badzHDev O+T5gHssHMbCxWxOAijgSH+3kbBxhZ1thCbOTO8wheS9ll/G+lZUP3Ff+BlwhEGpCy6N 960ePxey0U/FAwaL41fbq+2xU19EeZ1fj0hWdMYAtugONZssZeSXVSmLaH39uoTgVJtd iidqJ8Ef4r5XdpjWQDSad7iCJtmXbHDj9KvhySd63XXPqoeJ0k5khYHIs4OeWJZx0kAr gwOpGTYOuxom8lSToLLvuKToDXPX7s13Kf+6iDdXCQ2jB5pZg0uqv7c30xOHmxdNyx8d jWFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=P90T8msM0dbODByQdEj03PcAYsjq7ciKHVblE8vGmc4=; fh=9iEt4iCRn9CzCxci4w2sdEG90CBf9Xi5ef9RsAZByLs=; b=JcviSXetLyH6eGZvMxU7FSWSilH3GQf7ts7pWLA1d8+wn6AJvzkO3yGZOrGoksVlJo LSrcP4qynekv8KKyW8qPj8uP5fpY3iwYLD228QI7+AFC1pm1zoU3dwZ2lDP1IT94rEyL SeoeP/kYZ/h47886kr/jxeA07MCyPwtI1nU6vxcIgQAzalSnvqmzictaGmZPT9blvF17 vV8TZJ4wiqkgPUQK+8RB37g/WcWt3ZWSbfA5odmyVWjkEGIob58oVQ5WltX1ACkz5AtQ m7k2TcC/JcEZqbhlSeFzFOqLoK4ptPKS7iN/7h/fEPMzF5WWQ0cNY7VZ4dsakQe/Mm8+ yIbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=M5udTz2w; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-95472-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95472-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q15-20020a056402518f00b00565e08477b6si7147034edd.139.2024.03.07.03.48.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 03:48:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95472-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=M5udTz2w; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-95472-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95472-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 11DD21F23753 for ; Thu, 7 Mar 2024 11:48:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 799E112CDAF; Thu, 7 Mar 2024 11:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="M5udTz2w" 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 A043112D76D; Thu, 7 Mar 2024 11:45:20 +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=1709811922; cv=none; b=krGmfHZDBqni+M/qfldeGeJfWyrYXPi9o52PNSR2nrsAiDERbI2BfbJIt4p6/3sQuJ5ohfyJLCiuVyEix6YtztzsLAyls07Hw3+p5BmjjH/QH+rbrvlWCO9Xp1jDTrcZ6Mlg1Zmife8eZsOWuuKGvB9wg52Zn3eaLSYvFuE19qc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709811922; c=relaxed/simple; bh=8dO/knddMZmgChwWbJp/fcjiVO5qSxhidYiSZvCNm60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=orb0EXU/hIDavLSr21YE+IXNIcwqA8HnWTL86Ik9Kf8qUfaJQW+ABRMGaObDAofOdaTGdW6Pb6301Y/7/Xr3HtOLPjeqJIR6dKFBLLcdcG9T/RDNDZFmttAwTPwTiVEgtKgxduZF21Rt40C4eTJuEEnF7mTrsvTy8XOnM/134aU= 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=M5udTz2w; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709811919; bh=8dO/knddMZmgChwWbJp/fcjiVO5qSxhidYiSZvCNm60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M5udTz2wfvChTn94NCUrsgAFSKZ2d2X5UuphMjLjli3ARg0Ke9TmMKa/ZmrMIf1xN odBfOymsQ9dm7yuar/xHH4+/PFZdB3nDEIK9Gf45wn1VTCIXbVCr2F9HJv5h64No+i /CbmKmnkEvzyIlHOhRSozE4Dk+y3RNU8eZWHd8M9yE379ZJN7yWBiRP/TjJzKA73PS GHD8q5CfaBNTPnGv6SBfinSPZ/4oFTRu++8GvUtWOB9XKwOdkkt8L3+kVoFkm8JX9e Xu1vlnD9bgPscgZJeUEsPrAmXM7EjBriRqPt3UVWyU+p1BjyAm8IGIh8lQU4jpZCtg /EYpfNdaqV2Og== 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 1E13B37820EC; Thu, 7 Mar 2024 11:45:17 +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 11/22] ASoC: mediatek: Add common snd_soc_ops .startup() callback Date: Thu, 7 Mar 2024 12:44:34 +0100 Message-ID: <20240307114445.196981-12-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: 8bit MediaTek platforms are typically setting PCM rate and channels constraints for playback, capture and HDMI/DisplayPort playback: commonize the startup callback by adding the PCM constraints data to the mtk_platform_card_data structure and by reusing the common mtk_soundcard_startup() function for all of them by getting back the parameters from the aforementioned struct. Signed-off-by: AngeloGioacchino Del Regno --- .../mediatek/common/mtk-soundcard-driver.c | 51 +++++++++++++++++++ .../mediatek/common/mtk-soundcard-driver.h | 24 +++++++++ 2 files changed, 75 insertions(+) diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.c b/sound/soc/mediatek/common/mtk-soundcard-driver.c index b1db17e392d5..d344630f7851 100644 --- a/sound/soc/mediatek/common/mtk-soundcard-driver.c +++ b/sound/soc/mediatek/common/mtk-soundcard-driver.c @@ -139,6 +139,57 @@ void clean_card_reference(struct snd_soc_card *card) } EXPORT_SYMBOL_GPL(clean_card_reference); +int mtk_soundcard_startup(struct snd_pcm_substream *substream, + enum mtk_pcm_constraint_type ctype) +{ + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct mtk_soc_card_data *soc_card = snd_soc_card_get_drvdata(rtd->card); + const struct mtk_pcm_constraints_data *mpc = &soc_card->card_data->pcm_constraints[ctype]; + int ret; + + if (unlikely(!mpc)) + return -EINVAL; + + ret = snd_pcm_hw_constraint_list(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, + &mpc->rates); + if (ret < 0) { + dev_err(rtd->dev, "hw_constraint_list rate failed\n"); + return ret; + } + + ret = snd_pcm_hw_constraint_list(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_CHANNELS, + &mpc->channels); + if (ret < 0) { + dev_err(rtd->dev, "hw_constraint_list channel failed\n"); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(mtk_soundcard_startup); + +static int mtk_soundcard_playback_startup(struct snd_pcm_substream *substream) +{ + return mtk_soundcard_startup(substream, MTK_CONSTRAINT_PLAYBACK); +} + +const struct snd_soc_ops mtk_soundcard_common_playback_ops = { + .startup = mtk_soundcard_playback_startup, +}; +EXPORT_SYMBOL_GPL(mtk_soundcard_common_playback_ops); + +static int mtk_soundcard_capture_startup(struct snd_pcm_substream *substream) +{ + return mtk_soundcard_startup(substream, MTK_CONSTRAINT_CAPTURE); +} + +const struct snd_soc_ops mtk_soundcard_common_capture_ops = { + .startup = mtk_soundcard_capture_startup, +}; +EXPORT_SYMBOL_GPL(mtk_soundcard_common_capture_ops); + int mtk_soundcard_common_probe(struct platform_device *pdev) { struct device_node *platform_node, *adsp_node; diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.h b/sound/soc/mediatek/common/mtk-soundcard-driver.h index 4fd2ffb7e486..c38e2ac09ad3 100644 --- a/sound/soc/mediatek/common/mtk-soundcard-driver.h +++ b/sound/soc/mediatek/common/mtk-soundcard-driver.h @@ -11,11 +11,26 @@ struct mtk_sof_priv; struct mtk_soc_card_data; +struct snd_pcm_hw_constraint_list; + +enum mtk_pcm_constraint_type { + MTK_CONSTRAINT_PLAYBACK, + MTK_CONSTRAINT_CAPTURE, + MTK_CONSTRAINT_HDMIDP, + MTK_CONSTRAINT_MAX +}; + +struct mtk_pcm_constraints_data { + const struct snd_pcm_hw_constraint_list channels; + const struct snd_pcm_hw_constraint_list rates; +}; struct mtk_platform_card_data { struct snd_soc_card *card; struct snd_soc_jack *jacks; + const struct mtk_pcm_constraints_data *pcm_constraints; u8 num_jacks; + u8 num_pcm_constraints; u8 flags; }; @@ -23,9 +38,18 @@ struct mtk_soundcard_pdata { const char *card_name; struct mtk_platform_card_data *card_data; const struct mtk_sof_priv *sof_priv; + int (*soc_probe)(struct mtk_soc_card_data *card_data, bool legacy); }; +/* Common playback/capture card startup ops */ +extern const struct snd_soc_ops mtk_soundcard_common_playback_ops; +extern const struct snd_soc_ops mtk_soundcard_common_capture_ops; + +/* Exported for custom/extended soundcard startup ops */ +int mtk_soundcard_startup(struct snd_pcm_substream *substream, + enum mtk_pcm_constraint_type ctype); + int parse_dai_link_info(struct snd_soc_card *card); void clean_card_reference(struct snd_soc_card *card); int mtk_soundcard_common_probe(struct platform_device *pdev); -- 2.44.0