From nobody Mon Nov 25 09:51:56 2024 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2087.outbound.protection.outlook.com [40.107.105.87]) (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 5996E18C91F; Tue, 29 Oct 2024 02:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730167875; cv=fail; b=ud0NlaACTKpvFH5xR+LkwXDW0a4xo+Tr5lwD0Q4kOjQv3w1kMPo/VlTnvYV7DIHCQlsMuvn4ISsHfBzlXjkDc1uEsn75oPjS3/ncsQNlmpExHEnZyAEu6k/3VBMJyB7EwDR/h3FpQ9EpeNZxIR/oJZA2+EHm+xehRaeYl7BxByQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730167875; c=relaxed/simple; bh=pdSncvsYhLrAorO6FVqM+GPIWFy5+i+cKGmIQoIAhm8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=IZtJDSu2Y+LpOOz2QLzBpKPqFI6gipncj9DOZ6NqFmhD7+PYzHA4Er42/WOdpBZS6Vo2DPoFhTSOVyQtX0CRfCTWbURMBneafxQL+7TLwP1PD9UiiGNCTYPrl+fpn2Cserj4JMmkN6rSysckPDtZFNSvHNJ3GCqC4W0blIWxT7Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=ATNnotJ0; arc=fail smtp.client-ip=40.107.105.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="ATNnotJ0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Oz0FKKpJC83pt4oFHaqm8JzkjUiKiREXflpCorO1K6I23Qg0cH76IPXehROQpYqmChqcBl7wlgVDV1dOZMo2hbQDqN1Q1U2QwKxm9fUxnP6kIejR1Rjs6vE3kY3ksFmdRQFyYnFu/RCxZTHwv6vdzr5lfNtk3J9LjFsB2SMaHBtYsA//3JCo2k4LHbL57sXQfrL59qdYK+dpnTdrFhX5MimFE3dzDMsXc47yPdaILKTv4g+R9cse3oAsZqNWXA6mpf4nPhe39kdcjqOpd5sd+GVeYT0ZpkRk+jz0KCSShKD3yciXjOuq+mpDwQjaer729oso//rrtiu6HkPYnQP8iA== 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=BzADbvMztVt6ZantumeTHbYY78xulRpypDonxS7bacGxP87XIwfZya46dPynI3nstQnZWbrnPatqcqyTMOmsquTpt2LPcQg/bv1UHpgDhGPkUkw5WLE2eDYqKkyLusQBxsGNUyij7d5uyXptHGjGVCf75w0ZWr83deO1LO6owMd1jDEw+ReuuG1NAq9mvwyd7E7IR//JAhLjGGhquru5KjquZFCMdTlRvomZjbXO93zgc9QRsuCUoXLcA39yi29JopmnuR7QyqdjTgAQoa6V/8xSrmCl/eS0zVYXV+cKU9/ZNEDVY+qk+QR/GDbcJ4AWUM2oiyITw36humlTIYz9Pw== 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=ATNnotJ0sA7mm0T8DszCSPFlEEa/LzRdiaPDmQcY4SpflfpWtu8xOlfVKA2BZ4g/vNYMo6pR3lDSkk0/avKfOnWrgUEXeOPGcHCWKzK5i9XZ3LES7ZgjKffpGFV8dSx1pYuVADCJeYjJ8TD134NDKOboF4f+AmrP8PuH0+TosBHh5I1opdaj+7fniZ3JQda8k4dUjC/ffgHlxG+tbtcvmBOGOr216yzf8WzT8/Y4tC0h20oEkWkG4LpGgBG+zvTSpdGEXvTLDILAneoG9B60L/Elu5KEvb3fpOk1oqM20ZbSFVHC/huhTa90ir9/77Y8zpr3JE5y/1OOQ6BNb+cn+g== 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 DU2PR04MB9147.eurprd04.prod.outlook.com (2603:10a6:10:2f6::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Tue, 29 Oct 2024 02:11:08 +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.8093.023; Tue, 29 Oct 2024 02:11:08 +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: [PATCH v5 3/6] ASoC: fsl_easrc: define functions for memory to memory usage Date: Tue, 29 Oct 2024 10:20:54 +0800 Message-Id: <20241029022057.816402-4-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20241029022057.816402-1-shengjiu.wang@nxp.com> References: <20241029022057.816402-1-shengjiu.wang@nxp.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI2PR01CA0031.apcprd01.prod.exchangelabs.com (2603:1096:4:192::11) To AM0PR04MB7044.eurprd04.prod.outlook.com (2603:10a6:208:191::20) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB7044:EE_|DU2PR04MB9147:EE_ X-MS-Office365-Filtering-Correlation-Id: d091dd3b-07da-4f53-23a0-08dcf7bef3a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|52116014|1800799024|366016|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?D6+DVRqj0OLGPH7+2qyZlQpCepNVARhfAyRdR4x/fsteDexLzdRE4g7kA4HI?= =?us-ascii?Q?W8ciOIrv3ehJ9i9DwMVDpvOPqNfIC1RMQPmIgTJyjxJenAfxJ4luw97WULXQ?= =?us-ascii?Q?on2Jj7YYVz3zVRzSxDcq7RKAecDfDLf+3UZcnsbNwrRDpsPG9JEMfuQNWEiu?= =?us-ascii?Q?rxPk8gf+Ane4zWsQ9+Z3AP2zWIFRiolZyxGLPfmtHoosnw6oHvzHFV0n8YNy?= =?us-ascii?Q?sZ5JyyrbymUsDBNWU5fl4EChv8dlGA1ZrvtotlcLxW/8GM1wcQbKOMya5t7g?= =?us-ascii?Q?KZzexKOrTl1vcv21WJl0UDaqiu/zGBXBzy+213h+AqDH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Iys8OibOLgqjy2hqXsGtMtuNxPnk/2pr6VQzWdbqfyrShW?= =?us-ascii?Q?2k3CGcrRk3+3TFbIGLapIXkJ9nnDUxykhaqD2dMhNSPK4Xcdli8Lyxzyp6fD?= =?us-ascii?Q?FGSMuWSCHkXenxdrNc0ImI2FHIGdThfTfhprxN6xGNHu5NniLOFNzvyqzP1Q?= =?us-ascii?Q?RkeBZa69iAK+Kw+ibUPXkdRsEHSf?= 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)(7416014)(376014)(52116014)(1800799024)(366016)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?NJISlu6V+pd5gwO467aojuPio7sPiI7WofVJivl66cMHfcmmv8mU56Y71V4d?= =?us-ascii?Q?QiUpx75Ux2YOOZtc3biK13bqTG4y25tPyAX1wgEWGPP4Ulwf3pCUQ6WuYpZ7?= =?us-ascii?Q?KtWTVp3nNzU8dyMLfPsIMJz6nMuDmiYQcHCRjzLgurIlFUt2b5288BAxFN1W?= =?us-ascii?Q?GYKvH4mUoWTtnv5+Mh4UYV/MRY6nqkS0/gwFFNhcsC6LmZUYkiTZORxeKWTA?= =?us-ascii?Q?YztVqCtaiC6mfZfCQ2av0J5KRaMAwscCU7shVgItFHb1kYkFKK3e37uita2q?= =?us-ascii?Q?Wm8IamV5O4D4A/cQ67PGBViaVnZqigNdWR4ql5qUKS31owzZ7BCje3CvODug?= =?us-ascii?Q?7ODErjKC/Uolp83+wrRqjfw1eMPR+qUm40qQUtXEm9lZPWP5zcNLMjbC9Kt5?= =?us-ascii?Q?A+9/lWZGPrYr1EaC4LeAHgQBZxBpnM9CWql/QTSMGD8fJwflCup/2wuXLxJP?= =?us-ascii?Q?KqknzZD65ex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ZjDpS2?= =?us-ascii?Q?AvjVCLOAOPoRWKtcqwXzDIE5ahwdOMtnBy/yku9DvjfxRkchPZ5CF2ifVweA?= =?us-ascii?Q?NijtFZ49LcHdjMhNxQUrLjSoZ1N/sJyJEwv1oQh+/neRWpri7AgOBCWXTEkE?= =?us-ascii?Q?pMm4iKauuT6lS76YVjmNp673qBRAPeZmMJidSL3UyqHRyJF7FXHfGexWUDsj?= =?us-ascii?Q?MYVpY3hIDuUbNOHu0q6W74q4JxKpEwvSySQ1hz92?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d091dd3b-07da-4f53-23a0-08dcf7bef3a4 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB7044.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 02:11:08.5653 (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: jr65gSRJtMFojErHxKDGmYdOu30KBG63Mn379bv0BwXiWHnYJzeBgM86K+lJ8ukU4IvKJ6K1dvLfohhJNr9TGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB9147 Content-Type: text/plain; charset="utf-8" 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 asr= c_pair_index index) return REG_EASRC_FIFO(dir, index); } =20 +/* Get sample numbers in FIFO */ +static unsigned int fsl_easrc_get_output_fifo_size(struct fsl_asrc_pair *p= air) +{ + struct fsl_asrc *asrc =3D pair->asrc; + enum asrc_pair_index index =3D pair->index; + u32 val; + + regmap_read(asrc->regmap, REG_EASRC_SFS(index), &val); + val &=3D 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 =3D pair->private; + struct fsl_asrc *asrc =3D pair->asrc; + struct device *dev =3D &asrc->pdev->dev; + int ret; + + ctx_priv->in_params.sample_rate =3D pair->rate[IN]; + ctx_priv->in_params.sample_format =3D pair->sample_format[IN]; + ctx_priv->out_params.sample_rate =3D pair->rate[OUT]; + ctx_priv->out_params.sample_format =3D pair->sample_format[OUT]; + + ctx_priv->in_params.fifo_wtmk =3D FSL_EASRC_INPUTFIFO_WML; + ctx_priv->out_params.fifo_wtmk =3D FSL_EASRC_OUTPUTFIFO_WML; + /* Fill the right half of the re-sampler with zeros */ + ctx_priv->rs_init_mode =3D 0x2; + /* Zero fill the right half of the prefilter */ + ctx_priv->pf_init_mode =3D 0x2; + + ret =3D 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 =3D 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 =3D 1; + ctx_priv->in_params.group_len =3D pair->channels; + ctx_priv->in_params.access_len =3D pair->channels; + ctx_priv->out_params.iterations =3D 1; + ctx_priv->out_params.group_len =3D pair->channels; + ctx_priv->out_params.access_len =3D pair->channels; + + ret =3D 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 =3D 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 =3D 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 =3D 1; + } + + return 0; +} + +/* calculate capture data length according to output data length and sampl= e rate */ +static int fsl_easrc_m2m_calc_out_len(struct fsl_asrc_pair *pair, int inpu= t_buffer_length) +{ + struct fsl_asrc *easrc =3D pair->asrc; + struct fsl_easrc_priv *easrc_priv =3D easrc->private; + struct fsl_easrc_ctx_priv *ctx_priv =3D pair->private; + unsigned int in_rate =3D ctx_priv->in_params.norm_rate; + unsigned int out_rate =3D ctx_priv->out_params.norm_rate; + unsigned int channels =3D 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 =3D 5; */ + frac_bits =3D 39; + break; + case EASRC_RS_64_TAPS: + /* integer bits =3D 6; */ + frac_bits =3D 38; + break; + case EASRC_RS_128_TAPS: + /* integer bits =3D 7; */ + frac_bits =3D 37; + break; + default: + return -EINVAL; + } + + val1 =3D (u64)in_rate << frac_bits; + do_div(val1, out_rate); + val1 +=3D (s64)ctx_priv->ratio_mod << (frac_bits - 31); + + in_width =3D snd_pcm_format_physical_width(ctx_priv->in_params.sample_for= mat) / 8; + out_width =3D snd_pcm_format_physical_width(ctx_priv->out_params.sample_f= ormat) / 8; + + ctx_priv->in_filled_len +=3D input_buffer_length; + if (ctx_priv->in_filled_len <=3D ctx_priv->in_filled_sample * in_width * = channels) { + out_length =3D 0; + } else { + in_samples =3D ctx_priv->in_filled_len / (in_width * channels) - + ctx_priv->in_filled_sample; + + /* right shift 12 bit to make ratio in 32bit space */ + val2 =3D (u64)in_samples << (frac_bits - 12); + val1 =3D val1 >> 12; + do_div(val2, val1); + out_samples =3D val2; + + out_length =3D out_samples * out_width * channels; + ctx_priv->in_filled_len =3D ctx_priv->in_filled_sample * in_width * chan= nels; + } + + return out_length; +} + +static int fsl_easrc_m2m_get_maxburst(u8 dir, struct fsl_asrc_pair *pair) +{ + struct fsl_easrc_ctx_priv *ctx_priv =3D pair->private; + + if (dir =3D=3D 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 =3D pair->private; + + pair->first_convert =3D 1; + ctx_priv->in_filled_len =3D 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 =3D pair->private; + struct fsl_asrc *easrc =3D pair->asrc; + struct fsl_easrc_priv *easrc_priv =3D easrc->private; + unsigned int frac_bits; + + ctx_priv->ratio_mod +=3D val; + + switch (easrc_priv->rs_num_taps) { + case EASRC_RS_32_TAPS: + /* integer bits =3D 5; */ + frac_bits =3D 39; + break; + case EASRC_RS_64_TAPS: + /* integer bits =3D 6; */ + frac_bits =3D 38; + break; + case EASRC_RS_128_TAPS: + /* integer bits =3D 7; */ + frac_bits =3D 37; + break; + default: + return -EINVAL; + } + + val <<=3D (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 =3D FSL_EASRC_FORMATS; + cap->fmt_out =3D FSL_EASRC_FORMATS | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE; + cap->rate_in =3D easrc_rates; + cap->rate_in_count =3D ARRAY_SIZE(easrc_rates); + cap->rate_out =3D easrc_rates; + cap->rate_out_count =3D ARRAY_SIZE(easrc_rates); + cap->chan_min =3D 1; + cap->chan_max =3D 32; + return 0; +} + static const struct of_device_id fsl_easrc_dt_ids[] =3D { { .compatible =3D "fsl,imx8mn-easrc",}, {} @@ -1926,6 +2144,16 @@ static int fsl_easrc_probe(struct platform_device *p= dev) easrc->release_pair =3D fsl_easrc_release_context; easrc->get_fifo_addr =3D fsl_easrc_get_fifo_addr; easrc->pair_priv_size =3D sizeof(struct fsl_easrc_ctx_priv); + easrc->m2m_prepare =3D fsl_easrc_m2m_prepare; + easrc->m2m_start =3D fsl_easrc_m2m_start; + easrc->m2m_stop =3D fsl_easrc_m2m_stop; + easrc->get_output_fifo_size =3D fsl_easrc_get_output_fifo_size; + easrc->m2m_calc_out_len =3D fsl_easrc_m2m_calc_out_len; + easrc->m2m_get_maxburst =3D fsl_easrc_m2m_get_maxburst; + easrc->m2m_pair_suspend =3D fsl_easrc_m2m_pair_suspend; + easrc->m2m_pair_resume =3D fsl_easrc_m2m_pair_resume; + easrc->m2m_set_ratio_mod =3D fsl_easrc_m2m_set_ratio_mod; + easrc->m2m_get_cap =3D fsl_easrc_m2m_get_cap; =20 easrc_priv->rs_num_taps =3D EASRC_RS_32_TAPS; easrc_priv->const_coeff =3D 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; }; =20 /** --=20 2.34.1