Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1914802lqe; Tue, 9 Apr 2024 04:37:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWsX5eAEyzN1b8AxLRu4ytiOANLXlwlZxF5Y3txMnDMJjEdokBtsSn4+cNohRetg+HOfr9f85dE5lo3LcNpq/aan5gejJ7/bl82LlI2w== X-Google-Smtp-Source: AGHT+IFKOpcajTPtnb/NxZnwl75bc17NBxqLR5bRamq0QrWGodw9J8O7dlL9bRitlbf7OwLTPuae X-Received: by 2002:a50:d61c:0:b0:56e:33fe:5e88 with SMTP id x28-20020a50d61c000000b0056e33fe5e88mr7688282edi.34.1712662636300; Tue, 09 Apr 2024 04:37:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712662636; cv=pass; d=google.com; s=arc-20160816; b=j5/+1bquGpFaU9lDJP3usYnOGhjvfyU6aJyeOhqy/6KmTGqaecxbh/JXiPwC8m7iYA mac6m4985um005f/WMqzpK3NuzRRV+eEINPShbUuOhxjQnheNHt5iMx0JtPGGmsjn7pA tGaJj2WmQPgYblFZyaEFRDOOZA7KUmtf48Oa5udWYu9lp1jzRn36H7L6MjjtRxVDp13T qPG1A7fES9ojsB6AWUIZh51vbhjvcu8Wdaso1OUsnSQKrhXU0W3Xe479orK01jkuzqk/ 1ZK1ESs7vB49JJ76Hac3QBn1DBAVyz5mRk4o/ghYV3lAB27SqcN94NzC5hX6WUWRgOEs Zq1Q== 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=sJPpxV/LiRw5pfpuG7fERmmUV+5NVcBibNK/az57Tir1tIRfGD0/SJkOcyvh3nF5gi mvz73OwEsevcYv45flR5fOUIl04mIEBN2S0kb5noIglFPVzKKmYoFoTo6jB0W0La7kxa DHyEkz6K/sQXpxn31LGspgJQj78NbIamTgsx+13b1PC6qgofl0YVEs312zHbg31hFZUi 0VqfhBVqRxZ0kCIADe1goxTUMBL9KW70YLk5hEfnxrIm2YiCgc7vDG99IxjdteUDc6f8 z82phOowDUSknwIKr0txQIydhuvLwMZSDT5aQ9rnGVvkQfp7OnQOn975JRLX3rVJgLI9 JAxg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=nOSTlDqJ; 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-136778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136778-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 a11-20020a05640213cb00b0056e528b0004si2711132edx.53.2024.04.09.04.37.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 04:37:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136778-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=nOSTlDqJ; 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-136778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136778-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 D969C1F25591 for ; Tue, 9 Apr 2024 11:37:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2C2B130A4C; Tue, 9 Apr 2024 11:33:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="nOSTlDqJ" 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 BD15F12FF84; Tue, 9 Apr 2024 11:33:48 +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=1712662430; cv=none; b=Jk1cd5a+TLQWkrRKuG6IRL90/h4NvgTImRzpi1mlYPHsrNJm0v1P/41kpWJRr/LZwwG2NhD3laSKOSHj+811Mp8WWTka5wQG4c9YUZNULVZESvT9hooE01RBi0sini4BfnrW0ra2puUxEIsO67B0pMOnSOvFnqWeHNAJqiJ+Q7g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712662430; c=relaxed/simple; bh=8dO/knddMZmgChwWbJp/fcjiVO5qSxhidYiSZvCNm60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nCAs0ZUVEUssoSzuYKNL7tK2HoXYWwTlwu6aZBHjrAy+iZJTM6awMhS2RpwfQL6zstW05DQmLJcjxinqaDNq5byBs9CWuA87OYil9MKVMjS3+Q2fG/IOX2D3q29E9wjTCNvZDVbE9zkPqyhf8G+YtBXtVKlJKWkA0myyMzFrXMM= 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=nOSTlDqJ; 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=1712662427; bh=8dO/knddMZmgChwWbJp/fcjiVO5qSxhidYiSZvCNm60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nOSTlDqJRR/aEs8kZfV08cvdT6yX5D4bfTCXDDGrL5wTboLxsbsE2qlExEd0rH46Y yQd7NEzFb2wHyh1nbPaYgj7PFz7cuWuP0iTajpmVY+Irg6ufFkhwchSoX4DCcswWnm gop1k4z/dDZqzj8MZw54I54DbvSRlVOGebBWcOP7Wqv9zILoLiRDe1oGtU0GA4uPpq od61LTva846zQlaTqfeYWu4fxbvkvnmJi5CWtMeZuX4vgareFfng2SG3D2sU386dqe wWnbynZBdhbEM9AlTJljHVuWsJQeNDB599qwii2M8FBdOK/Ds4bsY3U4xTH+dfT9hU WlHszIVEAvNRw== 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 DA6543782133; Tue, 9 Apr 2024 11:33:44 +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 v4 07/18] ASoC: mediatek: Add common snd_soc_ops .startup() callback Date: Tue, 9 Apr 2024 13:32:59 +0200 Message-ID: <20240409113310.303261-8-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240409113310.303261-1-angelogioacchino.delregno@collabora.com> References: <20240409113310.303261-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