From patchwork Wed Dec 4 05:33:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 847596 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 7DEE6E7716D for ; Wed, 4 Dec 2024 05:35:35 +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 C314B162A; Wed, 4 Dec 2024 06:35:23 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C314B162A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1733290533; bh=qYZzVI0LlfJuMXguWOVx7jlkeVIN296ai7BfGvhMs2o=; 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=XdV2/u0tHDgvA1a8AdUEh2dR4laUsyuvbJkH38n9cldDnhVo73FzYc15q5xl3cx8W FzxReWiNNshqAO/0AdKolJYtGcLcYzSVk2B6yb2nUw0ikUZKcI21WyWTYYiuAmvqR+ E8ORtokLDIocAGkrS4dfojNqTA9pfOO8JX/Wqh+I= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 924C9F805E9; Wed, 4 Dec 2024 06:34:54 +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 446AAF805E2; Wed, 4 Dec 2024 06:34:53 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 087C2F80272; Wed, 4 Dec 2024 06:34:36 +0100 (CET) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2072.outbound.protection.outlook.com [40.107.20.72]) (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 0453EF8003C for ; Wed, 4 Dec 2024 06:34:33 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0453EF8003C 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=jP/kh9nu ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F9KILMB0al4/D3kgexKkEaFYWiLMPiguKSvfACg/FLUpbYdEpwbccU/zLEwP+XazKflTqFxoDH1PPzhm2TV9CLW02w7DphtgBR2b89wNfes786Wh4BAWEbDpU177rCHWvecT57H/gUJH8/fGXwK0blWCopVipIln5t4JdowJgDlf77HTrLtqugBADYjWtG+t0DbUwbE75DbRY5ynSlM0+XPyCBwzJ15I7j3o1NN5BuG+wNbED8cTK77WIiFL9NPjFTOO9avd/P5Pcr4u3cHrGz2/dbyWLJ8BbXX56ftnCumsH4PCGLJO8Yu25JYy2ypEr9g5Kes9UE/gMoaHTNCwnQ== 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=AjqYSBEF+harWuyMeHZEqZwNJnm1Hy5T0NuzIdWBwpY=; b=IEM7ji+JEUGagAh1VN8ZXgA1mwZGNc8r2P6+z7Qu/tCAUMdX3CIuRkfqnrzHHBot+ZJDyN1qqnIGke/oUTeXShobCUf7kstJ6KNKaZjkgTgMaRE2zdxgoUjD2F8auefVxDSEjX79XxGgz3PFWj9JJOJUllJr2Su/JM/ZDUuQvYH3nnq/5fykRxcS6pGyE0bpkue9XAANR50xycBcSOSVxyu7AVxRBUikzJqTZJIW/NVV5XEJHqpfddV3imXSWVN75a+IA1oGruErAJ/egqjAGb5hjJNdFdJCUdS/R41l5E1jLwTRi3v2b43gLtnl8lszgMRzv6aa2BkZJBcQkuL30Q== 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=AjqYSBEF+harWuyMeHZEqZwNJnm1Hy5T0NuzIdWBwpY=; b=jP/kh9nub7rCx1B8G0XbBV9fqwNO+rht0nZ8CLZ12qXI+V+jrv0q7P1QzzK3TpTqBgryco33nDRwGDBDiWVKhToUswuFF1T+lDNsqE0SwdoWmmDnVO9BVEV/VqK8/uck7xUzKNSF5auEhy30KV8IcAYELSIDQBkty8K7NVezae8IsbXJqJLzezrpsD+6+AvtsEMkC56N0X25lrQF0/V3IZVtQjtmh7R18AeYRjiBhl2S0niD2OE0G7LARcX8YOVtDFDlvRvExhFLuQf5gV9E1PWDonvNzr3wTITP2czGIyDemjkjsizFjN1eU5fqa2PQ7hlAz9pbFIz81Cm/ihH7HQ== 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 GV1PR04MB10125.eurprd04.prod.outlook.com (2603:10a6:150:1ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Wed, 4 Dec 2024 05:34:20 +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.8230.008; Wed, 4 Dec 2024 05:34:20 +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 RESEND 1/6] ALSA: compress: Add output rate and output format support Date: Wed, 4 Dec 2024 13:33:41 +0800 Message-Id: <20241204053346.1865723-2-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20241204053346.1865723-1-shengjiu.wang@nxp.com> References: <20241204053346.1865723-1-shengjiu.wang@nxp.com> X-ClientProxiedBy: SI1PR02CA0039.apcprd02.prod.outlook.com (2603:1096:4:1f6::9) To AM0PR04MB7044.eurprd04.prod.outlook.com (2603:10a6:208:191::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB7044:EE_|GV1PR04MB10125:EE_ X-MS-Office365-Filtering-Correlation-Id: 950fd5e2-f904-48f4-4283-08dd14254d9b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|7416014|376014|52116014|1800799024|921020|38350700014; X-Microsoft-Antispam-Message-Info: h69UwH6ua4v2khmkl1vFRu2SK+3YHxK1Haj2W2HuHwEMDhpF6cTxitDn/cMEeAX8SWgMwVTApKb82QUxjgIPKGTAdvTxkLf5VYMN4mil8ry66Ykl+2VJkqggzLjQyEddfY4goP3zmYRadnkaB2uKGaCLj9Izr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csSjMChWy1cwkHDE/3SFzWsIP7ZoPjfpJHi1YBoq3Kt0lEzp/Hp13faMIMiFLmsPWGvtRXRysorhTwgB2ftcSBHV93lO7unYXPK3ed8vezaYBnsk4mzZf+/fqeJq5JYGqUNY6roTWLoG83sgopQ08YtWxOy75QGD7vforoFNUa83Nh0ATtIXvlMlXt8cWkFHIFPa2qGd+Y85X4E8= 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)(7416014)(376014)(52116014)(1800799024)(921020)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: st/eiY35kp1WjXx9q8KdMljVrgH+x2TEayXNB9QMRjOKM6cIdwE/hVi25bqAfhtXETjaByZaCKAB2rntk4Wn5RQb3mYpNurIrhJQUkwJvnnNhu0EiGJErrpOjHwHFxg4qN3apNojbLQa45WL/ekyTwt33zYxo/WtD9hAsbfem0BBHhPCR4rigKctfcooVzqQGTSp9u2PB5ojUNukX2IbkRdeqBTCwKpbHLKRY2c/8gNQ43WGocG/Oa5DtJluZzqcDYScGy3TgBM0dMOFihsca0m31vU0YfeCqw/vOZ1t65jQblSsOaY5drsCR/EBoSEKPWvYt+JpcIBsCYSEmToCSmAorVVSzBCxjiRBg01qmcSnuIRh63n5iaR29Prknll/X03jdBb79D1zG0igVPCIyjD1nVuLbr5oDI+ptj7Xi/qIn5qt0T78FWqc8PVm6fmE5G0OHPfeBmyWsMZf4QGehqM7qI+TUddPl+FKe1whcd4jsNoSUMz+bcL8jsixJKWjwQtIMrA18zAv8dXZ17P4LyLiZPBwA3pyZfogcjITWKxg/t8QBtNtB+tIMI2Ioi9iyBY4atRDFHzPQvu+HFOVS1+AG46NOeTomQOlfAqD8yqYWkeAWxDin5LPeUFB4X3ybb8eZHgFFHiOwXYZsA1PbHDhhouSYf3nD2WIzF3zdaJQc9Wxl9w2oQraO3ci3PIPv+dURJ7DNlwn4x3i9Wwf+COrClGwGW5PCBlO4zAvQcqdH2itTq7a5jlehiv6O7uOv+lLmgVv/ONi5/Zb5HdqxPXXIq2JODbfcOhFYnapWJ6wpxxo0jkeXnkTgSSDqekrVc6hcF5rKn5uqgHFw2rGJmnbd0G5Iy6l3o6ufEnCpwIgUrc8fUvucquAlS9FVIjw34hXn5A2Hbs4uOD1P6As8isCtahD9MQyehH2frdfbERAnc/kp1dnraZen6d7FxU3/3y+geA48VzqwC9H2SoikD2iYjv3yb5kwjYXRHfvjFNTQxsN3hHgHpkB6zyyZPqeUmB4ijPXyn5EpEo8rGtVODLeKDS0AmTVYrIS83cLDb4g2APDz6BMiy+K+mZHanO0cAheOXpvJafOcp76pEnA0walFN8M1ScIE/l9yLn/9GNi709eJCXXnMNbr1Ob6dGjPMl7kDSOhv7OAAE+B5rlI9LF9pkLPUBeZY5AxQfK+94vYZwNFXwiqe1TRyZg5n6iVfioQBB3bwVT8ed8Axw5zkJQhh/NISINBFkkQqubhD9a0PXgO2yK85gAhSn5qMd/pIF+G5sunyEQVZOGek9rpild2MmWz6/QNEKrpTp42Yuxv6pETcXgTs8TE4GFFSZyj7DHNNx7izmrtdzhjwfwZA9QpHfGxIci+EEbrRXIxbnNefKT/gNQU1eXwgysMcN+LnENHf8/REjnK7UT2oy+rejMpK2Y3pNsjknbhYkbACpeFF6PUOVh+yBgL3fejnrYsEQ0n5HGTnt+krfeIJ/Z8CKmtbsBAUUl/DzLuT04/SOLiS7tL2KIsAo5FsVS2r0OMXUbHQl+kkcrupUYprnDE3YdcZyzfhE9WVslxdzS9q4K8sJwX1scOmIjt8hkVRzv X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 950fd5e2-f904-48f4-4283-08dd14254d9b X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB7044.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2024 05:34:20.7219 (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: yvsIYZTZfY9YjWM5wLHFhVIPGEWDpRe5fURSL4jSnsCszT5SwypJe5PM5CovdY7q11wHKIGS+/Dt6YlzGjq1mQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10125 Message-ID-Hash: Z44CNC2EOSE6SXPNHTVQBEN7H6MS77S6 X-Message-ID-Hash: Z44CNC2EOSE6SXPNHTVQBEN7H6MS77S6 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: Add 'pcm_format' for struct snd_codec, add 'pcm_formats' for struct snd_codec_desc, these are used for accelerator usage. Current accelerator example is sample rate converter (SRC). Define struct snd_codec_desc_src for descript minmum and maxmum sample rates. And add 'src_d' in union snd_codec_options structure. These are mainly used for capbility query. Signed-off-by: Jaroslav Kysela Signed-off-by: Shengjiu Wang Acked-by: Jaroslav Kysela Acked-by: Vinod Koul --- include/uapi/sound/compress_params.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/include/uapi/sound/compress_params.h b/include/uapi/sound/compress_params.h index ddc77322d571..bc7648a30746 100644 --- a/include/uapi/sound/compress_params.h +++ b/include/uapi/sound/compress_params.h @@ -334,6 +334,14 @@ union snd_codec_options { struct snd_dec_wma wma_d; struct snd_dec_alac alac_d; struct snd_dec_ape ape_d; + struct { + __u32 out_sample_rate; + } src_d; +} __attribute__((packed, aligned(4))); + +struct snd_codec_desc_src { + __u32 out_sample_rate_min; + __u32 out_sample_rate_max; } __attribute__((packed, aligned(4))); /** struct snd_codec_desc - description of codec capabilities @@ -347,6 +355,9 @@ union snd_codec_options { * @modes: Supported modes. See SND_AUDIOMODE defines * @formats: Supported formats. See SND_AUDIOSTREAMFORMAT defines * @min_buffer: Minimum buffer size handled by codec implementation + * @pcm_formats: Output (for decoders) or input (for encoders) + * PCM formats (required to accel mode, 0 for other modes) + * @u_space: union space (for codec dependent data) * @reserved: reserved for future use * * This structure provides a scalar value for profiles, modes and stream @@ -370,7 +381,12 @@ struct snd_codec_desc { __u32 modes; __u32 formats; __u32 min_buffer; - __u32 reserved[15]; + __u32 pcm_formats; + union { + __u32 u_space[6]; + struct snd_codec_desc_src src; + } __attribute__((packed, aligned(4))); + __u32 reserved[8]; } __attribute__((packed, aligned(4))); /** struct snd_codec @@ -395,6 +411,8 @@ struct snd_codec_desc { * @align: Block alignment in bytes of an audio sample. * Only required for PCM or IEC formats. * @options: encoder-specific settings + * @pcm_format: Output (for decoders) or input (for encoders) + * PCM formats (required to accel mode, 0 for other modes) * @reserved: reserved for future use */ @@ -411,7 +429,8 @@ struct snd_codec { __u32 format; __u32 align; union snd_codec_options options; - __u32 reserved[3]; + __u32 pcm_format; + __u32 reserved[2]; } __attribute__((packed, aligned(4))); #endif From patchwork Wed Dec 4 05:33:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 847350 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 EAD4FE7716D for ; Wed, 4 Dec 2024 05:35:57 +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 80E32E9A; Wed, 4 Dec 2024 06:35:45 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 80E32E9A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1733290555; bh=ava76Ve8aJqozawOgULm+0WWlEIDJuGJMeLj9SKdXBc=; 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=sOJ2XHOtjNMoAVNDZSmlYwmGRp4nApiPPEQI3ljFEnCbPSg7UG4DTpKSc762w7C6s KItYZyVxeP2iariX9//xcGhdvg/r4YUchKPQMBHgqubDzQ3byyHd9DoRMAtOpDNSVN LNWtj3M2lFj1b2AaRWSmqWfuQJDUvrW2Hs8nuXJk= Received: by alsa1.perex.cz (Postfix, from userid 50401) id AA793F805F8; Wed, 4 Dec 2024 06:35:00 +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 67CE3F8060A; Wed, 4 Dec 2024 06:34:59 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id F03B2F8032D; Wed, 4 Dec 2024 06:34:37 +0100 (CET) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2072.outbound.protection.outlook.com [40.107.20.72]) (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 4C44BF8003C for ; Wed, 4 Dec 2024 06:34:35 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4C44BF8003C 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=ennPkD01 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xKxCbvvS26GQ4u9omof8aZthQXT9q9hXF4dL11ZZYIV2+wNS5wKv5oj+5kVdCueil4CrBn4UIfs48EWbTJ7IVayZ3flLx9J9vceOKmBgmeRy+by2+2VxyD8HPvBhSVAvnJ5tOJPqg0LvkLXcyUoqi+RQdqhDAc3EpA0m3l8tptGIZva8sARHlasqwP+3iFgs7EA2ATObuSfYM8KDwPKO5aQrnxQaJljIfC+C7e4719zdYCPpJX3Jq+/eO1S2fobiITha7QE5tSp13y7Uqq31X7URoDM7LY3MpPjBfv0IHWeRxmNFSpMcy9ySIT5KyS3BnFfV0/GhYuGFma2iRZVrag== 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=8f6ttwYZXSGqEAL54j0qzoFjSj4HqsYoO6Te5HL+rSE=; b=uIBxm104xp3ua12/0OZUyiotoy8bDG8UqUDGQqDFkEjGMFLoCQeHO18OBaxtbMp97aaDbk3K7nTEOy+FhIjd0I8MSofTL0DPc43DWK6qLYDfW0FWaYUbXlv5PrIlGKIKOahEZnzbUugR0NCzVLGoN5FCTXVjewaphxgcAqMEtigcEOvBGhP3Kq89LCv+FvrAVK4P++o7xJDpl0L8fUkVLV+/tjvuHR5iRs5J3FV7XfqJ+oxu65UmKnkes2YlJnxLTuTAvsja/EZaKSPMSJU8/8LeerEBQiR3T9TWQI5TinOGzqlmI1NDfKJtazgpmEEoSR6Y6fjCnH5sBwJx/G+JBw== 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=8f6ttwYZXSGqEAL54j0qzoFjSj4HqsYoO6Te5HL+rSE=; b=ennPkD012vrWxwf8kSqCK65SHuBaOwWM1M/LHh6kYhNPI60gy/k2PHQ3LGk3li+UJp58BRXak84/J0tDmRuz4zmGfgQb5WmxJFrTfa9i2jl0nYAOKGHg7fY/to184+W/FQbX5jY80hphvJVhP6KGz1uYeN/KRaOT3gi+k7GVpvaNz6rv4/YAU7BPYQ+qyb+VL7l6CrlrYV2t0kkF4revpiyU3O+ceVLQZoKcLadI9BUExzmFh3n1r/35nkMC87l92K7aZ0JKJO92QBb9A9YfQSkFpzG0FTJL/1uxjkqvCn1a1ppNv1X+f2UBBfozL98kIT7NCtWJ9eBqYZ/wzzh0Gw== 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 GV1PR04MB10125.eurprd04.prod.outlook.com (2603:10a6:150:1ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Wed, 4 Dec 2024 05:34:25 +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.8230.008; Wed, 4 Dec 2024 05:34:25 +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 RESEND 2/6] ASoC: fsl_asrc: define functions for memory to memory usage Date: Wed, 4 Dec 2024 13:33:42 +0800 Message-Id: <20241204053346.1865723-3-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20241204053346.1865723-1-shengjiu.wang@nxp.com> References: <20241204053346.1865723-1-shengjiu.wang@nxp.com> X-ClientProxiedBy: SI1PR02CA0039.apcprd02.prod.outlook.com (2603:1096:4:1f6::9) To AM0PR04MB7044.eurprd04.prod.outlook.com (2603:10a6:208:191::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB7044:EE_|GV1PR04MB10125:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e9a8427-37ef-4a6a-36e1-08dd1425506d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|7416014|376014|52116014|1800799024|921020|38350700014; X-Microsoft-Antispam-Message-Info: k6Sn1y5An2d0Rl3/+XrPdMRtdWrzY2jh/EQ8croQqDy/FM24g3JLc9WW2/0hZ2O8bfSWcvyMFrudg58p3bdWRvVhNrygOkTpKkDFTlEhhzR+xRgwb92LuZZZOMoS/CaSwxH/ibqpG4/RSdDyGp6BGCOk6We3X/mcruHYX4eIp26xqt0YCstBOmgCU4iiCBSZzZ+sliry0ND7eEjlAPFa3dWONNHyekY66Ei35a+2QUCr+9YrLaqSXuEW89npgJ/bdkXMcTNin0cZzuWORY8aXw9whwgMIf4suHTyqmtOf4kTDQ21RrjWD25J2/iJweEQPn14GjOl9LtUVbgviWkJIvQrZPG04U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pUqPKNtqY6JVSTxHWF3tYUvdUjIf4UhjqH4x0= 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)(7416014)(376014)(52116014)(1800799024)(921020)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: I/q/mYeG8FRKBcLPAdg9Nl30UV9rKcAIiBulZEIfkWnJI7cJDcQWYiyXSIK5cui3XXmNM1e3YzIm+O5SNo6Kh0OLJ5zo98Rp28trKWg5lK+Imnm4MKpAlYOX8+cCiAO6mpSoMIpE9CCfict2q0OjlQytLQZPMrb+gCROGwYb3JLPveBox+HO/71nE+W/2c4zNyDKyzMJdR5nyPlJrGOE8AlvZkecOKS5PnGyTqNtumyRDgeT+ojRL66oZNU8fiiSGeXojT6I7ZBpLGYQY4ogACfpriAe8uCqwpisyG4XezT3NIlY41GBh8SoQrwLInx4S22ehUj6YkWqqf4xfxuC3A28my3Do9VVepv9PG1txt1Htdi64O5ZQNCYnl0rE4ZpEJMsdZvlQ6JqTbm9lhKWljxSyulGcohar7pxKlPQi4iLMhQvrjYpqtYxwGiHZTs3iRd5lK6Kq5VJR6QF5fqSqolTCyI/W69wXxrun3cUz4FhjOH0FRx5guRFnBlbdmjof4n04T0quGB/H1uGQYvKhJfIgK8HLUVsM+gogaIxr3rukW1myoIZSRAzvKRvZKFp+UhNZoJy6fyTvgMGNaN9MMGDXQmA2njP474ZA7wPD+CE0sv2AuStpb/eojCDQfBpx5nvgI7qBxv3eu08WB5GEG42WIS0uJO5zdDwuoyzSXG29hxJ5a3XUGcVy/Smau7kyJfgL3wforJviz7t7BnQ7Scw8JLQoxpu/5VmEaYprwlgiAgZHZXlWFZ5R5vpGd0fuLEo6Q2blMT4GHEMks2pJZN5STmerM3JdtNvxyjsv/fCtfn4tkVP75Ox1rtefn6F0V2gMEr1MFigDS9WBG+kGY2/eZ/OyvehZOYdf+eoEe8agQfqTkIkEXPpY02hKfiWN48ejY7o3S+lFJxsLJP4YbXlAzZKRAvEZRiVDiLfd4xuqw9QBaikkbeS+gk8ZV6je5i9cOA+GzuqMANMmCTF3x9bMtysscG6tBr2OPTpJtYtQeGKjdjnSO+DYMQjDKhR07OiXLiWgXVCzsPvDyPoj04iffl6CEwDEvE9ASr/p1dvrx79H5n0oXOF09rVxoA8hU0XatyOhPNufrSlK9lZs+iI+GtaKsE3KJsJJSrGY8NtoqYOPNq9DNcHS7rC2wIfJrrNdUEENYTqi410vYwYR0PAzO9TwSmGiALmNzz7sSE46JquBQguAojM7k19BoS+dpF+2awVPJ23S6xB4TTTrzQQBaWN3YNwG7VMcaUGL7x6fw9mQhhGhghqI7ewRwNKJPv08NbD7Jc9Y7GgyGdfOC8RsEnmHylyWViHVtm8R5uwpFI42qLewTcfPaY6QvWvzatzCVcvkFpY85ddv+lBdsc2f6JbKvtI9aKJZOA9/x74wJaE46seNdscGpRPVZj6HFGDSCUqbwTeujfwb7CGYDO6iLbYkJ5p/NlLVLyxPlVhPuPn18iP9m8oi/CUUisOIKTDU5klFjf+PPDhXQNXi1HYH2mFDXbi488oammT26imTNmwq0oaCEb+nTVxZfaUEvojwzI7HB75ap9vd/cgAr/eAupWw33cJm58t1XC0/bCcuC7pkePyxtUICt+hH8l X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e9a8427-37ef-4a6a-36e1-08dd1425506d X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB7044.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2024 05:34:25.6293 (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: 02TWQbtktz0MaS/q3yiycMHJTfNxaSKm9oqKdswlsOj2jG/brKUuPzqPUEyelcMtS5VWjJP4fT7QuiWh+n8gjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10125 Message-ID-Hash: LHDJKJBJAGAEZ7Q4LERSSUPMT2EXQALE X-Message-ID-Hash: LHDJKJBJAGAEZ7Q4LERSSUPMT2EXQALE 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. m2m_prepare: prepare for the start step m2m_start: the start step m2m_unprepare: unprepare for stop step, optional m2m_stop: stop step m2m_check_format: check format is supported or not m2m_calc_out_len: calculate output length according to input length m2m_get_maxburst: burst size for dma m2m_pair_suspend: suspend function of pair, optional. m2m_pair_resume: resume function of pair get_output_fifo_size: get remaining data size in FIFO Signed-off-by: Shengjiu Wang Acked-by: Jaroslav Kysela --- sound/soc/fsl/fsl_asrc.c | 142 ++++++++++++++++++++++++++++++++ sound/soc/fsl/fsl_asrc.h | 2 + sound/soc/fsl/fsl_asrc_common.h | 61 ++++++++++++++ 3 files changed, 205 insertions(+) diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index bd5c46d763c0..471753276209 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -1063,6 +1063,139 @@ static int fsl_asrc_get_fifo_addr(u8 dir, enum asrc_pair_index index) return REG_ASRDx(dir, index); } +/* Get sample numbers in FIFO */ +static unsigned int fsl_asrc_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_ASRFST(index), &val); + + val &= ASRFSTi_OUTPUT_FIFO_MASK; + + return val >> ASRFSTi_OUTPUT_FIFO_SHIFT; +} + +static int fsl_asrc_m2m_prepare(struct fsl_asrc_pair *pair) +{ + struct fsl_asrc_pair_priv *pair_priv = pair->private; + struct fsl_asrc *asrc = pair->asrc; + struct device *dev = &asrc->pdev->dev; + struct asrc_config config; + int ret; + + /* fill config */ + config.pair = pair->index; + config.channel_num = pair->channels; + config.input_sample_rate = pair->rate[IN]; + config.output_sample_rate = pair->rate[OUT]; + config.input_format = pair->sample_format[IN]; + config.output_format = pair->sample_format[OUT]; + config.inclk = INCLK_NONE; + config.outclk = OUTCLK_ASRCK1_CLK; + + pair_priv->config = &config; + ret = fsl_asrc_config_pair(pair, true); + if (ret) { + dev_err(dev, "failed to config pair: %d\n", ret); + return ret; + } + + pair->first_convert = 1; + + return 0; +} + +static int fsl_asrc_m2m_start(struct fsl_asrc_pair *pair) +{ + if (pair->first_convert) { + fsl_asrc_start_pair(pair); + pair->first_convert = 0; + } + /* + * Clear DMA request during the stall state of ASRC: + * During STALL state, the remaining in input fifo would never be + * smaller than the input threshold while the output fifo would not + * be bigger than output one. Thus the DMA request would be cleared. + */ + fsl_asrc_set_watermarks(pair, ASRC_FIFO_THRESHOLD_MIN, + ASRC_FIFO_THRESHOLD_MAX); + + /* Update the real input threshold to raise DMA request */ + fsl_asrc_set_watermarks(pair, ASRC_M2M_INPUTFIFO_WML, + ASRC_M2M_OUTPUTFIFO_WML); + + return 0; +} + +static int fsl_asrc_m2m_stop(struct fsl_asrc_pair *pair) +{ + if (!pair->first_convert) { + fsl_asrc_stop_pair(pair); + pair->first_convert = 1; + } + + return 0; +} + +/* calculate capture data length according to output data length and sample rate */ +static int fsl_asrc_m2m_calc_out_len(struct fsl_asrc_pair *pair, int input_buffer_length) +{ + unsigned int in_width, out_width; + unsigned int channels = pair->channels; + unsigned int in_samples, out_samples; + unsigned int out_length; + + in_width = snd_pcm_format_physical_width(pair->sample_format[IN]) / 8; + out_width = snd_pcm_format_physical_width(pair->sample_format[OUT]) / 8; + + in_samples = input_buffer_length / in_width / channels; + out_samples = pair->rate[OUT] * in_samples / pair->rate[IN]; + out_length = (out_samples - ASRC_OUTPUT_LAST_SAMPLE) * out_width * channels; + + return out_length; +} + +static int fsl_asrc_m2m_get_maxburst(u8 dir, struct fsl_asrc_pair *pair) +{ + struct fsl_asrc *asrc = pair->asrc; + struct fsl_asrc_priv *asrc_priv = asrc->private; + int wml = (dir == IN) ? ASRC_M2M_INPUTFIFO_WML : ASRC_M2M_OUTPUTFIFO_WML; + + if (!asrc_priv->soc->use_edma) + return wml * pair->channels; + else + return 1; +} + +static int fsl_asrc_m2m_get_cap(struct fsl_asrc_m2m_cap *cap) +{ + cap->fmt_in = FSL_ASRC_FORMATS; + cap->fmt_out = FSL_ASRC_FORMATS | SNDRV_PCM_FMTBIT_S8; + + cap->rate_in = supported_asrc_rate; + cap->rate_in_count = ARRAY_SIZE(supported_asrc_rate); + cap->rate_out = supported_asrc_rate; + cap->rate_out_count = ARRAY_SIZE(supported_asrc_rate); + cap->chan_min = 1; + cap->chan_max = 10; + + return 0; +} + +static int fsl_asrc_m2m_pair_resume(struct fsl_asrc_pair *pair) +{ + struct fsl_asrc *asrc = pair->asrc; + int i; + + for (i = 0; i < pair->channels * 4; i++) + regmap_write(asrc->regmap, REG_ASRDI(pair->index), 0); + + pair->first_convert = 1; + return 0; +} + static int fsl_asrc_runtime_resume(struct device *dev); static int fsl_asrc_runtime_suspend(struct device *dev); @@ -1147,6 +1280,15 @@ static int fsl_asrc_probe(struct platform_device *pdev) asrc->get_fifo_addr = fsl_asrc_get_fifo_addr; asrc->pair_priv_size = sizeof(struct fsl_asrc_pair_priv); + asrc->m2m_prepare = fsl_asrc_m2m_prepare; + asrc->m2m_start = fsl_asrc_m2m_start; + asrc->m2m_stop = fsl_asrc_m2m_stop; + asrc->get_output_fifo_size = fsl_asrc_get_output_fifo_size; + asrc->m2m_calc_out_len = fsl_asrc_m2m_calc_out_len; + asrc->m2m_get_maxburst = fsl_asrc_m2m_get_maxburst; + asrc->m2m_pair_resume = fsl_asrc_m2m_pair_resume; + asrc->m2m_get_cap = fsl_asrc_m2m_get_cap; + if (of_device_is_compatible(np, "fsl,imx35-asrc")) { asrc_priv->clk_map[IN] = input_clk_map_imx35; asrc_priv->clk_map[OUT] = output_clk_map_imx35; diff --git a/sound/soc/fsl/fsl_asrc.h b/sound/soc/fsl/fsl_asrc.h index 86d2422ad606..1c492eb237f5 100644 --- a/sound/soc/fsl/fsl_asrc.h +++ b/sound/soc/fsl/fsl_asrc.h @@ -12,6 +12,8 @@ #include "fsl_asrc_common.h" +#define ASRC_M2M_INPUTFIFO_WML 0x4 +#define ASRC_M2M_OUTPUTFIFO_WML 0x2 #define ASRC_DMA_BUFFER_NUM 2 #define ASRC_INPUTFIFO_THRESHOLD 32 #define ASRC_OUTPUTFIFO_THRESHOLD 32 diff --git a/sound/soc/fsl/fsl_asrc_common.h b/sound/soc/fsl/fsl_asrc_common.h index 7e1c13ca37f1..3bdd6ea07c09 100644 --- a/sound/soc/fsl/fsl_asrc_common.h +++ b/sound/soc/fsl/fsl_asrc_common.h @@ -21,6 +21,26 @@ enum asrc_pair_index { #define PAIR_CTX_NUM 0x4 +/** + * struct fsl_asrc_m2m_cap - capability data + * @fmt_in: input sample format + * @fmt_out: output sample format + * @chan_min: minimum channel number + * @chan_max: maximum channel number + * @rate_in: minimum rate + * @rate_out: maximum rete + */ +struct fsl_asrc_m2m_cap { + u64 fmt_in; + u64 fmt_out; + int chan_min; + int chan_max; + const unsigned int *rate_in; + int rate_in_count; + const unsigned int *rate_out; + int rate_out_count; +}; + /** * fsl_asrc_pair: ASRC Pair common data * @@ -34,6 +54,13 @@ enum asrc_pair_index { * @pos: hardware pointer position * @req_dma_chan: flag to release dev_to_dev chan * @private: pair private area + * @complete: dma task complete + * @sample_format: format of m2m + * @rate: rate of m2m + * @buf_len: buffer length of m2m + * @dma_buffer: buffer pointers + * @first_convert: start of conversion + * @ratio_mod: ratio modification */ struct fsl_asrc_pair { struct fsl_asrc *asrc; @@ -49,6 +76,15 @@ struct fsl_asrc_pair { bool req_dma_chan; void *private; + + /* used for m2m */ + struct completion complete[2]; + snd_pcm_format_t sample_format[2]; + unsigned int rate[2]; + unsigned int buf_len[2]; + struct snd_dma_buffer dma_buffer[2]; + unsigned int first_convert; + unsigned int ratio_mod; }; /** @@ -72,6 +108,17 @@ struct fsl_asrc_pair { * @request_pair: function pointer * @release_pair: function pointer * @get_fifo_addr: function pointer + * @m2m_get_cap: function pointer + * @m2m_prepare: function pointer + * @m2m_start: function pointer + * @m2m_unprepare: function pointer + * @m2m_stop: function pointer + * @m2m_calc_out_len: function pointer + * @m2m_get_maxburst: function pointer + * @m2m_pair_suspend: function pointer + * @m2m_pair_resume: function pointer + * @m2m_set_ratio_mod: function pointer + * @get_output_fifo_size: function pointer * @pair_priv_size: size of pair private struct. * @private: private data structure */ @@ -97,6 +144,20 @@ struct fsl_asrc { int (*request_pair)(int channels, struct fsl_asrc_pair *pair); void (*release_pair)(struct fsl_asrc_pair *pair); int (*get_fifo_addr)(u8 dir, enum asrc_pair_index index); + int (*m2m_get_cap)(struct fsl_asrc_m2m_cap *cap); + + int (*m2m_prepare)(struct fsl_asrc_pair *pair); + int (*m2m_start)(struct fsl_asrc_pair *pair); + int (*m2m_unprepare)(struct fsl_asrc_pair *pair); + int (*m2m_stop)(struct fsl_asrc_pair *pair); + + int (*m2m_calc_out_len)(struct fsl_asrc_pair *pair, int input_buffer_length); + int (*m2m_get_maxburst)(u8 dir, struct fsl_asrc_pair *pair); + int (*m2m_pair_suspend)(struct fsl_asrc_pair *pair); + int (*m2m_pair_resume)(struct fsl_asrc_pair *pair); + int (*m2m_set_ratio_mod)(struct fsl_asrc_pair *pair, int val); + + unsigned int (*get_output_fifo_size)(struct fsl_asrc_pair *pair); size_t pair_priv_size; void *private; From patchwork Wed Dec 4 05:33:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 847595 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 8D8FBE7716B for ; Wed, 4 Dec 2024 05:36:16 +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 5480A14DE; Wed, 4 Dec 2024 06:36:04 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5480A14DE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1733290574; 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=FXeFQecU/QzU/JoMIGNI1ZtojmlX5M3HrfQrPBtsw9CBMdea9ynX9gK9B/C0dGYDc 6m3/kUQT6O+4Zxh4aNPNjJ8H/AcohE23l87ezCCThT6z8htYyJgJinqtPTKkpWJlX0 O1XXQnVCMaUldIOpqJRkX6gdw88DzXX1LEkRL3D0= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 187ABF80632; Wed, 4 Dec 2024 06:35:06 +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 309D1F80624; Wed, 4 Dec 2024 06:35:06 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4485FF8032D; Wed, 4 Dec 2024 06:34:39 +0100 (CET) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2072.outbound.protection.outlook.com [40.107.20.72]) (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 8974AF801C0 for ; Wed, 4 Dec 2024 06:34:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8974AF801C0 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=fmq+g5SM ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZXefKCdMRiQZoNCJCnhww9AGFrdc7rScEBrGPuUXNE7mkxgW+cpThA37oGYEZ1mOgfY/ZzxISP2/qYyJ52xsXOClbc8AeFpucXUsYfR3Ib+uj9vQBo4yvJTBKyg2nr60MndmjiTKnqJewATTx/zON0yaEBcqelIcwMZe4X2Gz3O/z6ETpLbQ6wEfJMEPh5uYLZ0E0ADUp48AEMS92RbptKUNujmrfgAFpFxweIxbri2z4yzIgkrByD5y05i4FAUz3l/rd+3SqO46c/wcnDfVjOyH7Rdt6xyZA4Xy4AtNINGCuI7nC76NdwVJFNPqD0bFE0J7YgZ2wJhubNQSxGI9Lw== 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=iJt0pOWKl+gwCLQxnazJ6Uq/Z/xliqqmbLK0mjzVlgoKajXPo/sDK58PFMo/ZXW24k6JGXwxtPgTerZSoWw1y47hwAIiSozNBgE6nUjqNiZbROoDUYMtfRpnS0UA5yR/MTiUsoAg5EMCvyAqfEKR1iKDagPNe43oCckkpb/obb77yjTHunkUUnOAdKdDxpj8AzA1/b0tdZU2Ec45IqAfwWgpBzFRpDPttZjZJ/DXLzgcVSCo8r0m6vXIejABCGB7YoI4FoeG+zhAeiHykE5NelaKTpJUA4gNeAPHczAhvWnrL6heKP9RsyHUx3pQoiK5HG++3R83vB77yYiMboueow== 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=fmq+g5SMmJhgF3FRGNA9de9DDqt2cximP3nwIi0aybYSJra07YrLQ4OVzIDsXouUlu1x7ZEtdk/JFncLKpByfW0Ap/amriLm4hCNceHcyxOf0OEZQ8VNbfg3m6NW006LwPKSaBEVqTQCAlPwBqzDc1XoGin00EdZk8PFmj69FqjL5bz51NwZ4gsk93oGj+cGZNx7m6wLXnDdPSNI2D0MVslBix3d0sKwRjXgGeeoqniLhDBRCiGf6YCod9nzK7xbEndbNMzNh1cd4BVsbNsNQs8xu7pPAcROC01b0EtASswhwk3onWfRMyFdTbFsf5HtQiOobBxl3UCqXw9WMJ8ltg== 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 GV1PR04MB10125.eurprd04.prod.outlook.com (2603:10a6:150:1ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Wed, 4 Dec 2024 05:34:30 +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.8230.008; Wed, 4 Dec 2024 05:34:30 +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 RESEND 3/6] ASoC: fsl_easrc: define functions for memory to memory usage Date: Wed, 4 Dec 2024 13:33:43 +0800 Message-Id: <20241204053346.1865723-4-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20241204053346.1865723-1-shengjiu.wang@nxp.com> References: <20241204053346.1865723-1-shengjiu.wang@nxp.com> X-ClientProxiedBy: SI1PR02CA0039.apcprd02.prod.outlook.com (2603:1096:4:1f6::9) To AM0PR04MB7044.eurprd04.prod.outlook.com (2603:10a6:208:191::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB7044:EE_|GV1PR04MB10125:EE_ X-MS-Office365-Filtering-Correlation-Id: 910e8d5c-561f-454d-8d22-08dd14255351 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|7416014|376014|52116014|1800799024|921020|38350700014; X-Microsoft-Antispam-Message-Info: NVxdhwZl8ANEtNr70YHkN9i6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DZJGYB6Z8dHAVa7ZE56e+BDDMaDCfrFhhOsbIOIf3gPvQ69beW0uSgeNUtlMGf/0vQElWSj3WGNUf5M2lOQnq05W9BpgY2RSVLkQ+RLw93i3V2iH+nCh5BD903p/kIPwxVKp/zVMQ5uaFg6ugIdhahDlI3aRWWpWXL8wPKoiXxEVQAhK6c9xSW/myB3EDCe+ztLou2yasofzsHMa+TpB3NmVwqy+EtmVTw2lqQQ8zqQLkVIwwm+bkVFn4kNlMVX0ayLKpb1bzWHNRDSmbujZMxiz9kkVb7CckYKPljiy1RAcyhEUE6UTjaFBpBkl9zuiUaTo55j6yna0fyeFP4ZKQXc= 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)(7416014)(376014)(52116014)(1800799024)(921020)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ENjJoS0x5+ZcrjzqypZRE2olKUuu6ZqKnDGF7rzIaZkWU/v/IHKKlVieU0kQy+z6eCi8J0/lvCaSvr0qPDPjrpgdRk+j4ZV79KepquNynfMWLf/ptZTBbao0zLupUVGV99v4Ep1hR8RntVJ3uwAO/SxeGARVmMGYMN5N5Cxuzlvrzu+4uaWlHpCeTRwO5Y4Q5mAnqY3mf9BURfEg74G7Lhb5ujgGLAuTb8vGVUeNkfpZ7czIvQN6FDO8yAud19So6rrvDb6OqSUK2QlTudNEI7o1Zp9rCbTmYiJ49d2VCXeBKvw3uMjq8LUd/m3cXCcKQVkxUuyst4gX7QMtibh3R1sOfXeq93lCwNTIhVT18v0Zh+JjiR4M6ElcE+oEMws+uG+Ricv5A2b+3L3C2xWq4FJtXpCTnn+d3uadahOysY3leGw0QmnPHwFcnM3iYJXI//AE1gK0grt2jTMxq/pmKZgj71LYMlffCpkczwBKq6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4kl3dk1vC0Hf5UJdHkTfu35fNo7HoXu X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 910e8d5c-561f-454d-8d22-08dd14255351 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB7044.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2024 05:34:30.2625 (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: f9lMTa/7ODOOejwClL9p7awZj0i/UkyLo9gYBiuiDS/rcROhulM45d6sAaAH0j01ZTOdVL3v7pjGriuk8KMDmg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10125 Message-ID-Hash: PRHATZTLVWX42BUULTWRPZNB5HPONQ3P X-Message-ID-Hash: PRHATZTLVWX42BUULTWRPZNB5HPONQ3P 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; }; /** From patchwork Wed Dec 4 05:33:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 847349 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 D9984E7716B for ; Wed, 4 Dec 2024 05:36:26 +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 307A014E4; Wed, 4 Dec 2024 06:36:15 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 307A014E4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1733290585; bh=wOlGpfTQAS7sNYLbXFLKL6O9SAl3YTuTI8SC5Ey8fSI=; 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=ALPKw+r8LIvRNbdJoCWOwEn+brq//En/J/vBQbHXlch3f7CWkD0ATIh5BRs7UPx5K dUJx21XBmGfaoFz3+t8m2vMgzkLPT1BOLsC1CB+Chy/21vCI7aGs+lEt5dOphpJCDZ HCGHYAKg8XnP+KOtlmwkG+eCdjVNrQFFlozispE4= Received: by alsa1.perex.cz (Postfix, from userid 50401) id F192BF8065E; Wed, 4 Dec 2024 06:35:12 +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 2FADEF80651; Wed, 4 Dec 2024 06:35:12 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 538E2F80272; Wed, 4 Dec 2024 06:34:41 +0100 (CET) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2072.outbound.protection.outlook.com [40.107.20.72]) (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 C81D0F8003C for ; Wed, 4 Dec 2024 06:34:37 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C81D0F8003C 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=fZ8itot6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EYB+FU8HaG02o15KgIgEnbeCUsD776mu1aLM3yKVkoUR4IaL8QBhqrOLDUs33Uz/BHxhMxTuPNch5YlxAeFyEUgfQTTbgIKNDXBOYvVkV+0Z4S3OfvZX4yFZ75TZODH502/DGcc6zA1szb+4isEMlW7ua9pW93CbawaG3jwnpWnHYIhMJuh5PTRzkSWrT3qUHAPPrg8dVfpFJrAVLwGNE1MgXRP88oGpRwBbjq2WgZFDQXeNwf/v/ECG93qlY4JGGf9lvcuXblKOlaJFRBYxsBuYQxFubpy8VpbqAt4fURpXyGVMmr9eqX47TWAnev9eKWpmKCnoZQLruBJXbHzvkw== 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=bGPb+mdKrZt2tU75PNwV+UeH06NumTCOB8hjqlF8OMA=; b=oZutFak5YixoNqq1dOOqXVZ5HtcFJcpcZox6AyY7NtsLdD3+u86Xv0q8rF98+ki9eb/YG7GnOMoA+D5OWfzCSlThzAk7kdQOqSUX91SmfHrRwUiswdiyYyrXlJc2X/p6jXmaATsZelv4yTkCpIYICQVppX2Rt+BKSfTfZcnCZMiJFZkZO6/xNt5tqJ2sWMLsH1QM/YqHlXCrkKUxym5NoWt4iXSqrY0ZHz25oy6wn7mZmowepiIxbEEAyj7QN1Mnlcd0sanUQBxetPj3JMFQhOXXWMRi5YnJey8yQhND/9S2nOJ/TqQ6lCg/+ovkufatVVCGtkCIj0s8HUu24giikQ== 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=bGPb+mdKrZt2tU75PNwV+UeH06NumTCOB8hjqlF8OMA=; b=fZ8itot6nJzs+a3kHAxX9KFxRuGkBgpmF1pUTxKwgrYRCbhQI1kLWw+xVCS3nX/9m/H4DvgGVLkJjaaMRdMBt3X3yyB5a25utht1Lo2J9wYe/aEelMkdn4p/+Oy0K/yv34j2WyBp89eL/vGJT2MQH4IB39GrIseD7FfY6aWoQf+IBB8wiuPQJyzqnWIUo3/0WtaG/qWvcageSTm/S52OpVGURsOA/6rtMkaf4t4hUSR1zrwyvcz2sL5sN8YostVxcJicPrYd1vR/I5b85019brJjofP4lDMam/8PkaShlYDnWDzj0I3j0v4YuNH/yzEghLTEyiyxKYbHDnRGwEGrJw== 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 GV1PR04MB10125.eurprd04.prod.outlook.com (2603:10a6:150:1ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Wed, 4 Dec 2024 05:34:34 +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.8230.008; Wed, 4 Dec 2024 05:34:34 +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 RESEND 4/6] ASoC: fsl_asrc_m2m: Add memory to memory function Date: Wed, 4 Dec 2024 13:33:44 +0800 Message-Id: <20241204053346.1865723-5-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20241204053346.1865723-1-shengjiu.wang@nxp.com> References: <20241204053346.1865723-1-shengjiu.wang@nxp.com> X-ClientProxiedBy: SI1PR02CA0039.apcprd02.prod.outlook.com (2603:1096:4:1f6::9) To AM0PR04MB7044.eurprd04.prod.outlook.com (2603:10a6:208:191::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB7044:EE_|GV1PR04MB10125:EE_ X-MS-Office365-Filtering-Correlation-Id: 322f0b01-8ae1-4514-cc9c-08dd142555d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|7416014|376014|52116014|1800799024|921020|38350700014; X-Microsoft-Antispam-Message-Info: vaoMCOvCII7HKJduf5tWNObkMJAPqBAOnWVTgkDl9j4sYavofXIAxkdy5nTh3YF6y4ykxAPh+LE/StZD/HHyd9b+xh7PjI8SCOU+RIghA7VDCANUMvvb2qUs4NA4PGDdLaZbpoKRp/RInLCpnCDE35otnnBk3c7BZZObIis8aWTnSZ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OPkD6tvkV2nvlqE3K06AF1ZN4B5tc3CSdr+/uu3YpiFDTrTgNEPblgEAGA0UHITVVpo2icZGNECmnTlmax3WB6uXY62aibiPpGBE3Poj9Tn8LvVwyx8Rxv1Xx0Uy3Xx1/HE6jxrHv9dxg6xdlDq67lw+9ajsht1JoByKNjf4acB/5/i4/TbYLT4yQ04vKZUQ0HFSCuI= 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)(7416014)(376014)(52116014)(1800799024)(921020)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jdvl/3KBfKBxG9Lqb6wxedylTXHnVSoMVLoMi6ypyOiZj0VKtOX0ZwYV8+jlx+tkE8AlKfMGZPPtpRkN02TLG2EaFqG2qqPfpxKEj8uV4UxHJyu9mT4t9O/88BK0hihHvUE/zCa/cc/go3EvQHNpe916x4qBx5GGaLEVs15KfiCSRQaIA3qFsVwYRby2Vvae8NcJ2eQbU46TCtlnYmg89OhlQ4icpNKwur6uWQcF5XtMOZZiEDlkI0RBDm3QRRe+Mca5cmXwB6649XKZHLNmrLj60lzu8WDgAtTQUkr05GMGGJ/YccI8nKC+9nxteUI1eXuSE77hCRT0goF8f6bujq6595l5qNOAVGfpsPtV19OQCGyvhYZ1TKqEhMYzr0DL4gi4oUIWv2114W/KicsjRTmn6m+OgxkfudslmgX+wdiHvWUX+jFy2Ex8qz+MVl8q2hRUQqRHJWjQCpX/yIkuUvJ98hq55nSRqD1o7MHFJ0dqw7T1dXmjIORzTOodNeljaRaZ/POD1lJw0Vs0Q2poTlQ2rFwitxkSSNK5LDNn4acqXEHgv972gbrTcr0xTbetPI1QPkGUafJgE+N1brNDv1QEZsemr2VkCMmjOk4cV/XP3nkqqtrGy/eSpuUDQKr6T7C1wRgKnyD4OxZ9HcrjMbhnclZuHQbWAh7tjpeA2ukDGIJFkcAIi6um6gZ6+VMsqmPOWRq/ECsH9FKLiuKZON55/9VY4CXm1EKs8zCNYtN9QKJrDmEpBsMFbjh9dI9dbHm1ucgaPazzuHUBpL8u/yRkKdjQNhWC4kUunBvThGPAmrohjyG/wAAKcVQL2IUGh8mpRMkBbdEdDor6lXfWzUk4X8W0//J9B3QgnYEWNzp63uqPZ4wcoghzcMUd/0JIbABttwMAjq4puT5pCec2RUi25/A1JXTckA1nz95xbJBCTOT+bcThy4iGYYgdFajEjf+Rm237JVcKizXl06Ah4JNE905ZBQjV2eISMznJSyFgYtvnZuMxWVvJHt1dtf3xGbTrkp5+Z7M8EnB38tL0mUYVyYVzyiT3HojXFRfTty98tiABhVwuaHPlKeyu4m2aAvUd7v+f/B4o865Jr7eXR9eCKTz9nI6RLxm40LZ8Z9742bZPX3w651Imc4nat7fIsBw35T8q0xg73MSq2i91b3MM+ZGz9XaYX11yCoVPmS2SZ/+2qIl1adKxe9oPaxCeLZO600eb7Ko7BnvDcZByMlOLfy1nyVUcONmEl3iIM7bdCl49xUgkbOogKcIjx6/QdGYAlqZBqOq5I4lmiz+KSjZoc3Z034bQSvysBryl/G472HaARWHWHCCsI1hzCzOQCzd4pEusYp/ecM91I1d9DLxYQxOYx1XNMPgMtOtxKpr7wM2OjyYlhBzF6O37WjDPpo6W4j6WwfbD2NevJRg2ffATB8+98EkhaL5JnOaDzrpVFq9X0wtwZpZGiITqzdaSjKC1kw6vZ5JNgU+ukYoJk7BWZeSLlS4wK8HnAxp28pauRkdCw94vJnao8+wccmdDEj20rU5A9delAsc0k6v7ZLRKqx2N0dBNEbeGkYzcEefRFvH3w4QjyQKk6jPKiUf+ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 322f0b01-8ae1-4514-cc9c-08dd142555d7 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB7044.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2024 05:34:34.5918 (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: Hj/77Q7Gx7ZtRGDOC0V1mAZuFv4qHzOpusNpiVkXTSk5p5kjEDTIdW/lNNPnsG4lLB4cLrQKlRCA5WDH6d6g+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10125 Message-ID-Hash: IUHPG34G37SXT4EJH4UZBB3NESMRIYL4 X-Message-ID-Hash: IUHPG34G37SXT4EJH4UZBB3NESMRIYL4 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: Implement the ASRC memory to memory function using the compress framework, user can use this function with compress ioctl interface. This feature can be shared by ASRC and EASRC drivers Signed-off-by: Shengjiu Wang Acked-by: Jaroslav Kysela --- sound/soc/fsl/Kconfig | 1 + sound/soc/fsl/Makefile | 2 +- sound/soc/fsl/fsl_asrc_common.h | 9 + sound/soc/fsl/fsl_asrc_m2m.c | 727 ++++++++++++++++++++++++++++++++ 4 files changed, 738 insertions(+), 1 deletion(-) create mode 100644 sound/soc/fsl/fsl_asrc_m2m.c diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig index 8e88830e8e57..698afae46918 100644 --- a/sound/soc/fsl/Kconfig +++ b/sound/soc/fsl/Kconfig @@ -8,6 +8,7 @@ config SND_SOC_FSL_ASRC depends on HAS_DMA select REGMAP_MMIO select SND_SOC_GENERIC_DMAENGINE_PCM + select SND_COMPRESS_ACCEL help Say Y if you want to add Asynchronous Sample Rate Converter (ASRC) support for the Freescale CPUs. diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile index ad97244b5cc3..d656a9ab54e3 100644 --- a/sound/soc/fsl/Makefile +++ b/sound/soc/fsl/Makefile @@ -10,7 +10,7 @@ obj-$(CONFIG_SND_SOC_P1022_RDK) += snd-soc-p1022-rdk.o # Freescale SSI/DMA/SAI/SPDIF Support snd-soc-fsl-audmix-y := fsl_audmix.o snd-soc-fsl-asoc-card-y := fsl-asoc-card.o -snd-soc-fsl-asrc-y := fsl_asrc.o fsl_asrc_dma.o +snd-soc-fsl-asrc-y := fsl_asrc.o fsl_asrc_dma.o fsl_asrc_m2m.o snd-soc-fsl-lpc3xxx-y := lpc3xxx-pcm.o lpc3xxx-i2s.o snd-soc-fsl-sai-y := fsl_sai.o snd-soc-fsl-ssi-y := fsl_ssi.o diff --git a/sound/soc/fsl/fsl_asrc_common.h b/sound/soc/fsl/fsl_asrc_common.h index 3bdd6ea07c09..0cd595b0f629 100644 --- a/sound/soc/fsl/fsl_asrc_common.h +++ b/sound/soc/fsl/fsl_asrc_common.h @@ -60,6 +60,7 @@ struct fsl_asrc_m2m_cap { * @buf_len: buffer length of m2m * @dma_buffer: buffer pointers * @first_convert: start of conversion + * @ratio_mod_flag: flag for new ratio modifier * @ratio_mod: ratio modification */ struct fsl_asrc_pair { @@ -84,6 +85,7 @@ struct fsl_asrc_pair { unsigned int buf_len[2]; struct snd_dma_buffer dma_buffer[2]; unsigned int first_convert; + bool ratio_mod_flag; unsigned int ratio_mod; }; @@ -98,6 +100,7 @@ struct fsl_asrc_pair { * @mem_clk: clock source to access register * @ipg_clk: clock source to drive peripheral * @spba_clk: SPBA clock (optional, depending on SoC design) + * @card: compress sound card * @lock: spin lock for resource protection * @pair: pair pointers * @channel_avail: non-occupied channel numbers @@ -131,6 +134,7 @@ struct fsl_asrc { struct clk *mem_clk; struct clk *ipg_clk; struct clk *spba_clk; + struct snd_card *card; spinlock_t lock; /* spin lock for resource protection */ struct fsl_asrc_pair *pair[PAIR_CTX_NUM]; @@ -166,4 +170,9 @@ struct fsl_asrc { #define DRV_NAME "fsl-asrc-dai" extern struct snd_soc_component_driver fsl_asrc_component; +int fsl_asrc_m2m_init(struct fsl_asrc *asrc); +void fsl_asrc_m2m_exit(struct fsl_asrc *asrc); +int fsl_asrc_m2m_resume(struct fsl_asrc *asrc); +int fsl_asrc_m2m_suspend(struct fsl_asrc *asrc); + #endif /* _FSL_ASRC_COMMON_H */ diff --git a/sound/soc/fsl/fsl_asrc_m2m.c b/sound/soc/fsl/fsl_asrc_m2m.c new file mode 100644 index 000000000000..693ec0a477a4 --- /dev/null +++ b/sound/soc/fsl/fsl_asrc_m2m.c @@ -0,0 +1,727 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2014-2016 Freescale Semiconductor, Inc. +// Copyright (C) 2019-2024 NXP +// +// Freescale ASRC Memory to Memory (M2M) driver + +#include +#include +#include +#include +#include +#include +#include + +#include "fsl_asrc_common.h" + +#define DIR_STR(dir) (dir) == IN ? "in" : "out" + +#define ASRC_xPUT_DMA_CALLBACK(dir) \ + (((dir) == IN) ? asrc_input_dma_callback \ + : asrc_output_dma_callback) + +/* Maximum output and capture buffer size */ +#define ASRC_M2M_BUFFER_SIZE (512 * 1024) + +/* Maximum output and capture period size */ +#define ASRC_M2M_PERIOD_SIZE (48 * 1024) + +/* dma complete callback */ +static void asrc_input_dma_callback(void *data) +{ + struct fsl_asrc_pair *pair = (struct fsl_asrc_pair *)data; + + complete(&pair->complete[IN]); +} + +/* dma complete callback */ +static void asrc_output_dma_callback(void *data) +{ + struct fsl_asrc_pair *pair = (struct fsl_asrc_pair *)data; + + complete(&pair->complete[OUT]); +} + +/** + *asrc_read_last_fifo: read all the remaining data from FIFO + *@pair: Structure pointer of fsl_asrc_pair + *@dma_vaddr: virtual address of capture buffer + *@length: payload length of capture buffer + */ +static void asrc_read_last_fifo(struct fsl_asrc_pair *pair, void *dma_vaddr, u32 *length) +{ + struct fsl_asrc *asrc = pair->asrc; + enum asrc_pair_index index = pair->index; + u32 i, reg, size, t_size = 0, width; + u32 *reg32 = NULL; + u16 *reg16 = NULL; + u8 *reg24 = NULL; + + width = snd_pcm_format_physical_width(pair->sample_format[OUT]); + if (width == 32) + reg32 = dma_vaddr + *length; + else if (width == 16) + reg16 = dma_vaddr + *length; + else + reg24 = dma_vaddr + *length; +retry: + size = asrc->get_output_fifo_size(pair); + if (size + *length > ASRC_M2M_BUFFER_SIZE) + goto end; + + for (i = 0; i < size * pair->channels; i++) { + regmap_read(asrc->regmap, asrc->get_fifo_addr(OUT, index), ®); + if (reg32) { + *reg32++ = reg; + } else if (reg16) { + *reg16++ = (u16)reg; + } else { + *reg24++ = (u8)reg; + *reg24++ = (u8)(reg >> 8); + *reg24++ = (u8)(reg >> 16); + } + } + t_size += size; + + /* In case there is data left in FIFO */ + if (size) + goto retry; +end: + /* Update payload length */ + if (reg32) + *length += t_size * pair->channels * 4; + else if (reg16) + *length += t_size * pair->channels * 2; + else + *length += t_size * pair->channels * 3; +} + +/* config dma channel */ +static int asrc_dmaconfig(struct fsl_asrc_pair *pair, + struct dma_chan *chan, + u32 dma_addr, dma_addr_t buf_addr, u32 buf_len, + int dir, int width) +{ + struct fsl_asrc *asrc = pair->asrc; + struct device *dev = &asrc->pdev->dev; + struct dma_slave_config slave_config; + enum dma_slave_buswidth buswidth; + unsigned int sg_len, max_period_size; + struct scatterlist *sg; + int ret, i; + + switch (width) { + case 8: + buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE; + break; + case 16: + buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES; + break; + case 24: + buswidth = DMA_SLAVE_BUSWIDTH_3_BYTES; + break; + case 32: + buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES; + break; + default: + dev_err(dev, "invalid word width\n"); + return -EINVAL; + } + + memset(&slave_config, 0, sizeof(slave_config)); + if (dir == IN) { + slave_config.direction = DMA_MEM_TO_DEV; + slave_config.dst_addr = dma_addr; + slave_config.dst_addr_width = buswidth; + slave_config.dst_maxburst = asrc->m2m_get_maxburst(IN, pair); + } else { + slave_config.direction = DMA_DEV_TO_MEM; + slave_config.src_addr = dma_addr; + slave_config.src_addr_width = buswidth; + slave_config.src_maxburst = asrc->m2m_get_maxburst(OUT, pair); + } + + ret = dmaengine_slave_config(chan, &slave_config); + if (ret) { + dev_err(dev, "failed to config dmaengine for %s task: %d\n", + DIR_STR(dir), ret); + return -EINVAL; + } + + max_period_size = rounddown(ASRC_M2M_PERIOD_SIZE, width * pair->channels / 8); + /* scatter gather mode */ + sg_len = buf_len / max_period_size; + if (buf_len % max_period_size) + sg_len += 1; + + sg = kmalloc_array(sg_len, sizeof(*sg), GFP_KERNEL); + if (!sg) + return -ENOMEM; + + sg_init_table(sg, sg_len); + for (i = 0; i < (sg_len - 1); i++) { + sg_dma_address(&sg[i]) = buf_addr + i * max_period_size; + sg_dma_len(&sg[i]) = max_period_size; + } + sg_dma_address(&sg[i]) = buf_addr + i * max_period_size; + sg_dma_len(&sg[i]) = buf_len - i * max_period_size; + + pair->desc[dir] = dmaengine_prep_slave_sg(chan, sg, sg_len, + slave_config.direction, + DMA_PREP_INTERRUPT); + kfree(sg); + if (!pair->desc[dir]) { + dev_err(dev, "failed to prepare dmaengine for %s task\n", DIR_STR(dir)); + return -EINVAL; + } + + pair->desc[dir]->callback = ASRC_xPUT_DMA_CALLBACK(dir); + pair->desc[dir]->callback_param = pair; + + return 0; +} + +/* main function of converter */ +static void asrc_m2m_device_run(struct fsl_asrc_pair *pair, struct snd_compr_task_runtime *task) +{ + struct fsl_asrc *asrc = pair->asrc; + struct device *dev = &asrc->pdev->dev; + enum asrc_pair_index index = pair->index; + struct snd_dma_buffer *src_buf, *dst_buf; + unsigned int in_buf_len; + unsigned int out_dma_len; + unsigned int width; + u32 fifo_addr; + int ret; + + /* set ratio mod */ + if (asrc->m2m_set_ratio_mod) { + if (pair->ratio_mod_flag) { + asrc->m2m_set_ratio_mod(pair, pair->ratio_mod); + pair->ratio_mod_flag = false; + } + } + + src_buf = &pair->dma_buffer[IN]; + dst_buf = &pair->dma_buffer[OUT]; + + width = snd_pcm_format_physical_width(pair->sample_format[IN]); + fifo_addr = asrc->paddr + asrc->get_fifo_addr(IN, index); + + in_buf_len = task->input_size; + + if (in_buf_len < width * pair->channels / 8 || + in_buf_len > ASRC_M2M_BUFFER_SIZE || + in_buf_len % (width * pair->channels / 8)) { + dev_err(dev, "out buffer size is error: [%d]\n", in_buf_len); + goto end; + } + + /* dma config for output dma channel */ + ret = asrc_dmaconfig(pair, + pair->dma_chan[IN], + fifo_addr, + src_buf->addr, + in_buf_len, IN, width); + if (ret) { + dev_err(dev, "out dma config error\n"); + goto end; + } + + width = snd_pcm_format_physical_width(pair->sample_format[OUT]); + fifo_addr = asrc->paddr + asrc->get_fifo_addr(OUT, index); + out_dma_len = asrc->m2m_calc_out_len(pair, in_buf_len); + if (out_dma_len > 0 && out_dma_len <= ASRC_M2M_BUFFER_SIZE) { + /* dma config for capture dma channel */ + ret = asrc_dmaconfig(pair, + pair->dma_chan[OUT], + fifo_addr, + dst_buf->addr, + out_dma_len, OUT, width); + if (ret) { + dev_err(dev, "cap dma config error\n"); + goto end; + } + } else if (out_dma_len > ASRC_M2M_BUFFER_SIZE) { + dev_err(dev, "cap buffer size error\n"); + goto end; + } + + reinit_completion(&pair->complete[IN]); + reinit_completion(&pair->complete[OUT]); + + /* Submit DMA request */ + dmaengine_submit(pair->desc[IN]); + dma_async_issue_pending(pair->desc[IN]->chan); + if (out_dma_len > 0) { + dmaengine_submit(pair->desc[OUT]); + dma_async_issue_pending(pair->desc[OUT]->chan); + } + + asrc->m2m_start(pair); + + if (!wait_for_completion_interruptible_timeout(&pair->complete[IN], 10 * HZ)) { + dev_err(dev, "out DMA task timeout\n"); + goto end; + } + + if (out_dma_len > 0) { + if (!wait_for_completion_interruptible_timeout(&pair->complete[OUT], 10 * HZ)) { + dev_err(dev, "cap DMA task timeout\n"); + goto end; + } + } + + /* read the last words from FIFO */ + asrc_read_last_fifo(pair, dst_buf->area, &out_dma_len); + /* update payload length for capture */ + task->output_size = out_dma_len; +end: + return; +} + +static int fsl_asrc_m2m_comp_open(struct snd_compr_stream *stream) +{ + struct fsl_asrc *asrc = stream->private_data; + struct snd_compr_runtime *runtime = stream->runtime; + struct device *dev = &asrc->pdev->dev; + struct fsl_asrc_pair *pair; + int size, ret; + + pair = kzalloc(sizeof(*pair) + asrc->pair_priv_size, GFP_KERNEL); + if (!pair) + return -ENOMEM; + + pair->private = (void *)pair + sizeof(struct fsl_asrc_pair); + pair->asrc = asrc; + + init_completion(&pair->complete[IN]); + init_completion(&pair->complete[OUT]); + + runtime->private_data = pair; + + size = ASRC_M2M_BUFFER_SIZE; + ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size, &pair->dma_buffer[IN]); + if (ret) + goto error_alloc_in_buf; + + ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size, &pair->dma_buffer[OUT]); + if (ret) + goto error_alloc_out_buf; + + ret = pm_runtime_get_sync(dev); + if (ret < 0) { + dev_err(dev, "Failed to power up asrc\n"); + goto err_pm_runtime; + } + + return 0; + +err_pm_runtime: + snd_dma_free_pages(&pair->dma_buffer[OUT]); +error_alloc_out_buf: + snd_dma_free_pages(&pair->dma_buffer[IN]); +error_alloc_in_buf: + kfree(pair); + return ret; +} + +static int fsl_asrc_m2m_comp_release(struct snd_compr_stream *stream) +{ + struct fsl_asrc *asrc = stream->private_data; + struct snd_compr_runtime *runtime = stream->runtime; + struct fsl_asrc_pair *pair = runtime->private_data; + struct device *dev = &asrc->pdev->dev; + + pm_runtime_put_sync(dev); + + snd_dma_free_pages(&pair->dma_buffer[IN]); + snd_dma_free_pages(&pair->dma_buffer[OUT]); + + kfree(runtime->private_data); + + return 0; +} + +static int fsl_asrc_m2m_comp_set_params(struct snd_compr_stream *stream, + struct snd_compr_params *params) +{ + struct fsl_asrc *asrc = stream->private_data; + struct snd_compr_runtime *runtime = stream->runtime; + struct fsl_asrc_pair *pair = runtime->private_data; + struct fsl_asrc_m2m_cap cap; + int ret, i; + + ret = asrc->m2m_get_cap(&cap); + if (ret) + return -EINVAL; + + if (pcm_format_to_bits(params->codec.format) & cap.fmt_in) + pair->sample_format[IN] = params->codec.format; + else + return -EINVAL; + + if (pcm_format_to_bits(params->codec.pcm_format) & cap.fmt_out) + pair->sample_format[OUT] = params->codec.pcm_format; + else + return -EINVAL; + + /* check input rate is in scope */ + for (i = 0; i < cap.rate_in_count; i++) + if (params->codec.sample_rate == cap.rate_in[i]) { + pair->rate[IN] = params->codec.sample_rate; + break; + } + if (i == cap.rate_in_count) + return -EINVAL; + + /* check output rate is in scope */ + for (i = 0; i < cap.rate_out_count; i++) + if (params->codec.options.src_d.out_sample_rate == cap.rate_out[i]) { + pair->rate[OUT] = params->codec.options.src_d.out_sample_rate; + break; + } + if (i == cap.rate_out_count) + return -EINVAL; + + if (params->codec.ch_in != params->codec.ch_out || + params->codec.ch_in < cap.chan_min || + params->codec.ch_in > cap.chan_max) + return -EINVAL; + + pair->channels = params->codec.ch_in; + pair->buf_len[IN] = params->buffer.fragment_size; + pair->buf_len[OUT] = params->buffer.fragment_size; + + return 0; +} + +static int fsl_asrc_m2m_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma) +{ + struct snd_dma_buffer *dmab = dmabuf->priv; + + return snd_dma_buffer_mmap(dmab, vma); +} + +static struct sg_table *fsl_asrc_m2m_map_dma_buf(struct dma_buf_attachment *attachment, + enum dma_data_direction direction) +{ + struct snd_dma_buffer *dmab = attachment->dmabuf->priv; + struct sg_table *sgt; + + sgt = kmalloc(sizeof(*sgt), GFP_KERNEL); + if (!sgt) + return NULL; + + if (dma_get_sgtable(attachment->dev, sgt, dmab->area, dmab->addr, dmab->bytes) < 0) + goto free; + + if (dma_map_sgtable(attachment->dev, sgt, direction, 0)) + goto free; + + return sgt; + +free: + sg_free_table(sgt); + kfree(sgt); + return NULL; +} + +static void fsl_asrc_m2m_unmap_dma_buf(struct dma_buf_attachment *attachment, + struct sg_table *table, + enum dma_data_direction direction) +{ + dma_unmap_sgtable(attachment->dev, table, direction, 0); +} + +static void fsl_asrc_m2m_release(struct dma_buf *dmabuf) +{ + /* buffer is released by fsl_asrc_m2m_comp_release() */ +} + +static const struct dma_buf_ops fsl_asrc_m2m_dma_buf_ops = { + .mmap = fsl_asrc_m2m_mmap, + .map_dma_buf = fsl_asrc_m2m_map_dma_buf, + .unmap_dma_buf = fsl_asrc_m2m_unmap_dma_buf, + .release = fsl_asrc_m2m_release, +}; + +static int fsl_asrc_m2m_comp_task_create(struct snd_compr_stream *stream, + struct snd_compr_task_runtime *task) +{ + DEFINE_DMA_BUF_EXPORT_INFO(exp_info_in); + DEFINE_DMA_BUF_EXPORT_INFO(exp_info_out); + struct fsl_asrc *asrc = stream->private_data; + struct snd_compr_runtime *runtime = stream->runtime; + struct fsl_asrc_pair *pair = runtime->private_data; + struct device *dev = &asrc->pdev->dev; + int ret; + + exp_info_in.ops = &fsl_asrc_m2m_dma_buf_ops; + exp_info_in.size = ASRC_M2M_BUFFER_SIZE; + exp_info_in.flags = O_RDWR; + exp_info_in.priv = &pair->dma_buffer[IN]; + task->input = dma_buf_export(&exp_info_in); + if (IS_ERR(task->input)) { + ret = PTR_ERR(task->input); + return ret; + } + + exp_info_out.ops = &fsl_asrc_m2m_dma_buf_ops; + exp_info_out.size = ASRC_M2M_BUFFER_SIZE; + exp_info_out.flags = O_RDWR; + exp_info_out.priv = &pair->dma_buffer[OUT]; + task->output = dma_buf_export(&exp_info_out); + if (IS_ERR(task->output)) { + ret = PTR_ERR(task->output); + return ret; + } + + /* Request asrc pair/context */ + ret = asrc->request_pair(pair->channels, pair); + if (ret) { + dev_err(dev, "failed to request pair: %d\n", ret); + goto err_request_pair; + } + + ret = asrc->m2m_prepare(pair); + if (ret) { + dev_err(dev, "failed to start pair part one: %d\n", ret); + goto err_start_part_one; + } + + /* Request dma channels */ + pair->dma_chan[IN] = asrc->get_dma_channel(pair, IN); + if (!pair->dma_chan[IN]) { + dev_err(dev, "[ctx%d] failed to get input DMA channel\n", pair->index); + ret = -EBUSY; + goto err_dma_channel_in; + } + + pair->dma_chan[OUT] = asrc->get_dma_channel(pair, OUT); + if (!pair->dma_chan[OUT]) { + dev_err(dev, "[ctx%d] failed to get output DMA channel\n", pair->index); + ret = -EBUSY; + goto err_dma_channel_out; + } + + return 0; + +err_dma_channel_out: + dma_release_channel(pair->dma_chan[IN]); +err_dma_channel_in: + if (asrc->m2m_unprepare) + asrc->m2m_unprepare(pair); +err_start_part_one: + asrc->release_pair(pair); +err_request_pair: + return ret; +} + +static int fsl_asrc_m2m_comp_task_start(struct snd_compr_stream *stream, + struct snd_compr_task_runtime *task) +{ + struct snd_compr_runtime *runtime = stream->runtime; + struct fsl_asrc_pair *pair = runtime->private_data; + + asrc_m2m_device_run(pair, task); + + return 0; +} + +static int fsl_asrc_m2m_comp_task_stop(struct snd_compr_stream *stream, + struct snd_compr_task_runtime *task) +{ + return 0; +} + +static int fsl_asrc_m2m_comp_task_free(struct snd_compr_stream *stream, + struct snd_compr_task_runtime *task) +{ + struct fsl_asrc *asrc = stream->private_data; + struct snd_compr_runtime *runtime = stream->runtime; + struct fsl_asrc_pair *pair = runtime->private_data; + + /* Stop & release pair/context */ + if (asrc->m2m_stop) + asrc->m2m_stop(pair); + + if (asrc->m2m_unprepare) + asrc->m2m_unprepare(pair); + asrc->release_pair(pair); + + /* Release dma channel */ + if (pair->dma_chan[IN]) + dma_release_channel(pair->dma_chan[IN]); + if (pair->dma_chan[OUT]) + dma_release_channel(pair->dma_chan[OUT]); + + return 0; +} + +static int fsl_asrc_m2m_get_caps(struct snd_compr_stream *cstream, + struct snd_compr_caps *caps) +{ + caps->num_codecs = 1; + caps->min_fragment_size = 4096; + caps->max_fragment_size = 4096; + caps->min_fragments = 1; + caps->max_fragments = 1; + caps->codecs[0] = SND_AUDIOCODEC_PCM; + + return 0; +} + +static int fsl_asrc_m2m_fill_codec_caps(struct fsl_asrc *asrc, + struct snd_compr_codec_caps *codec) +{ + struct fsl_asrc_m2m_cap cap; + snd_pcm_format_t k; + int j = 0; + int ret; + + ret = asrc->m2m_get_cap(&cap); + if (ret) + return -EINVAL; + + pcm_for_each_format(k) { + if (pcm_format_to_bits(k) & cap.fmt_in) { + codec->descriptor[j].max_ch = cap.chan_max; + memcpy(codec->descriptor[j].sample_rates, + cap.rate_in, + cap.rate_in_count * sizeof(__u32)); + codec->descriptor[j].num_sample_rates = cap.rate_in_count; + codec->descriptor[j].formats = k; + codec->descriptor[j].pcm_formats = cap.fmt_out; + codec->descriptor[j].src.out_sample_rate_min = cap.rate_out[0]; + codec->descriptor[j].src.out_sample_rate_max = + cap.rate_out[cap.rate_out_count - 1]; + j++; + } + } + + codec->codec = SND_AUDIOCODEC_PCM; + codec->num_descriptors = j; + return 0; +} + +static int fsl_asrc_m2m_get_codec_caps(struct snd_compr_stream *stream, + struct snd_compr_codec_caps *codec) +{ + struct fsl_asrc *asrc = stream->private_data; + + return fsl_asrc_m2m_fill_codec_caps(asrc, codec); +} + +static struct snd_compr_ops fsl_asrc_m2m_compr_ops = { + .open = fsl_asrc_m2m_comp_open, + .free = fsl_asrc_m2m_comp_release, + .set_params = fsl_asrc_m2m_comp_set_params, + .get_caps = fsl_asrc_m2m_get_caps, + .get_codec_caps = fsl_asrc_m2m_get_codec_caps, + .task_create = fsl_asrc_m2m_comp_task_create, + .task_start = fsl_asrc_m2m_comp_task_start, + .task_stop = fsl_asrc_m2m_comp_task_stop, + .task_free = fsl_asrc_m2m_comp_task_free, +}; + +int fsl_asrc_m2m_suspend(struct fsl_asrc *asrc) +{ + struct fsl_asrc_pair *pair; + int i; + + for (i = 0; i < PAIR_CTX_NUM; i++) { + pair = asrc->pair[i]; + if (!pair) + continue; + if (!completion_done(&pair->complete[IN])) { + if (pair->dma_chan[IN]) + dmaengine_terminate_all(pair->dma_chan[IN]); + asrc_input_dma_callback((void *)pair); + } + if (!completion_done(&pair->complete[OUT])) { + if (pair->dma_chan[OUT]) + dmaengine_terminate_all(pair->dma_chan[OUT]); + asrc_output_dma_callback((void *)pair); + } + + if (asrc->m2m_pair_suspend) + asrc->m2m_pair_suspend(pair); + } + + return 0; +} +EXPORT_SYMBOL_GPL(fsl_asrc_m2m_suspend); + +int fsl_asrc_m2m_resume(struct fsl_asrc *asrc) +{ + struct fsl_asrc_pair *pair; + int i; + + for (i = 0; i < PAIR_CTX_NUM; i++) { + pair = asrc->pair[i]; + if (!pair) + continue; + if (asrc->m2m_pair_resume) + asrc->m2m_pair_resume(pair); + } + + return 0; +} +EXPORT_SYMBOL_GPL(fsl_asrc_m2m_resume); + +int fsl_asrc_m2m_init(struct fsl_asrc *asrc) +{ + struct device *dev = &asrc->pdev->dev; + struct snd_card *card; + struct snd_compr *compr; + int ret; + + ret = snd_card_new(dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, + THIS_MODULE, 0, &card); + if (ret < 0) + return ret; + + strscpy(card->driver, "fsl-asrc-m2m", sizeof(card->driver)); + strscpy(card->shortname, "ASRC-M2M", sizeof(card->shortname)); + strscpy(card->longname, "ASRC-M2M", sizeof(card->shortname)); + + asrc->card = card; + + compr = devm_kzalloc(dev, sizeof(*compr), GFP_KERNEL); + if (!compr) { + ret = -ENOMEM; + goto err; + } + + compr->ops = &fsl_asrc_m2m_compr_ops; + compr->private_data = asrc; + + ret = snd_compress_new(card, 0, SND_COMPRESS_ACCEL, "ASRC M2M", compr); + if (ret < 0) + goto err; + + ret = snd_card_register(card); + if (ret < 0) + goto err; + + return 0; +err: + snd_card_free(card); + return ret; +} +EXPORT_SYMBOL_GPL(fsl_asrc_m2m_init); + +void fsl_asrc_m2m_exit(struct fsl_asrc *asrc) +{ + struct snd_card *card = asrc->card; + + snd_card_free(card); +} +EXPORT_SYMBOL_GPL(fsl_asrc_m2m_exit); + +MODULE_IMPORT_NS(DMA_BUF); +MODULE_AUTHOR("Shengjiu Wang "); +MODULE_DESCRIPTION("Freescale ASRC M2M driver"); +MODULE_LICENSE("GPL"); From patchwork Wed Dec 4 05:33:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 847594 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 AC4D6E7716D for ; Wed, 4 Dec 2024 05:36:57 +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 00F7C15FE; Wed, 4 Dec 2024 06:36:46 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 00F7C15FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1733290616; bh=Kga5T+ah2FU3Ou2fNm/+P5B4ui4zBo7U8oJFsAlVAeU=; 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=rzyZjN843f6ua/zDpzThaLsSxrIJ5Rzp4DwLEoXvUcmD+nV/Hj2recNln2KvjJ1UR xAvVYdFbbpy93Quy9SzFSooO3Dkb9xKHcS1dmztFOaOjjk+39PU84TmuvvsJ5HG+ea uJ2Kbksknk8XFPfEhTLFojqLtSWLPEZXe0QDj3lY= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5C0CAF8032D; Wed, 4 Dec 2024 06:35:18 +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 20D5CF80689; Wed, 4 Dec 2024 06:35:18 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 47ECFF80607; Wed, 4 Dec 2024 06:35:01 +0100 (CET) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2066.outbound.protection.outlook.com [40.107.21.66]) (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 83DFFF805CA for ; Wed, 4 Dec 2024 06:34:54 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 83DFFF805CA 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=gPDT8RV3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Rq/PQVJTKn6d0K2abJQ1t3/A9AWzedtMOmZsgoi3fIOTeY0+eaWEHh4rmP2enHzGgHlVPI/AlCaHCD25Tkk0We76qtTP/ihUyaOInGbCqQ5Ax9ZJR837jkRzSNOuWGMQCN4zCbwdH3bzUXeHjPyaHQgoqxybnCDRfv2u3WBIf3CMzeuikoOFMahJUvmQ5u8p0NMDLjsqn9dGDZC4AcUd7JG59vj2UkyO6z4MucE/8keiiOTD2Kd+fFiJEw86a/0rcIFPqvUnWgHJh58Oxu8L1FLqK/X5/wZBovu+FPa5FfRj0YjNO6Bdsx/g4gr4WDB9vSPgFv3MwKCYPrTwhWeCNg== 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=Gx4r59MsUrRSAYnRBL2LULLZNbMWnLuBxzcN1FydhN0=; b=Ro/FUBltVysLhRJa1NBQVPlE3827U2mTI9kWey6A4EW8VcciCoLbwJdCBgwwmzRtXDmhHMvT6OqHvUkE9MBO8OHnmCP6GpxXI3T56P+22TEtIorfpB30FLYVwFK5dNphZ13iTjpzMETrgig1EsfRM3uFuhiQOEUsxRZIuTfl4k8DnoInrhqWUUumLDmqSVcywNpcfQ+c/vaD1FCDQR4GTESm5TYQJAxCyMSmRb0w0UIwQ/ZLxLtWDTkSvGpL72QlV7AOUEiTO/FJjlE/8a6rZ6Sms6EIZi5XymBmsSx+yEhgqjGWbzBohEYRASaa4aDsxpTvLQHmg8odW7s9riNSmw== 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=Gx4r59MsUrRSAYnRBL2LULLZNbMWnLuBxzcN1FydhN0=; b=gPDT8RV3/BBtRhzlNTzw6vXGGTaItGm0qIdM10lAU/zUXdZn8rikqWQsY9L1ibwozU0xh4x0R07yFpLhZ+zsqKoh/INAq9fBMilK1SzQALvAyNDjw4o5+blMyxVlhqVxzxqCHTpMxaOOi+vZjiA0tvtUKDV5Zzlo87yqRUJvF24ngK8P5+YpPfdAUWRw1elJntdlM0uEil/cH+mPc7NteqHr6+9ygPBwOqzBYFkqVR1XkvoOVmFX62NgIJVizyMzY1MUGYRh0puSQ4LC8ESBMks8Dp6TBT/uzkpxLItVtbcY9vjuQQRn9BmrFsoKy0Iui2uY52rMryLYLbSIb1u2Vg== 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 GV1PR04MB10125.eurprd04.prod.outlook.com (2603:10a6:150:1ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Wed, 4 Dec 2024 05:34:39 +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.8230.008; Wed, 4 Dec 2024 05:34:39 +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 RESEND 5/6] ASoC: fsl_asrc: register m2m platform device Date: Wed, 4 Dec 2024 13:33:45 +0800 Message-Id: <20241204053346.1865723-6-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20241204053346.1865723-1-shengjiu.wang@nxp.com> References: <20241204053346.1865723-1-shengjiu.wang@nxp.com> X-ClientProxiedBy: SI1PR02CA0039.apcprd02.prod.outlook.com (2603:1096:4:1f6::9) To AM0PR04MB7044.eurprd04.prod.outlook.com (2603:10a6:208:191::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB7044:EE_|GV1PR04MB10125:EE_ X-MS-Office365-Filtering-Correlation-Id: b4f7cfa9-19b8-40c5-7725-08dd14255884 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|7416014|376014|52116014|1800799024|921020|38350700014; X-Microsoft-Antispam-Message-Info: dIdsaZStmUIQIzZqC5/q9S5HuY6a39HIfI+wedLmY/EG4P27Z5vKGBzlNU/+CtODtzNoa0yIX0GpTjcHtpL6Py6XYDrGBsocxDENzsmVjzUtwscLRmKgzQR2uzRIzfi03a4xELYul1aoTrrqiPHFZUABsW0NccQ3YLcbg01FiZxKQWsRWdS2YAEfuPdB4/XLHOdFC7XMLPnefOPHSQWljezkmsZ8WWlaqo6IhaDoDSjksyQz9JjGMLLf1s6gwFbZm0J6TfDA7XLpg5BG787nSTVu1fOrPBP8x2/0pNVsjPHdMphTWRxF5kgTJvltt1nN61KCzT+gr0azvCIVYRSCVxGVlw+TfCoOk/3oqiyRKWQkzR4xtvYIRcc4Kv2kqbZWxw6u9OauPlBm+2m0Un+0ch+rGfzJRTCXoUVDt35ApVhiroVuHkq8VHzp1eJPlboRuazMYpnCMfGrxsivesLS47BEoOmOoAx+o7EwrbyRgeSAB5zSwvs0sX18qUeH2MIwJxjdOS1BjIDmokuTwQPQ4bYuW14pl/J0E19+KxzhasdLmUWUDHK6wJw3OH6wUEwdJmTpYb4I2Dt/F7hQv4B+2m4fmvdCFcJoR9ZCt1cO/7ilvnFiSGPuUM6hYMF2E3oJJhU/9f/oacoxqZxE4XY6AAJzX8LEB9hoV8QDwgD15gqx1S0YaBSHxCgOUxiTiLT8YEggnRsOsPsSnepf3dkhGhUebS+KYKE/xOXBeRmzvVetJDVzi4N6530wFX1ffQrxLBBddctk7t8Q8FC6jt7nsFA0PFjMQzvaacH4OU6lAv5jFLJ334FjKFwJ/Pl2ju87gc1WBAbMuFj49+2F7m3n+avedXa3qLhgjgBFLA5F5fa12GfD5XQKYrpmcKrllHGbr/aREBYTBlpd8cZMaF9hZutdB495u3+W/zYlApVqcggY0pQ9VLZ7aH8ItK87Cj/G7uXSYdzf2mOMpy24Gnkrwf2ib0x3AByFlDkNg5++qMUoFjvUS3ZRN0lbxBDYc2cjni1zr1wD0mgdqph1A7ncoy+cR2X8buCfoU2PDhKooGnyQspwmoBI7lOJpgf4OE+X56w0u52C8G8hDR2QCtpa0CRc0Ojy2078dzB6sr57qivDvhz2PpYNcfxwMRbZLKilPvwkY823cnj5AyW+Zcc+9xo+cyVdKBJvT86pkTdRdRMVD560Ikdh137hKv9HYIV/kM37hUOu7VATQhhmq1aYuRnshsM1F/vi0XYPJWlbSCAXoafs/aCUNaw0pMocPM+9JxbB59u7RIDfFzGS1jdLz2agKoJjc0aGNACORfhlVDbFvJSZIDgl4wOvVP0XsurN4KRYe+Re5elVhz1Pbwv8l6du4LXW+2Fjn1+3VlAkULzNzyGdWZ8lGFWEZabc/G3b60Px6mr/3mybwIwAotbWWaVPZD62VB9pOYi3dH4/muQ= 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)(7416014)(376014)(52116014)(1800799024)(921020)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MPF7O07cUdJvLDaT6pIER7RslQzgmwfQDTJbjRMo1u1qW6M2PihRjqW49Z2J+GZ5FPalEC5lRyRTKLQXsMR74H2AQq/LL/43w++nMXvDhtz1vvh/C1bn63Z9ClyG47BjTUEPdaZOKHV0b0kElbVvlNkjc187UnqfF1RYjR7eTlEbdvhC2X+jnzPNj0SvZchi32ZTjHl97diwZy2da/kWEDzkxW1Twd/q0j/OUv5iW5vg2u6W7MNMr4iov6YjnK7KbQMCFke8WsK92ZoEHGySEInr05fl1Z0niViYXSu3wlOAvYfR8jnb4g01mlsbWDgfUjhFpnkAr1gBgaMqqVyA1q4Bpv5fek0/t4T3U5py/4Vv2uN0ZRJD8geLBGGB5Wvl3f2vV+cpGxcX1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HO+ZDjq5SAulxNJkYriHDFgb1h1ShU/qjf3aL1bMhWT5fA/4c0fT1dYCQ3Odyts3eZACJbtcoS5UFVL0QaRZiNQ/mhJVVTbdSCDBuQWL1bXZCvfu0QLT X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4f7cfa9-19b8-40c5-7725-08dd14255884 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB7044.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2024 05:34:39.0354 (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: yiJINn2hgP+uOsYKI5AeNpe86OAtuhYAXH8v7z93ou1lyXSkEYFK2lcDAYD28XhgmZK0RUuaeiJNc847nbGH2w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10125 Message-ID-Hash: QY7ZY4MT5LXZRRBHVORZ3YSJSWWHQMVH X-Message-ID-Hash: QY7ZY4MT5LXZRRBHVORZ3YSJSWWHQMVH 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: Register m2m platform device, that user can use M2M feature. Signed-off-by: Shengjiu Wang Acked-by: Jaroslav Kysela --- sound/soc/fsl/fsl_asrc.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index 471753276209..677529916dc0 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -1384,6 +1384,12 @@ static int fsl_asrc_probe(struct platform_device *pdev) goto err_pm_get_sync; } + ret = fsl_asrc_m2m_init(asrc); + if (ret) { + dev_err(&pdev->dev, "failed to init m2m device %d\n", ret); + return ret; + } + return 0; err_pm_get_sync: @@ -1396,6 +1402,10 @@ static int fsl_asrc_probe(struct platform_device *pdev) static void fsl_asrc_remove(struct platform_device *pdev) { + struct fsl_asrc *asrc = dev_get_drvdata(&pdev->dev); + + fsl_asrc_m2m_exit(asrc); + pm_runtime_disable(&pdev->dev); if (!pm_runtime_status_suspended(&pdev->dev)) fsl_asrc_runtime_suspend(&pdev->dev); @@ -1497,10 +1507,29 @@ static int fsl_asrc_runtime_suspend(struct device *dev) return 0; } +static int fsl_asrc_suspend(struct device *dev) +{ + struct fsl_asrc *asrc = dev_get_drvdata(dev); + int ret; + + fsl_asrc_m2m_suspend(asrc); + ret = pm_runtime_force_suspend(dev); + return ret; +} + +static int fsl_asrc_resume(struct device *dev) +{ + struct fsl_asrc *asrc = dev_get_drvdata(dev); + int ret; + + ret = pm_runtime_force_resume(dev); + fsl_asrc_m2m_resume(asrc); + return ret; +} + static const struct dev_pm_ops fsl_asrc_pm = { - SET_RUNTIME_PM_OPS(fsl_asrc_runtime_suspend, fsl_asrc_runtime_resume, NULL) - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, - pm_runtime_force_resume) + RUNTIME_PM_OPS(fsl_asrc_runtime_suspend, fsl_asrc_runtime_resume, NULL) + SYSTEM_SLEEP_PM_OPS(fsl_asrc_suspend, fsl_asrc_resume) }; static const struct fsl_asrc_soc_data fsl_asrc_imx35_data = { @@ -1538,7 +1567,7 @@ static struct platform_driver fsl_asrc_driver = { .driver = { .name = "fsl-asrc", .of_match_table = fsl_asrc_ids, - .pm = &fsl_asrc_pm, + .pm = pm_ptr(&fsl_asrc_pm), }, }; module_platform_driver(fsl_asrc_driver); From patchwork Wed Dec 4 05:33:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 847348 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 46D7CE7716B for ; Wed, 4 Dec 2024 05:37:08 +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 7B6EE14E2; Wed, 4 Dec 2024 06:36:56 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7B6EE14E2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1733290626; bh=oROrbigEnbxBbJQZmQCz+t1ZoYRdoE4L/rIVMdGvE9E=; 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=F6MgI82SQ+1AFGWOAiS/yk4pKCbRjd0oPaYIdJqQDytn0MR+yTSLOSsKc5/cgO2v7 R1Yl1Zf0F2V0Xjs654LMLiaxf4qsQQRnGy7vDBHAu+MzsuyqRFl1SrhpNC5UsnmE91 68JmFXNrYmkWrR6Vux+pAvGvnEM9cdB3m9X9zQm8= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3CEEDF80689; Wed, 4 Dec 2024 06:35:23 +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 4062AF806B3; Wed, 4 Dec 2024 06:35:23 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 94275F80613; Wed, 4 Dec 2024 06:35:02 +0100 (CET) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2066.outbound.protection.outlook.com [40.107.21.66]) (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 D1AD2F805EC for ; Wed, 4 Dec 2024 06:34:55 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D1AD2F805EC 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=VBePAkvy ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vCA4GLv6Rk09JsEWGvECnAHqqzjL9/cxRx6ZsMEjBGOVCMQpdHYUKz3I2YUCq9u4UZm9iPRIICMJvTybComMvs+iNzSgSuMPhIKkXFJIJaEj+JFTMTSTGXYgQykVjhN6xpL7u9TEFQwSf8sP3GbXSEDyy36wWVAg/zA9PPStL3A131x3rNZpps9DsgH5D3hJSEdz9RMRWQO59XzTXXHh2NHErj/KcMtMqUT5aqoFZH8Rove5c9NHaQaj9iVrSAB/Yqg8xVCrVPm8BL7d33pWk1ZNeUiE1wDwqXOpO1CmY7PG/Hw7RjW1+6uKhFf2z1vkdIOf9Rj8Oq4v0swgo0T4qw== 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=mJK8WWOvDdKnJn03HGc+yupP/YXIOxc9ngBNgUkeoqw=; b=jjZMtKxdGv0lSMbndjwfd6MORnq9+nJeXyJarIV7PPPr99OLbkHL8sQfMi64+Y3vEgZ+ifZMRxAyrAmHqS+8kQuxOXYP0/cSiA98lipT52dho/RE//b6adADM97d5FOCrGRIC/58hpTuufz6LgLnqpYIiQRNZZFIraUZxEUL3HciqtppHWe+a454MB0mmcVcZbJcrKvPrI5FepGxhlTmITYJb87aRmlTe6Bikyl2KNKL6UXz76lqOljhQa81yimaGQ2VN5lW4rrJLufWVKQgJl60UksDbawNO0+zinLuPBXQf9XUg+jyRuEWSYsyUzWRGeUCDLRXXoJSQ9H8HrLIBw== 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=mJK8WWOvDdKnJn03HGc+yupP/YXIOxc9ngBNgUkeoqw=; b=VBePAkvyj57D/WluMrgguQ/DkYVh1wEof88wFmZF/jJuhT5xAdfDG1T7iJ7oKeeCN7wrQUx6vOKDSRaP2ExM1vzZ73UGUrZWrdvr19r+BCyTddAHZ+UWH5m8AfOdjtjcUR/O4b4dsVMXxKFAcSGuVvTXW73Q3zHRFhCb+2p5JsxUJozEGmuQPVZxZxjIk3ZibUbN/WB2Sa0hX7H3KQ4t/lcIM7zpKHO9i6nKt3elcFYZbSPtzQsep/LVt2xEpLsN5w5VVwZ/wG+M8mhQYwQmZeDB9ohJY1jyzjc1HTJNYhvKKKSNMapEGAnbJhR1fCBJ0Jwj8XlG9wlz/eG6UpgC+Q== 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 GV1PR04MB10125.eurprd04.prod.outlook.com (2603:10a6:150:1ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Wed, 4 Dec 2024 05:34:44 +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.8230.008; Wed, 4 Dec 2024 05:34:44 +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 RESEND 6/6] ASoC: fsl_easrc: register m2m platform device Date: Wed, 4 Dec 2024 13:33:46 +0800 Message-Id: <20241204053346.1865723-7-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20241204053346.1865723-1-shengjiu.wang@nxp.com> References: <20241204053346.1865723-1-shengjiu.wang@nxp.com> X-ClientProxiedBy: SI1PR02CA0039.apcprd02.prod.outlook.com (2603:1096:4:1f6::9) To AM0PR04MB7044.eurprd04.prod.outlook.com (2603:10a6:208:191::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB7044:EE_|GV1PR04MB10125:EE_ X-MS-Office365-Filtering-Correlation-Id: f2521656-d872-413d-1495-08dd14255ba2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|7416014|376014|52116014|1800799024|921020|38350700014; X-Microsoft-Antispam-Message-Info: 2mkYLbvHJORao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b9g+eFh3PrlNSYxDAn05j7Fm9iaB9Q5IUOoGZ0mxVdBKxEAJRkjEmRhnUt2vbUZClAu37ZZ50/ugbhfRn0873pdf+fMZOeEyQJsZtLOuiSK8OfAaWZmW1cTYqVMVmBoaNRv3LsCp+oWomA3J5LPL0zRwAEDif3w2V8II6K7jtdsSd52gD1woZd/CFV847K4e3h7uMnILcgOSD/E8Ioa9v+bPOuBDuuPf4fXWxqmffbrEsXInp+DA26kAMlPMP/6Xdg11C0FrgcqSCO9UMQGEEn3UoqtRoMtoLbMN5LlYof2riM8OcyaBmuWfIx3LAoAMzOlZ7BrtBbyepF7gbYue5gmVH11/T8= 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)(7416014)(376014)(52116014)(1800799024)(921020)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5RM51+D8Gf5NvP/ijv2PYoEdyInBR1M0srhHI19Wi9nGwR5C7EW4EGbEJ1fvdPy5uZGmHkfFQ7toPahD/dqIsbRYGwRj/Ba0cF2bB7cukgjlvUs2LVK8o8gpyfFwPkuGsgRvBCmGQ2kodyBSJxavCdsvnnrnM4kL7pfQZKQpGlfQKRkp4dOrOUif0MkQfsJ12xlLRY6h4zF3qD9KzsRDb60kfD4bFn83k12JqrAcb0MnAD+BJDdpnIy45dV+IgeJWkpFI4sOqc0AFzMW6znNZO0YFxtusTvcQ00H0+EqgrsfGFB2VDKB1OGi1sbddyAHFpUDD6uorBfPfbgA1GvcV4cwzyf0Qr0A1A4lO3J+euCO/F+Z05rMN7PAHApsEe0SBCfxr9tv9fQgnGCUD+n/+6S06KL1lS+RgHNvPsWT+EafOaDITN7w9vU7FVxTZael30b20Zhl6d1ZOzMIad/n8Kc8N4sunUWi84AMp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S0oWxspshxbOAGxOHBeds/eK/vkpvLG/FIrjdzv1 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2521656-d872-413d-1495-08dd14255ba2 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB7044.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2024 05:34:44.2987 (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: YxpHrJxr8MiF0lB1rwGmeIms/4WAIBzFSUCY1VAiDSS17+ZK6zu66pF93kmPpfcWSaqtmHXWC1BUWlIMTl7uJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10125 Message-ID-Hash: UT3R2PDZJOZIEKTH46DWE4S2HYM7D6HB X-Message-ID-Hash: UT3R2PDZJOZIEKTH46DWE4S2HYM7D6HB 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: Register m2m platform device,that user can use M2M feature. Signed-off-by: Shengjiu Wang Acked-by: Jaroslav Kysela --- sound/soc/fsl/fsl_easrc.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c index f17a185a1910..f404a39009e1 100644 --- a/sound/soc/fsl/fsl_easrc.c +++ b/sound/soc/fsl/fsl_easrc.c @@ -2204,6 +2204,12 @@ static int fsl_easrc_probe(struct platform_device *pdev) goto err_pm_disable; } + ret = fsl_asrc_m2m_init(easrc); + if (ret) { + dev_err(&pdev->dev, "failed to init m2m device %d\n", ret); + return ret; + } + return 0; err_pm_disable: @@ -2213,6 +2219,10 @@ static int fsl_easrc_probe(struct platform_device *pdev) static void fsl_easrc_remove(struct platform_device *pdev) { + struct fsl_asrc *easrc = dev_get_drvdata(&pdev->dev); + + fsl_asrc_m2m_exit(easrc); + pm_runtime_disable(&pdev->dev); } @@ -2313,10 +2323,29 @@ static int fsl_easrc_runtime_resume(struct device *dev) return ret; } +static int fsl_easrc_suspend(struct device *dev) +{ + struct fsl_asrc *easrc = dev_get_drvdata(dev); + int ret; + + fsl_asrc_m2m_suspend(easrc); + ret = pm_runtime_force_suspend(dev); + return ret; +} + +static int fsl_easrc_resume(struct device *dev) +{ + struct fsl_asrc *easrc = dev_get_drvdata(dev); + int ret; + + ret = pm_runtime_force_resume(dev); + fsl_asrc_m2m_resume(easrc); + return ret; +} + static const struct dev_pm_ops fsl_easrc_pm_ops = { RUNTIME_PM_OPS(fsl_easrc_runtime_suspend, fsl_easrc_runtime_resume, NULL) - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, - pm_runtime_force_resume) + SYSTEM_SLEEP_PM_OPS(fsl_easrc_suspend, fsl_easrc_resume) }; static struct platform_driver fsl_easrc_driver = {