From patchwork Tue Nov 12 10:34:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 842888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 38259D32D8E for ; Tue, 12 Nov 2024 10:36:09 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 8D00D14E4; Tue, 12 Nov 2024 11:35:57 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8D00D14E4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1731407767; bh=pdSncvsYhLrAorO6FVqM+GPIWFy5+i+cKGmIQoIAhm8=; h=From:To:Subject:Date:In-Reply-To:References:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=Kd1BFTxV8Sjl/VZIsoox8tupVXry3jupEXQ5Ca/xzMJjw0+0Q/2k8j/iBMbJstxEk QNA3lXoWs0nIixlRCS2OE/UYNvqizUTqE0VtulLWVRnntQTT+bGP7ZvTlIZsMPgWHs IDESs29PtKlHArMvUppkJiavv7rm39sIC9h3+Cgo= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0BD87F8062E; Tue, 12 Nov 2024 11:34:55 +0100 (CET) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 8F236F80634; Tue, 12 Nov 2024 11:34:55 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D8A0BF805F0; Tue, 12 Nov 2024 11:34:46 +0100 (CET) Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazlp170110001.outbound.protection.outlook.com [IPv6:2a01:111:f403:c200::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D50D4F805EE for ; Tue, 12 Nov 2024 11:34:44 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D50D4F805EE Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector1 header.b=H3MSp4As ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Q+EQjw68E9XWU7o5vejt9HaCUqRL+oNyWB/BdwjEGu55psRBo4ByloSLmhnBQzrNaxvNm8TtktRKmgVlrKyJns8pyIIaCpi8NuxLthLUmkHqSlND6L6vyJsCIIDTHJx8Ngv5bDYMBamVBaAAjll/OlkJ//tBQ6kNAEoVwmBGxnoUnYiyYfKWHX8xm2yCL89JtpMqzXI1j6+7deFWBZdJNmlvbGPRVtHpdpdioGCkN6LQPNFZ1CftUR3KMC8qh+9sWIDPSUjSirtwJfs76uqN5oyNVpdM/SvtjbEmYK4IQnVj3O5E1EX4P0SIzPfmkPlAMDA2bMHaOeOS97BrxsMKcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=asHgnuhLl7u97cA8ELXln78RhYt/mxLwaxyHgw0InHM=; b=ZnvbpYGcZc8G94Ha0CVFwHYsYWQG2OD2E2NP1mEsAO1IjGBSVIyyugIc0jRhqLV1jnUeoGwXGZfohpYZ1DYMcv6a1MWVWO55bxk/Dl8Ua23BeRBGvrDCnU6PqmEjqhj2BSEzRl4YRCTm2z3P8KqwAHrkZ1KYhtjjea4M3p65nqF7o80fSzU+HRWcOWDeHGzAXrpB75k2kxp70H4iuMLQSLnS5uvGKniYwDimC7Q5O4isr1Rx22Q/81ZXCfnsxwRVakiFWyAq2wrcEK1uU93095YC/4woPrtWjFsEawpwlaCi4Q+vosqJbufAWr3J8PyTPuX967cb3kV0uR46YbOvNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=asHgnuhLl7u97cA8ELXln78RhYt/mxLwaxyHgw0InHM=; b=H3MSp4As77kErRkyi+frno9dYJqscxiNEMbV81ceEppmQBQ9Tq2AIZjCvbcQS3oXRsn/C0t5NicqQ9fQUofVtyB3X6LFjuOJWvPfA7Gequay0riqAJp9o3wc5fxC+Ek17+wnupJpCiHZE/P/2XsnnIeeZLhXTDsf+059rKtWGM8c3PhIohZC1rS4RSKuLT4eHNMbM+3U69ZT70LfBcgEZiiSQcDBJ9iyXs2eeA0Nc+OhI7nYxGDj0A0NjlETTmFpu6H0Ch7Joi3QKyoG3oynQMUuW7bXHsm4gLWvAYRHUYpsWfJNyNnF58/uSJNijUFx4HedGibSECa8syKJm87ixg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB7044.eurprd04.prod.outlook.com (2603:10a6:208:191::20) by VI0PR04MB10757.eurprd04.prod.outlook.com (2603:10a6:800:26a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.28; Tue, 12 Nov 2024 10:34:43 +0000 Received: from AM0PR04MB7044.eurprd04.prod.outlook.com ([fe80::7be0:296:768c:e891]) by AM0PR04MB7044.eurprd04.prod.outlook.com ([fe80::7be0:296:768c:e891%6]) with mapi id 15.20.8137.027; Tue, 12 Nov 2024 10:34:43 +0000 From: Shengjiu Wang To: vkoul@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, shengjiu.wang@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, nicoleotsuka@gmail.com, lgirdwood@gmail.com, broonie@kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [RESEND PATCH v5 3/6] ASoC: fsl_easrc: define functions for memory to memory usage Date: Tue, 12 Nov 2024 18:34:01 +0800 Message-Id: <20241112103404.3565675-4-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20241112103404.3565675-1-shengjiu.wang@nxp.com> References: <20241112103404.3565675-1-shengjiu.wang@nxp.com> X-ClientProxiedBy: SI1PR02CA0008.apcprd02.prod.outlook.com (2603:1096:4:1f7::14) To AM0PR04MB7044.eurprd04.prod.outlook.com (2603:10a6:208:191::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB7044:EE_|VI0PR04MB10757:EE_ X-MS-Office365-Filtering-Correlation-Id: 833dbfb7-8024-42cb-c483-08dd03059e87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|7416014|52116014|376014|38350700014|921020; X-Microsoft-Antispam-Message-Info: c75y06nanCWY0TsDXfROwN40jq8L52Snu6OnHk8O7N4bBOXEG9SM9KKIrSpQCGUpY20sa8gWR0XCyOpNhHHAj8TzTiw2zGzJsQ/7nRRsLge4fTYzlDs56JZe/pLqiuudF/0n9LEr9gqNfI1rnozjnadFeVI7fZYXO5AYitTlR4CeQyibP5i98JReAH4z8V/6kyulHlPijZpWcIAursjkQjX7rloCJ6cJ39k+BVKrPq/RPeJCrW//IZTZsurdmQnMx+5gl//kQBxdH8qLlpWXJuvbPGGyR/1JOTDlvh+AsJl5LL6nUFz9HI5pum/P90SJeqLE43Y8yHJwa9GNRQTfHUhd86bk7yTQvqA523hl4ghIf/l7ggxMPdDfc43b30K/ndLRSyLyddjz1zKcA+8tZhTCI4xmr08eniY3NMs7cmXDYYpUKDQaUqGbqTXM0Di+sn6t8+f3UTM03LSF/dwF1U3cMPc+11Z3TM+7W7VulnaVgSAHXxPcWS7vXi/f85PCYhmG2M31/TE+Sg+AIMQmH9GbPHzjJqh1ezueT1+i7g0WCeMkCxV1gzKWfisHzn+OcnuTjWUrZR7nmChnT+v5nGLZaFW29int5g+KHrD23jgdUB00PPvVnvBqRN48R5KRw+Bz8dKPYeoogkE4F5Lg5u/ji0iu5QA590m6nzrxtDbaI2dbp9mKfGacRSPopVt3IkG3UJ+d8gcaZ9xP02b05uH7qvfYa2RA1HEW7lvz/UELehy5KBvXJnj20JWqDcbQjn5wE4gKmCg8FnpYGqKq5hn8wZzmj7cRAdmUky6SSaa1AdyEsRqkxQPG6xNdXinHfM9m+qbh4G1epLvh/9lRq8xh9KTYN4xlNVhAL+k7/0gYkJ5iCF0jW3+oA2b2CmBpmluZUXjpZx+wC/tX1dO0QdPHr//7juTui+NJith79K1zr+qqtiwamxqJeJA2D1pa0cAKkEmboUGz2zpw31pECLi1yWEgwds96UR43uEVxdu1tOut6BTgDtdktc8W/P39yNxsZCnodAOoSm8ci8iTok1zUWpGaQ3/1av9A3IaEqfgWOZ69Uodk27bRySC9F/zWvOdbVq8voAhHVYxzztYjRinOyKeYzYCpHY+xSeZaJ8eyOlEpeu0qawtJoistqzLm66jgiUfhyAzAIXnqDq1ptshFk5uVDr+8HS3ikI6je3TkKJ9m6YNWP2M9qLkwmiZ63NO9eSbWzWp3m/HBDzzIfi8z88nhI0m4O0rHBeJYPhmz30oPYaHtY9pNzqgaCd7av5c+tqWFgGnEvWRMyI0jSxL8M+xmUZTSRQr8bEEmeemtQjkFOyj2wc9n/D/hXprQjcjcsks9yP1ti9KJ2sBZxufnNl5/Sv89syE38urG0rH7OZw8xddIPyBz6Ev5oO9 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB7044.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(7416014)(52116014)(376014)(38350700014)(921020); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZpUWuvGfGBR5GOMLI/ozoLMGw0uTl7FLjUIfpvUR2LAbDVbNGaqdbj54q4u5yJkZcxIO2btKSXiMjWJw7rOR5hPreWO9qVbNtFalxzgwasa2RO+FKjPWFknnJy8ehaGBTG25Chkp8OGzujINtFMLRXrja2qoma62GCmESpMLXfxPjBZw/8/GWegHQwL+5Vbo3yP0KknIW7SAwLYFxSmh+qk03STkfNEksrvEZNTa3BaF88ZsMug9exQZp7oX10f1Mkkgho5c3xb+wxeUZEuTRXm/AtbIgTmKzGUuAc6vRuHjDbnCDu72EGw2ZR1jyyNsQyoYEAHPyJ+G+FiC1ZsmKjodx30KKNLRlTBao8NtZ62IP7fhYxOgvPS+sgMV3MTVTNKifnkT1sGQVAyHayK6l/0ZoyZjT/Qo/MnVrT4edUB4Mc8pvmiJVsGDLo1Pdw+EcaIl8sbPCeMFWBQTSPME4Yg2X0BpIbxJFhPx9IjIU4ymSD+qVYdIL2iy/fiNVzipQispnlwEk6G5LukUQ1NaKYiL2BYim2/0WLwTzdEWCCJpNg4rmM6+yf52QLhJvDZxfscrg8OxBdJA1aMKUSfdo82fhr2WM+LIM+wVGDfbZU6r7W4AXDcb+KF2Sm1/+NWo1HOHtC+2hAQ+oeITKxFUmryvTX2S3DgRQ2MjuUcW/W5aUrl6ivBULRTe13yM5VnydVrBCRt3BVDSRSaKVYAI8UNaH/HYnTpaBmEveWJrkH0oNQ5eq0JWYsQSfQ0gFWh9BeU2EAdr+hcEwcz8z9HOJu/xd3AHphbcnygqoXo/LUmANx0+TH5C4ZM9CvEuTjkgSdVNOkBXgKIXV0AYlRKewyuDrdrrlNo2YRxzUfj2WupJ9y9gpiE7iC3mUMXe+/pZ13/yjid81obgMBKaVS4JGeRcsR2UNPoLPGA0wAo0DbM8SRjPWGmAgfXfAdNlzqSEKPJYnheBOrkXq91/tv7zNseBufQDjx4mjKpLz5aQ3+0FnQPNRUIhSJC6TtKJrZDVYA0loa3SK1AfX/OUTpLeFXe9jClqbUI60mItRnwHG3EwQXhoFnNResIcl/93romDlZ2TxL0bXfpqF6bomDrTHXioc5qNU9E/NaRJAojx+PJemGfx3pS42BhVjYXtiBD/TMph9CcZ7C8Vtaq52STqhoCPqSiDqkIkgkY9znkTvF3GrfOEO/LGNMMiypXwjQqlu4xsLvKMB1jPCngevKowO0J+kwzRG5kkQIS7DbJl6TBPThtuWVvpN/Z4FTDhcgM4RVoiUyZXXq6PhNVR5OrMQZIm/CdVT1UB27baV6HmP9u/bQrislrLqF6VHvpglzRJ4JpHRjZ3HeGbtZv42nViiNs7Wf9zBckCaRs6ndSylt7tD661DZH+HtrK9MllrT5hMxk2jO9PZ8ayGiUfoeq0jZHFJZpuMyz1SpTU8jF4EQvAi2n8L68cwHFJRVBlC5fSJVoqzrrEIpzFMe24UnN7DyUBcPHnqjn2bRJGQUZcAG+uCKOlYXgE4rZnyCzW1T6l36WIzPXseuC1s33H1NJ16afuBbkWs6J1BtrmN7PAkmP8nx8uS9k2meDp5b6D5CQ8 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 833dbfb7-8024-42cb-c483-08dd03059e87 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB7044.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 10:34:42.9600 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: It4piUhJiI2B9pCobzwMBB5Pt6PKJoKBHx1r8ok0wGbuEnIQ5sOfwJtSIiAsU4+UQHMk1qcvUib9KvTyDzJomg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0PR04MB10757 Message-ID-Hash: VUAQXOI7D7IWFJAR6ZRA3XG4YD4PUSTB X-Message-ID-Hash: VUAQXOI7D7IWFJAR6ZRA3XG4YD4PUSTB X-MailFrom: shengjiu.wang@nxp.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: ASRC can be used on memory to memory case, define several functions for m2m usage and export them as function pointer. Signed-off-by: Shengjiu Wang Acked-by: Jaroslav Kysela --- sound/soc/fsl/fsl_easrc.c | 228 ++++++++++++++++++++++++++++++++++++++ sound/soc/fsl/fsl_easrc.h | 4 + 2 files changed, 232 insertions(+) diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c index d22f0621c465..f17a185a1910 100644 --- a/sound/soc/fsl/fsl_easrc.c +++ b/sound/soc/fsl/fsl_easrc.c @@ -1861,6 +1861,224 @@ static int fsl_easrc_get_fifo_addr(u8 dir, enum asrc_pair_index index) return REG_EASRC_FIFO(dir, index); } +/* Get sample numbers in FIFO */ +static unsigned int fsl_easrc_get_output_fifo_size(struct fsl_asrc_pair *pair) +{ + struct fsl_asrc *asrc = pair->asrc; + enum asrc_pair_index index = pair->index; + u32 val; + + regmap_read(asrc->regmap, REG_EASRC_SFS(index), &val); + val &= EASRC_SFS_NSGO_MASK; + + return val >> EASRC_SFS_NSGO_SHIFT; +} + +static int fsl_easrc_m2m_prepare(struct fsl_asrc_pair *pair) +{ + struct fsl_easrc_ctx_priv *ctx_priv = pair->private; + struct fsl_asrc *asrc = pair->asrc; + struct device *dev = &asrc->pdev->dev; + int ret; + + ctx_priv->in_params.sample_rate = pair->rate[IN]; + ctx_priv->in_params.sample_format = pair->sample_format[IN]; + ctx_priv->out_params.sample_rate = pair->rate[OUT]; + ctx_priv->out_params.sample_format = pair->sample_format[OUT]; + + ctx_priv->in_params.fifo_wtmk = FSL_EASRC_INPUTFIFO_WML; + ctx_priv->out_params.fifo_wtmk = FSL_EASRC_OUTPUTFIFO_WML; + /* Fill the right half of the re-sampler with zeros */ + ctx_priv->rs_init_mode = 0x2; + /* Zero fill the right half of the prefilter */ + ctx_priv->pf_init_mode = 0x2; + + ret = fsl_easrc_set_ctx_format(pair, + &ctx_priv->in_params.sample_format, + &ctx_priv->out_params.sample_format); + if (ret) { + dev_err(dev, "failed to set context format: %d\n", ret); + return ret; + } + + ret = fsl_easrc_config_context(asrc, pair->index); + if (ret) { + dev_err(dev, "failed to config context %d\n", ret); + return ret; + } + + ctx_priv->in_params.iterations = 1; + ctx_priv->in_params.group_len = pair->channels; + ctx_priv->in_params.access_len = pair->channels; + ctx_priv->out_params.iterations = 1; + ctx_priv->out_params.group_len = pair->channels; + ctx_priv->out_params.access_len = pair->channels; + + ret = fsl_easrc_set_ctx_organziation(pair); + if (ret) { + dev_err(dev, "failed to set fifo organization\n"); + return ret; + } + + /* The context start flag */ + pair->first_convert = 1; + return 0; +} + +static int fsl_easrc_m2m_start(struct fsl_asrc_pair *pair) +{ + /* start context once */ + if (pair->first_convert) { + fsl_easrc_start_context(pair); + pair->first_convert = 0; + } + + return 0; +} + +static int fsl_easrc_m2m_stop(struct fsl_asrc_pair *pair) +{ + /* Stop pair/context */ + if (!pair->first_convert) { + fsl_easrc_stop_context(pair); + pair->first_convert = 1; + } + + return 0; +} + +/* calculate capture data length according to output data length and sample rate */ +static int fsl_easrc_m2m_calc_out_len(struct fsl_asrc_pair *pair, int input_buffer_length) +{ + struct fsl_asrc *easrc = pair->asrc; + struct fsl_easrc_priv *easrc_priv = easrc->private; + struct fsl_easrc_ctx_priv *ctx_priv = pair->private; + unsigned int in_rate = ctx_priv->in_params.norm_rate; + unsigned int out_rate = ctx_priv->out_params.norm_rate; + unsigned int channels = pair->channels; + unsigned int in_samples, out_samples; + unsigned int in_width, out_width; + unsigned int out_length; + unsigned int frac_bits; + u64 val1, val2; + + switch (easrc_priv->rs_num_taps) { + case EASRC_RS_32_TAPS: + /* integer bits = 5; */ + frac_bits = 39; + break; + case EASRC_RS_64_TAPS: + /* integer bits = 6; */ + frac_bits = 38; + break; + case EASRC_RS_128_TAPS: + /* integer bits = 7; */ + frac_bits = 37; + break; + default: + return -EINVAL; + } + + val1 = (u64)in_rate << frac_bits; + do_div(val1, out_rate); + val1 += (s64)ctx_priv->ratio_mod << (frac_bits - 31); + + in_width = snd_pcm_format_physical_width(ctx_priv->in_params.sample_format) / 8; + out_width = snd_pcm_format_physical_width(ctx_priv->out_params.sample_format) / 8; + + ctx_priv->in_filled_len += input_buffer_length; + if (ctx_priv->in_filled_len <= ctx_priv->in_filled_sample * in_width * channels) { + out_length = 0; + } else { + in_samples = ctx_priv->in_filled_len / (in_width * channels) - + ctx_priv->in_filled_sample; + + /* right shift 12 bit to make ratio in 32bit space */ + val2 = (u64)in_samples << (frac_bits - 12); + val1 = val1 >> 12; + do_div(val2, val1); + out_samples = val2; + + out_length = out_samples * out_width * channels; + ctx_priv->in_filled_len = ctx_priv->in_filled_sample * in_width * channels; + } + + return out_length; +} + +static int fsl_easrc_m2m_get_maxburst(u8 dir, struct fsl_asrc_pair *pair) +{ + struct fsl_easrc_ctx_priv *ctx_priv = pair->private; + + if (dir == IN) + return ctx_priv->in_params.fifo_wtmk * pair->channels; + else + return ctx_priv->out_params.fifo_wtmk * pair->channels; +} + +static int fsl_easrc_m2m_pair_suspend(struct fsl_asrc_pair *pair) +{ + fsl_easrc_stop_context(pair); + + return 0; +} + +static int fsl_easrc_m2m_pair_resume(struct fsl_asrc_pair *pair) +{ + struct fsl_easrc_ctx_priv *ctx_priv = pair->private; + + pair->first_convert = 1; + ctx_priv->in_filled_len = 0; + + return 0; +} + +/* val is Q31 */ +static int fsl_easrc_m2m_set_ratio_mod(struct fsl_asrc_pair *pair, int val) +{ + struct fsl_easrc_ctx_priv *ctx_priv = pair->private; + struct fsl_asrc *easrc = pair->asrc; + struct fsl_easrc_priv *easrc_priv = easrc->private; + unsigned int frac_bits; + + ctx_priv->ratio_mod += val; + + switch (easrc_priv->rs_num_taps) { + case EASRC_RS_32_TAPS: + /* integer bits = 5; */ + frac_bits = 39; + break; + case EASRC_RS_64_TAPS: + /* integer bits = 6; */ + frac_bits = 38; + break; + case EASRC_RS_128_TAPS: + /* integer bits = 7; */ + frac_bits = 37; + break; + default: + return -EINVAL; + } + + val <<= (frac_bits - 31); + regmap_write(easrc->regmap, REG_EASRC_RUC(pair->index), EASRC_RSUC_RS_RM(val)); + + return 0; +} + +static int fsl_easrc_m2m_get_cap(struct fsl_asrc_m2m_cap *cap) +{ + cap->fmt_in = FSL_EASRC_FORMATS; + cap->fmt_out = FSL_EASRC_FORMATS | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE; + cap->rate_in = easrc_rates; + cap->rate_in_count = ARRAY_SIZE(easrc_rates); + cap->rate_out = easrc_rates; + cap->rate_out_count = ARRAY_SIZE(easrc_rates); + cap->chan_min = 1; + cap->chan_max = 32; + return 0; +} + static const struct of_device_id fsl_easrc_dt_ids[] = { { .compatible = "fsl,imx8mn-easrc",}, {} @@ -1926,6 +2144,16 @@ static int fsl_easrc_probe(struct platform_device *pdev) easrc->release_pair = fsl_easrc_release_context; easrc->get_fifo_addr = fsl_easrc_get_fifo_addr; easrc->pair_priv_size = sizeof(struct fsl_easrc_ctx_priv); + easrc->m2m_prepare = fsl_easrc_m2m_prepare; + easrc->m2m_start = fsl_easrc_m2m_start; + easrc->m2m_stop = fsl_easrc_m2m_stop; + easrc->get_output_fifo_size = fsl_easrc_get_output_fifo_size; + easrc->m2m_calc_out_len = fsl_easrc_m2m_calc_out_len; + easrc->m2m_get_maxburst = fsl_easrc_m2m_get_maxburst; + easrc->m2m_pair_suspend = fsl_easrc_m2m_pair_suspend; + easrc->m2m_pair_resume = fsl_easrc_m2m_pair_resume; + easrc->m2m_set_ratio_mod = fsl_easrc_m2m_set_ratio_mod; + easrc->m2m_get_cap = fsl_easrc_m2m_get_cap; easrc_priv->rs_num_taps = EASRC_RS_32_TAPS; easrc_priv->const_coeff = 0x3FF0000000000000; diff --git a/sound/soc/fsl/fsl_easrc.h b/sound/soc/fsl/fsl_easrc.h index 7c70dac52713..c9f770862662 100644 --- a/sound/soc/fsl/fsl_easrc.h +++ b/sound/soc/fsl/fsl_easrc.h @@ -601,6 +601,8 @@ struct fsl_easrc_slot { * @out_missed_sample: sample missed in output * @st1_addexp: exponent added for stage1 * @st2_addexp: exponent added for stage2 + * @ratio_mod: update ratio + * @in_filled_len: input filled length */ struct fsl_easrc_ctx_priv { struct fsl_easrc_io_params in_params; @@ -618,6 +620,8 @@ struct fsl_easrc_ctx_priv { int out_missed_sample; int st1_addexp; int st2_addexp; + int ratio_mod; + unsigned int in_filled_len; }; /**