From patchwork Mon Mar 11 10:56:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13588585 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11020002.outbound.protection.outlook.com [52.101.154.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CB2C37169; Mon, 11 Mar 2024 10:56:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710154599; cv=fail; b=VfQvRfscrCn+WBslRD7wckPkme7z+TdTq3JPnI6BpHHtH7OfMXpJcmf5gEF9VjCPuZQwOxas15FSuygGGyslzVv42NUzL4jo4KyAVbXTiV/zvI3bV0epY8A7iNMFEp07pg6eUWIX2xxaS24Sk/syZ8ZRtoqTTGSn53SxssBwMgQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710154599; c=relaxed/simple; bh=l2wUCmHDK8MzOelGsKM+UYRm9Vter11l6pl5SdW3fx0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=I1AFrGVVWctW2G5s6oXLgY4KW/VsPG+N+YRy0q51nQxfH3Vn+xL+SIMrjhHghVDUmvvd4082DLQ/q2FP53Q5kTa98t7KjsTwO/To0znFx/eQNDjI99d+H0KQzHV2HAVujOcSAbtIGgTC45iGpW1KlR7ngcuDaGAtI7uvO7zpS0U= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com; spf=pass smtp.mailfrom=chipsnmedia.com; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b=N0StllYb; arc=fail smtp.client-ip=52.101.154.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="N0StllYb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rc9CfVBCmg6iA7pm2NdTZvs8rT4Q7YWOAyroUm192e1GDbYu0G7u1TDngGmEpeKXjObGaGal//RT4TQkZ2Xn+tnx5CH1nlLGmsx/TSikS0upIswNfEkB152N6QyUkB72vQ14qWHUBwVxZKT+0XSLZgYRHIZnQWmMpVDp2l29xTH8lVCp5dAITb8cQyvAUgu48lHHHf3jRIGR6Osvtgv6qnay5WOpAufO+2TZwBMciUeJSXNyEiBgi2gB6BqGGKvWogUegfeZ3nCccoYrrEU1WBY5Q/3DYaOw3m9NlnSjuxQncGN3KiLU9Q+8r86rcWHk/6UM/DtqdU7ZbMF6xeBAIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=rLpqCFd9QlagKVmdqGgrlC5upXeqJ3Sr5cHld6DJd6E=; b=Do7ZWhN3BQwkB+L10VDceYMnVrD5sQeIYfFFy0ZQfMYOtKx4ZeLpnV421dIUAYkVcJTCH1htq+3q2kXqU6t3wRMNV+tiO98BVuYfEwV4E57TPIF2rN/ZmsL5No2KUITJPuRUWhLXnpXVaTzxxgF8N7g+QUR4+U6M6rhRxJaBXA9/qFo50bIQRzSpO4yJ01MDSkVD9CZoxSSU6bn8NBebuPc/R+f8NvEibc8mg19D8tARL6rHFbJPEls3nChgytSH0SfOV2iOQWRXdnfc6FIPObJZfIFcHtVrMyCgGs/pKu818ldUfZSi4BxXOiMKFHoY+30Hlis+I7BjwoIWJV74pQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=chipsnmedia.com; dmarc=pass action=none header.from=chipsnmedia.com; dkim=pass header.d=chipsnmedia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chipsnmedia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rLpqCFd9QlagKVmdqGgrlC5upXeqJ3Sr5cHld6DJd6E=; b=N0StllYbrYQSE41UPjOCVrkuXr7xZqk2CwjaYcPzruZIfgaAu+b7iMFjbx7kEx4kb9W968t506qw1bHjDdFxevY1k5o3RO3BtJpRENojAFre+uvAqnKHUgyUKJG2qbvX4XI2bFCKlLcoSOZMs9/rnLTaIeE9Mj/DcW2kWQkEaWI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=chipsnmedia.com; Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) by SE1P216MB2024.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Mon, 11 Mar 2024 10:56:31 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::ebb8:2043:fd53:303a]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::ebb8:2043:fd53:303a%3]) with mapi id 15.20.7362.035; Mon, 11 Mar 2024 10:56:30 +0000 From: "jackson.lee" To: mchehab@kernel.org, nicolas@ndufresne.ca, sebastian.fricke@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, hverkuil@xs4all.nl, nas.chung@chipsnmedia.com, lafley.kim@chipsnmedia.com, b-brnich@ti.com, "Jackson.lee" Subject: [RESEND PATCH v2 1/4] media: chips-media: wave5: Support SPS/PPS generation for each IDR Date: Mon, 11 Mar 2024 19:56:20 +0900 Message-Id: <20240311105623.20406-2-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240311105623.20406-1-jackson.lee@chipsnmedia.com> References: <20240311105623.20406-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0127.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1::6) To SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SE1P216MB1303:EE_|SE1P216MB2024:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d2fb6ac-2fd6-4300-d1ed-08dc41b9e896 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rmq3OwIEJm8WTwuRSfrHgQFCxAncYeHYranuCx0Jr0PwpKx1RL5vwLpZRE9+mPHUYkivTXDrjlBxx+gA2zeNrLRFCwLZCpfJJzea905eIZr4CFyohwC9l0y5RVT10a8yAk8+phBV5MHp5sof+gKtoIQ2jBSGh8RmYMDLVlkEtUekGnz8KVFu8Ge54aDxWOlZ5WAeSbqaL/qNx3j9mwCROhcsWAqE1dKttbge5l5ebGV4CA6ia7/VncQdRg8a7inZ5ayUIzjt5jGI5iTiDDJ0ePwwo6yBLjU9YwtMdK7Nu6XRFhUiqNwmqgOE+iMyYS7cS4i3WopjZhlNGiqx6/h985PgRifyWXzBwjcWOlT9M02Vc8y+HHzGyoczxmbGXuRex38txKRC77z/Ee4EtLx1FwjRGvCMizwSUIwm3qssdHePdyTAnb4Ynkq4FNEvbbP6R8tY37jQdwkJRy6qAYqO3XuOEFC+o1/ajDCH0xcPdam1nk/Y/tfTSfsiJhnbG6U663ViDSW+eX5CAf3MKC0bN8uiOr9lvtpK90Np4WDPoG6Tuc88wbKEJzAy0HWYpqYnEaGClDKP0tFptyHF76Nnsvqdy6i3qbYshNRCoyyO8kGaUGePXnCIgD+3+9h14a4d96g6v9QkGIfBUES3eZGlMsM+yxhoMGoUpPYWc4cxSmjDYEE1EKKMJbBtupKcc6FKtx1ZeY/APzOPgHmg0OtQedimJOfBjPWVgPyNc8hoM78= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SE1P216MB1303.KORP216.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(52116005)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ek4IxOMPARtVagvrttkXy1CO7EtTChuP00gaLP/nBdJtmimEHXMOy7fdgXHKeV0iXxrW5sK7C7J+f2P9aHevKTo4idKh2W7exgY4bGGPSLUTyb9xFMq2rQ8gKof4LuA5tMuTbcJCiCHW2ojtaq7od+Lz82+P5bIGUNZakY+tQVN/71ZvF6G4vib2UzWU7sX3E6aSXM4Bh2dJ0vOrv8vnb0FUoq8Jpp69QIrnoEhtZCwuuQM1WHkTRWJrQkdQiBgGKNAxNEXdiHnHuZ9iX0mCsK15eCeYCQohEK7bplR12zAXzIXSf0lXJrJqHXfP3l50tZCFrss3rjq34bzP8ygRAc7QVHe98e+pZ4IdhUh8lUsaYhUHjRU2u4sSe0j6/Hn2xcpZHjot4tkPB3qZgysxdq62bQx0IlTr1biAkeYYb1FvcNno5cgIHuHXD6kcFk4yD10y2Cqi/wrpXhjzlkoEDwhbkO7PVciYfs/hQDDbsvuUEZ/vBTuap31DKxWFifFsIhpp0jLlSCDiT9ZUNT9DKw96HU8+wxerkEiPtGicS/frFjQ3oZtrbefNxTQsqyKHDg2mFZ5ffTIsvl7fxfqytzYxA4aVwyOVkNa0dY5zVhA/8seKqzNJPA3zbaNF9BfHlGtj2c9tPBKbHVcnekjMaxBTLeXY//owWfebiSnLygTuVKfhAqaXLGGBk7a0PUqVlHeUl7QmJnW1QYv/ED032XrXj2bRhQeYy4XZuD7jmqprB0IKk+jik1ad6Djp3FjADqcBTmk6RwpU41RuNElm3qMgGMffO6SV+aLauFleMZWcqbaoVxsGWVHlIGvOWKKmhSwov5xkqD0yDm1baXEtPFpmgpgk735uGbisjavVUOUDPJUG1VWjq4Gnh4ZG+pzCIbC0GjgMZN8Mkg+XQda09fGEJu4hbq8vkYBaenxz/nrw+BXB2NawAkfctjpD0i/N46aHlm3XlXlo8psXtWv4IJSCvRHKo8MURikmz68s1V2NjxkSzGj9iVww+Y6g5cdhYe3Bbw1niYKqsTdtB4Xfq+lZ+WHSdeVI96RZJdyAiIOKGSnOtfOfjQ+/lr1CE72HH4tbX+4BQvOyhaBlrPg+Lw+DRZsbQ/SjWg5AgcaArJU7+BQr2pQ0wqB1dAuh6HbJk+3DZZmm+G0Pyfa125Z3eXE0gD9SxE7J1ggPg5DLZNloIOYNWJ37BiremuHz6vd7xivpz1HlrF3umpSAEJv9fPOf5vVW7pqwiABt+bl8vSZWAga/tIIj8u5mZNPZMsacRxoklt8tt6yUQgNL8gMpNFvV3Oydz5oAYiq/6OTtQiNze5EGK2qPVI6ikNm8H8boimpIE96IWsSBjFjCKPorbeFUfG1CsyFrZduxB1xt0UPJFYZFAlcthAIxS1N+QwkBDpmddgWlRjw8a3iuRtZotbnCdRQ2ZexS8GHTIRE8+nfOGfgkNiA5K90D43ifvzYPzcE+i0WGbX4MsHDpuY/iBaVgCuLMdlylKRYP0FUiTORb+yJO2u3Sk3RTaOsE4a3J/Xs0N88Kz0vKpz/7PE6sGw9TKwLnhBnN5XEe8WcPp3V8m1SmpfsIQj+IqWCPDTA+B1YcdMSVnatryQXN7mE9BGAUtVVe/o/ScPzofn+03m0= X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d2fb6ac-2fd6-4300-d1ed-08dc41b9e896 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 10:56:30.7800 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4d70c8e9-142b-4389-b7f2-fa8a3c68c467 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tdklFd38tZ3s1CVgpOygb0QHHJDseD7F2AHqO2tregj/vesMdt9jTMEMyRLsnCFyYholKHniM5sRa2dAC1hQ+/efx45kly0tH+zYmshWBQE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE1P216MB2024 From: "Jackson.lee" Provide a control to toggle (0 = off / 1 = on), whether the SPS and PPS are generated for every IDR. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung Reviewed-by: Nicolas Dufresne --- .../platform/chips-media/wave5/wave5-hw.c | 19 +++++++++++++++---- .../chips-media/wave5/wave5-vpu-enc.c | 7 +++++++ .../platform/chips-media/wave5/wave5-vpuapi.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-hw.c b/drivers/media/platform/chips-media/wave5/wave5-hw.c index f1e022fb148e..4a262822bf17 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-hw.c +++ b/drivers/media/platform/chips-media/wave5/wave5-hw.c @@ -23,6 +23,15 @@ #define FEATURE_AVC_ENCODER BIT(1) #define FEATURE_HEVC_ENCODER BIT(0) +#define ENC_AVC_INTRA_IDR_PARAM_MASK 0x7ff +#define ENC_AVC_INTRA_PERIOD 6 +#define ENC_AVC_IDR_PERIOD 17 +#define ENC_AVC_FORCED_IDR_HEADER 28 + +#define ENC_HEVC_INTRA_QP 3 +#define ENC_HEVC_FORCED_IDR_HEADER 9 +#define ENC_HEVC_INTRA_PERIOD 16 + /* Decoder support fields */ #define FEATURE_AVC_DECODER BIT(3) #define FEATURE_HEVC_DECODER BIT(2) @@ -1601,12 +1610,14 @@ int wave5_vpu_enc_init_seq(struct vpu_instance *inst) if (inst->std == W_AVC_ENC) vpu_write_reg(inst->dev, W5_CMD_ENC_SEQ_INTRA_PARAM, p_param->intra_qp | - ((p_param->intra_period & 0x7ff) << 6) | - ((p_param->avc_idr_period & 0x7ff) << 17)); + ((p_param->intra_period & ENC_AVC_INTRA_IDR_PARAM_MASK) << ENC_AVC_INTRA_PERIOD) | + ((p_param->avc_idr_period & ENC_AVC_INTRA_IDR_PARAM_MASK) << ENC_AVC_IDR_PERIOD) | + (p_param->forced_idr_header_enable << ENC_AVC_FORCED_IDR_HEADER)); else if (inst->std == W_HEVC_ENC) vpu_write_reg(inst->dev, W5_CMD_ENC_SEQ_INTRA_PARAM, - p_param->decoding_refresh_type | (p_param->intra_qp << 3) | - (p_param->intra_period << 16)); + p_param->decoding_refresh_type | (p_param->intra_qp << ENC_HEVC_INTRA_QP) | + (p_param->forced_idr_header_enable << ENC_HEVC_FORCED_IDR_HEADER) | + (p_param->intra_period << ENC_HEVC_INTRA_PERIOD)); reg_val = (p_param->rdo_skip << 2) | (p_param->lambda_scaling_enable << 3) | diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index f29cfa3af94a..f04baa93a9b7 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -1061,6 +1061,9 @@ static int wave5_vpu_enc_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: inst->enc_param.entropy_coding_mode = ctrl->val; break; + case V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR: + inst->enc_param.forced_idr_header_enable = ctrl->val; + break; case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: break; default: @@ -1219,6 +1222,7 @@ static void wave5_set_enc_openparam(struct enc_open_param *open_param, else open_param->wave_param.intra_refresh_arg = num_ctu_row; } + open_param->wave_param.forced_idr_header_enable = input.forced_idr_header_enable; } static int initialize_sequence(struct vpu_instance *inst) @@ -1702,6 +1706,9 @@ static int wave5_vpu_open_enc(struct file *filp) 0, 1, 1, 0); v4l2_ctrl_new_std(v4l2_ctrl_hdl, &wave5_vpu_enc_ctrl_ops, V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, 1, 32, 1, 1); + v4l2_ctrl_new_std(v4l2_ctrl_hdl, &wave5_vpu_enc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR, + 0, 1, 1, 0); if (v4l2_ctrl_hdl->error) { ret = -ENODEV; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h index 352f6e904e50..3ad6118550ac 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h @@ -566,6 +566,7 @@ struct enc_wave_param { u32 lambda_scaling_enable: 1; /* enable lambda scaling using custom GOP */ u32 transform8x8_enable: 1; /* enable 8x8 intra prediction and 8x8 transform */ u32 mb_level_rc_enable: 1; /* enable MB-level rate control */ + u32 forced_idr_header_enable: 1; /* enable header encoding before IDR frame */ }; struct enc_open_param { From patchwork Mon Mar 11 10:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13588586 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11020002.outbound.protection.outlook.com [52.101.154.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB31838F82; Mon, 11 Mar 2024 10:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710154601; cv=fail; b=FVYeFDahgy9jo50BeZMm/Tc26gjRTg2VQPu0EjY//SGO0U5KKgSQ1jW8X9ASABn800D6MhUWeC/6qcTIQ0eno/aJplNygcugEj5MLsUHLv9zt6rm12Ev8QmlNfM9JBOCd7/gIchxXnIvdrPWz7YnYaJIkA7vDM07CC+NFBm0s3Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710154601; c=relaxed/simple; bh=c699SjHFtTzC7I067eLP9WqVNL2aredc7aHxW6xMntE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=D5y2rSRPa5iV9iYzgHW4+LccYOnTffkKXvdu3qDAU8vCOSq5jTTQoIgjwnsx8SdSOje40QZjO88Ibdv6fkkxOEmp05FC50eRyjB/luQZlwMN5KG9R/MDQ+CCWWF+oYP3460xp/KVYs1PLmvuxCgNQTgFym28be/9fjtQReEQOzo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com; spf=pass smtp.mailfrom=chipsnmedia.com; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b=F3G2wuWk; arc=fail smtp.client-ip=52.101.154.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="F3G2wuWk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gb2bawGp5cP34Uk03W1SCXn37hVi3m80AUxWin/lP1xiWngdTjuZeBWUJ8rgmFhmEFbkaFBPXxzYSqFnJFoaH/tenDLwIw4+pvRMuArwrDprGlyrhrEwEeVea3djYhRftYsChyg/XwbxYBdesDXPzwa1yVxFF4E90PfWr66yx+fGZkX1yEutGysG0fw7FJXKRc7BpAt9/D4khoan67LRVPijkW/OGuoLTS/AGD7IYkeCuZwKAu5aBGYkY9pwml4IjfAjgL9B3yxBr0QJtTuSQGHBhwVrvcJd9Gy54TuDTtC3o3kKnTF5ku/X+i8YK9xzxgDe/ZaeXlAF6kMgdBiJhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=pBu1pcMHOWrYRIuELwvfaJNrJcQdtFs5qXu5g0hd17c=; b=NUAP3motvxX6mn2naE64itbYZgGsbBOL+r+StEa16oWkkokveS6qpYcKx0lkNPy5NcVYZAmaYK9bNuh3rw3jloWjM20Wce15lbXmtPBrvCjw+yT6YnVp4nIZ56MWf7Wn4kztMqGIPid9ssJ8NByUhi9OTFAB3mx9yxEuaFM5DDqfMwqnLXz5IdFom6H1O52Xg4e1v5+anmMZyKvrWAmUKKET8zF5k0vKpPItxKXuSfjGI/6cV24hhMRn/I1kooxIOyxqDCy/C1wGH1GHR6bQRSmENd5suahLlUx/CG/zRvjKi6OIuZZhm/WisWXpex3vzC48sx8F+qSl0BZMNOds5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=chipsnmedia.com; dmarc=pass action=none header.from=chipsnmedia.com; dkim=pass header.d=chipsnmedia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chipsnmedia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pBu1pcMHOWrYRIuELwvfaJNrJcQdtFs5qXu5g0hd17c=; b=F3G2wuWkJ5eJ29EbRCX8VTyqgZp8RtgJkKMN12JwNJn2ujEWppH4Yr8WlqiDAZQHa3C/dwNawvdYgJ3TGkQgNfSo/hTgd0e/paxYaKWJ/rNZgOJjsGsFbmvZ3HIkLI99ya64P7eFe+0KIHTp4q02Phnd/GQXic8s88YTCulawjw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=chipsnmedia.com; Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) by SE1P216MB2024.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Mon, 11 Mar 2024 10:56:31 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::ebb8:2043:fd53:303a]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::ebb8:2043:fd53:303a%3]) with mapi id 15.20.7362.035; Mon, 11 Mar 2024 10:56:31 +0000 From: "jackson.lee" To: mchehab@kernel.org, nicolas@ndufresne.ca, sebastian.fricke@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, hverkuil@xs4all.nl, nas.chung@chipsnmedia.com, lafley.kim@chipsnmedia.com, b-brnich@ti.com, "Jackson.lee" Subject: [RESEND PATCH v2 2/4] media: chips-media: wave5: Support runtime suspend/resume Date: Mon, 11 Mar 2024 19:56:21 +0900 Message-Id: <20240311105623.20406-3-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240311105623.20406-1-jackson.lee@chipsnmedia.com> References: <20240311105623.20406-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0127.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1::6) To SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SE1P216MB1303:EE_|SE1P216MB2024:EE_ X-MS-Office365-Filtering-Correlation-Id: 25069910-1368-47a6-d792-08dc41b9e8be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kCNt3y5e5ZDeYTgEWydzXOfFb2EAY0DshyJtiW+Prl5lzT/w+gyoO/n/LO5IV/P4JAsefxi6tBU/mZPADlVDPcjgbr+4TioJvYvJwF2lWfFsKnXNo99pgKs09+I7tDdWLDtGelUffEkEfQPP9USs6yp+LLd0YIZT3Wo8h1GHafXAN2rHUboIfrdPUJXVUAjA0qWET6AlonEwvZXZ7YHCGSaCrpOCieNNojgX7GMm9bvAl6ZxmWhdFaIYR/V3p5p8OZaMgLxneotp32m+768XIQlv9ljI5/o8TqOOfKxvfDgVOYgebu/QRhD3HzKRkoAb9+pLoL/ODujzbuylEQZIlR5clhBjtH3AIE8oTTyvpaK6MdWuRr2ua5Nioh9xeBTlqXT5/tRjIMCsiW5BYn0J751YWJz0ZJ4z59jdL5hpaN11DsAcf2tDgqflgcoBeB9S6m0zfmEdVRUFMEfDsCXXW6gEl46grgUAFy0wtjeoMU3z4/mni/K560H/Ec57APM9P7HjDVptgSXAwfFa/X1DhPVrY71b2c9ZWCh2eez7GpzqWQuBNRv7BgrxG6GxPg4PDWQLZjA7ixdI6NOdqkYbml++4uIBfCHehdvcqRIE0SvR4SCI0sXJMX2iyYLTqEltfnxLXTEHxubYw6/tLHC+jKRBauUCSh1hWc3JJYpg+Rz4ddIrIbVR1WMGfPm4Eqb5CCKuKajE8wWqivfBciUbZA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SE1P216MB1303.KORP216.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(52116005)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jRR7m5irvb264qJDRSkz4TN0tcgRdGO4BIe/93FSlYM3uKJYQfxw7qI8iYASogHFn6Y8FVzLY+O0NCpVmP13zTBd1RNrCiSByseRUVUthERQWiElADAkb84A14BIYi13Jqf/6jq6sUjnp9Ejy3lBDg+4a1Uuw7EDyZh0lcktjMAPmRxUwTWguF7WaLT414UuERsoWUiOcuzTtguXjkVZY9DX+GTrx3HCtiYBoGMy2jc0acDshifUf1cjpBYQbtZmRCTmNn/NEigsEck1SZ/bmEsxq6PrSeD7Ovb3lNyT0gi0R5B+lHi6QnAWNCJxvZZSzSKucoolb69O/gNLZ7QF66Qy19eCS4q6E5ieLD1rhrs5cYDpMJiLgNApXAyDP5nTjnw+oenXklOBe0rz304LuY6lcwtQ+441VAiTNW+0iJorDfytvy0YPUjIEaFayHTJmvn3T5tnGTRbbENJm8d+YgsmhBH/+1kxhAXtys8iMis4c1L8P5mfHo7kU5xLTSj0lRhVXLGMsKAnVET/2hVjRrYemkoL2rzvAgItgd4MSyEH8LK/ZqLrWvGDU6O/rM4wEYGGsUH9S2snY6zW+L+YACNp0+NJ7IIeIBlAV69Ut+WlCkbzGIQcu/ukXPjzdN6Adn3m2yCcxb9jUyos3enENmxh6DudHxjKkX1QuvRat6h7KA9ET1rAH0yXVDSFDsid0kuEnEeZjOLNsCrtqxpoVC4voiBuN3JpYuswLZ0fqMU4taJ0qCcQgHjKjSiM25+HAACj/ZHONcN/V0BEUxZGLovV9OxW5YiM9MZGygMr8x6eRInBX96TEo2GBwlh/1/5a/1mjlbXhAf7iALDlNRpc1faKsZBUKnLM25hBI+sd1f75CTSgawun4iluk5lNBYusSFiUAj86OvjyTJ+n96WUdwNBl407RAgMI+vJ8J0ZsDGt3Ak5DV8Y1Sc0lWDm15YdNzS2d88OwkyVF4Y4x+fzVw5QHlLAwsMwZ4Xs3TlIBGM1mFPpn13cOb1SMwxeWqxiLI/rvmQi6/U/fT+4Kl9FikVIQz85sEDSusSRcmPkdh+phb61Aq1ANVVXU41MB4x7FCb83UbNLBf5mhSYwtI0nrPsQxf54ILtLbYeameMqSTw1XRHPHKKY/4JMldrsnj1qhRpC4vUArR06qTwxbs7aOWlc6uVgQUen9C4DB9kQIT+6AnQS943vwuEEyHpqo9eo+9PXbNZ8B0eswnO6GlLEk5I6Fb8CLul3/aVFMM0N8kaSIB8pi/A5xPN1V9ZYPli7n7k6wB3pm4MuGngQ0kaVG/tKHYvxFucugUNOc5Goz6BXj2PFw8hRWCBCQgokFHM/crrGGMQTTUYxFwdDV/2fr2N3/FZoQEyoQEdbYm6F3VT5unkOQs5ZcIbKDVUQdMwn+F9j0uo2CGA/J9VoBMCKRqHDzLEL6h+yG4naRulgyzNWJeJhl7M0nr4dRaiFhdpm6+rN7OAes64e5cruRl1opVxiKozIH2FwKv7mN25EzxZTgJi1pqbfKRJX27Ct9K/PvXijqmGOL2u2FOy7sV7+U/2Cu+Hu6AEmjW6wyLCPVI2eAg87fEGZ00ADZS3hz652vCCcNUFSxxNlqJPcCLOFwGfhoN2neuUR7VtHRcDeU= X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25069910-1368-47a6-d792-08dc41b9e8be X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 10:56:31.0502 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4d70c8e9-142b-4389-b7f2-fa8a3c68c467 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ntfbn6T7Uh6+o7UMA/IR00I6QPt/hSWpav6anELbHB8kawt139kjQ+Nfsa4adcpfRQLjuD8gUcQduAj/cAFTqb7S+EAddJki2MR9uoiL7aA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE1P216MB2024 From: "Jackson.lee" For saving a power resource, we support runtime suspend/resume for an encoder/decoder. So our vpu module's power turns on only if an encoder/decoder is used. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung Reviewed-by: Nicolas Dufresne --- .../platform/chips-media/wave5/wave5-hw.c | 4 +- .../chips-media/wave5/wave5-vpu-dec.c | 16 ++++++- .../chips-media/wave5/wave5-vpu-enc.c | 15 +++++++ .../platform/chips-media/wave5/wave5-vpu.c | 43 +++++++++++++++++++ .../platform/chips-media/wave5/wave5-vpuapi.c | 14 ++++-- .../media/platform/chips-media/wave5/wave5.h | 3 ++ 6 files changed, 88 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-hw.c b/drivers/media/platform/chips-media/wave5/wave5-hw.c index 4a262822bf17..826b92b7b582 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-hw.c +++ b/drivers/media/platform/chips-media/wave5/wave5-hw.c @@ -1084,8 +1084,8 @@ int wave5_vpu_re_init(struct device *dev, u8 *fw, size_t size) return setup_wave5_properties(dev); } -static int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uint16_t *code, - size_t size) +int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uint16_t *code, + size_t size) { u32 reg_val; struct vpu_buf *common_vb; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c index ef227af72348..a199877c643b 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c @@ -5,6 +5,7 @@ * Copyright (C) 2021-2023 CHIPS&MEDIA INC */ +#include #include "wave5-helper.h" #define VPU_DEC_DEV_NAME "C&M Wave5 VPU decoder" @@ -518,6 +519,8 @@ static void wave5_vpu_dec_finish_decode(struct vpu_instance *inst) if (q_status.report_queue_count == 0 && (q_status.instance_queue_count == 0 || dec_info.sequence_changed)) { dev_dbg(inst->dev->dev, "%s: finishing job.\n", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); } } @@ -1382,6 +1385,7 @@ static int wave5_vpu_dec_start_streaming(struct vb2_queue *q, unsigned int count int ret = 0; dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type); + pm_runtime_resume_and_get(inst->dev->dev); v4l2_m2m_update_start_streaming_state(m2m_ctx, q); @@ -1425,13 +1429,15 @@ static int wave5_vpu_dec_start_streaming(struct vb2_queue *q, unsigned int count } } } - + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return ret; free_bitstream_vbuf: wave5_vdi_free_dma_memory(inst->dev, &inst->bitstream_vbuf); return_buffers: wave5_return_bufs(q, VB2_BUF_STATE_QUEUED); + pm_runtime_put_autosuspend(inst->dev->dev); return ret; } @@ -1517,6 +1523,7 @@ static void wave5_vpu_dec_stop_streaming(struct vb2_queue *q) bool check_cmd = TRUE; dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type); + pm_runtime_resume_and_get(inst->dev->dev); while (check_cmd) { struct queue_status_info q_status; @@ -1540,6 +1547,9 @@ static void wave5_vpu_dec_stop_streaming(struct vb2_queue *q) streamoff_output(q); else streamoff_capture(q); + + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); } static const struct vb2_ops wave5_vpu_dec_vb2_ops = { @@ -1626,7 +1636,7 @@ static void wave5_vpu_dec_device_run(void *priv) int ret = 0; dev_dbg(inst->dev->dev, "%s: Fill the ring buffer with new bitstream data", __func__); - + pm_runtime_resume_and_get(inst->dev->dev); ret = fill_ringbuffer(inst); if (ret) { dev_warn(inst->dev->dev, "Filling ring buffer failed\n"); @@ -1709,6 +1719,8 @@ static void wave5_vpu_dec_device_run(void *priv) finish_job_and_return: dev_dbg(inst->dev->dev, "%s: leave and finish job", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); } diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index f04baa93a9b7..013e2bb37fbb 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -5,6 +5,7 @@ * Copyright (C) 2021-2023 CHIPS&MEDIA INC */ +#include #include "wave5-helper.h" #define VPU_ENC_DEV_NAME "C&M Wave5 VPU encoder" @@ -1310,6 +1311,7 @@ static int wave5_vpu_enc_start_streaming(struct vb2_queue *q, unsigned int count struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; int ret = 0; + pm_runtime_resume_and_get(inst->dev->dev); v4l2_m2m_update_start_streaming_state(m2m_ctx, q); if (inst->state == VPU_INST_STATE_NONE && q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { @@ -1364,9 +1366,13 @@ static int wave5_vpu_enc_start_streaming(struct vb2_queue *q, unsigned int count if (ret) goto return_buffers; + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return 0; return_buffers: wave5_return_bufs(q, VB2_BUF_STATE_QUEUED); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return ret; } @@ -1408,6 +1414,7 @@ static void wave5_vpu_enc_stop_streaming(struct vb2_queue *q) */ dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type); + pm_runtime_resume_and_get(inst->dev->dev); if (wave5_vpu_both_queues_are_streaming(inst)) switch_state(inst, VPU_INST_STATE_STOP); @@ -1432,6 +1439,9 @@ static void wave5_vpu_enc_stop_streaming(struct vb2_queue *q) streamoff_output(inst, q); else streamoff_capture(inst, q); + + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); } static const struct vb2_ops wave5_vpu_enc_vb2_ops = { @@ -1478,6 +1488,7 @@ static void wave5_vpu_enc_device_run(void *priv) u32 fail_res = 0; int ret = 0; + pm_runtime_resume_and_get(inst->dev->dev); switch (inst->state) { case VPU_INST_STATE_PIC_RUN: ret = start_encode(inst, &fail_res); @@ -1491,6 +1502,8 @@ static void wave5_vpu_enc_device_run(void *priv) break; } dev_dbg(inst->dev->dev, "%s: leave with active job", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return; default: WARN(1, "Execution of a job in state %s is invalid.\n", @@ -1498,6 +1511,8 @@ static void wave5_vpu_enc_device_run(void *priv) break; } dev_dbg(inst->dev->dev, "%s: leave and finish job", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); } diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.c b/drivers/media/platform/chips-media/wave5/wave5-vpu.c index 0d90b5820bef..8e08461b3515 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "wave5-vpu.h" #include "wave5-regdefine.h" #include "wave5-vpuconfig.h" @@ -117,6 +118,38 @@ static int wave5_vpu_load_firmware(struct device *dev, const char *fw_name, return 0; } +static int wave5_pm_suspend(struct device *dev) +{ + struct vpu_device *vpu = dev_get_drvdata(dev); + + if (pm_runtime_suspended(dev)) + return 0; + + wave5_vpu_sleep_wake(dev, true, NULL, 0); + clk_bulk_disable_unprepare(vpu->num_clks, vpu->clks); + + return 0; +} + +static int wave5_pm_resume(struct device *dev) +{ + struct vpu_device *vpu = dev_get_drvdata(dev); + int ret = 0; + + wave5_vpu_sleep_wake(dev, false, NULL, 0); + ret = clk_bulk_prepare_enable(vpu->num_clks, vpu->clks); + if (ret) { + dev_err(dev, "Enabling clocks, fail: %d\n", ret); + return ret; + } + + return ret; +} + +static const struct dev_pm_ops wave5_pm_ops = { + SET_RUNTIME_PM_OPS(wave5_pm_suspend, wave5_pm_resume, NULL) +}; + static int wave5_vpu_probe(struct platform_device *pdev) { int ret; @@ -232,6 +265,12 @@ static int wave5_vpu_probe(struct platform_device *pdev) (match_data->flags & WAVE5_IS_DEC) ? "'DECODE'" : ""); dev_info(&pdev->dev, "Product Code: 0x%x\n", dev->product_code); dev_info(&pdev->dev, "Firmware Revision: %u\n", fw_revision); + + pm_runtime_set_autosuspend_delay(&pdev->dev, 5000); + pm_runtime_use_autosuspend(&pdev->dev); + pm_runtime_enable(&pdev->dev); + wave5_vpu_sleep_wake(&pdev->dev, true, NULL, 0); + return 0; err_enc_unreg: @@ -254,6 +293,9 @@ static int wave5_vpu_remove(struct platform_device *pdev) { struct vpu_device *dev = dev_get_drvdata(&pdev->dev); + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + mutex_destroy(&dev->dev_lock); mutex_destroy(&dev->hw_lock); clk_bulk_disable_unprepare(dev->num_clks, dev->clks); @@ -281,6 +323,7 @@ static struct platform_driver wave5_vpu_driver = { .driver = { .name = VPU_PLATFORM_DEVICE_NAME, .of_match_table = of_match_ptr(wave5_dt_ids), + .pm = &wave5_pm_ops, }, .probe = wave5_vpu_probe, .remove = wave5_vpu_remove, diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c index 1a3efb638dde..b0911fef232f 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c @@ -6,6 +6,8 @@ */ #include +#include +#include #include "wave5-vpuapi.h" #include "wave5-regdefine.h" #include "wave5.h" @@ -200,9 +202,13 @@ int wave5_vpu_dec_close(struct vpu_instance *inst, u32 *fail_res) if (!inst->codec_info) return -EINVAL; + pm_runtime_resume_and_get(inst->dev->dev); + ret = mutex_lock_interruptible(&vpu_dev->hw_lock); - if (ret) + if (ret) { + pm_runtime_put_sync(inst->dev->dev); return ret; + } do { ret = wave5_vpu_dec_finish_seq(inst, fail_res); @@ -234,7 +240,7 @@ int wave5_vpu_dec_close(struct vpu_instance *inst, u32 *fail_res) unlock_and_return: mutex_unlock(&vpu_dev->hw_lock); - + pm_runtime_put_sync(inst->dev->dev); return ret; } @@ -702,6 +708,8 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res) if (!inst->codec_info) return -EINVAL; + pm_runtime_resume_and_get(inst->dev->dev); + ret = mutex_lock_interruptible(&vpu_dev->hw_lock); if (ret) return ret; @@ -733,9 +741,9 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res) } wave5_vdi_free_dma_memory(vpu_dev, &p_enc_info->vb_task); - mutex_unlock(&vpu_dev->hw_lock); + pm_runtime_put_sync(inst->dev->dev); return 0; } diff --git a/drivers/media/platform/chips-media/wave5/wave5.h b/drivers/media/platform/chips-media/wave5/wave5.h index 063028eccd3b..6125eff938a8 100644 --- a/drivers/media/platform/chips-media/wave5/wave5.h +++ b/drivers/media/platform/chips-media/wave5/wave5.h @@ -56,6 +56,9 @@ int wave5_vpu_get_version(struct vpu_device *vpu_dev, u32 *revision); int wave5_vpu_init(struct device *dev, u8 *fw, size_t size); +int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uint16_t *code, + size_t size); + int wave5_vpu_reset(struct device *dev, enum sw_reset_mode reset_mode); int wave5_vpu_build_up_dec_param(struct vpu_instance *inst, struct dec_open_param *param); From patchwork Mon Mar 11 10:56:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13588588 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11020002.outbound.protection.outlook.com [52.101.154.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E70463BB48; Mon, 11 Mar 2024 10:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710154606; cv=fail; b=oatQlZLxQr4g1XU4+CHkAHiPCzTpImF6i0VISWVcFf8y6bjXFiQFRriLtkePzwySDQN26Fpv4a3rKZ1W2w9W4U6arXO1jQxTSu4TPDgSlYXRD0/j7tZDM+2G7JyzIe5mgb6CBsT3vPrjjSbU1uKNHMcEXgTC2q2H5nXtQWR+0L0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710154606; c=relaxed/simple; bh=KF2KkhwY97yPpKXUVmpbF3i7xpjsEMSKD3I5xXqOQ9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=XKV3BxofgjG7CN7rEoTBsy0Aq6Yb9DIG0oWg+Kid1CfU8MeZAiYBMrYlqIdZbxY8HiNe5YyrqyBJmO4vw++UhsCALwftVNMbKUSXxDAQgmbP6gt1d+eP52PFCzhaeWhgV7fn1zyTwfMsmO9vDV1i/055oENcK62Qq+4GeKyDL1A= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com; spf=pass smtp.mailfrom=chipsnmedia.com; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b=T9VRpWjV; arc=fail smtp.client-ip=52.101.154.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="T9VRpWjV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GOb2xBqX/Uz0Va4dn5ABwrAaKy8hFVZ/jnNc1AQce4bPlF2qDFawF84dwbPvjRuu7rLR3v+2oPNIvJ698k7Hw/qTIB7dl5xZUP3rhb9vmlaY3qJX/IgD2gY7rMT3Mv8/mAdqdTrnW5VXc++0T4qQZlN8EWBgyyFtQyl0qCjFBEpT3s6BiJ35KZaUn1nhrg3CmyXxsFh8n3Ca9iWq9s0MfwRnnk5CZUrp+HC94vdfh5OHlTyBb5V8kHiKprkauih8WPBKSIR5YwKlGx2pWaX2J7FQ/nd1MNbp/RmssKLzF1+ipk1lSr58zKIV963wCfEK/n/MUp7tUGPzPQmcS4LIAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=JA4o8o+vK0XyEfLgBuETe7CuY9cS1ojcn8q/FWut3IE=; b=LsURu7fj5BLPFLO0qjimtC09JPhBdCouruRtt16LHF7doEOBj1Cru2MJ/+zfWAVJ6gcJgr9KyX60OjFHdpV5/kq4B+W1f2QOqqKBR4UrrGkaSLLwHA5+ZfgstkVjY7eXHTrGpjASRWY4xH5BITgYKSztqo64IQiXG0NFLSrb68KrzfD2optUjC2sLh+kYCwr0Vo4uoSx3IHvIoOUtmAeGb+JIg0QX2i7hdjErjfZXpEIt+s+wC6x1LfR4oaJwpYYgm8y4KSiGVXTe1QiuvJSlDYrOj+VVmRua3EhH36o8wR0OdvjggGxywpq4XoVUj93wf0xtKm6F/489Gr7eq6org== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=chipsnmedia.com; dmarc=pass action=none header.from=chipsnmedia.com; dkim=pass header.d=chipsnmedia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chipsnmedia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JA4o8o+vK0XyEfLgBuETe7CuY9cS1ojcn8q/FWut3IE=; b=T9VRpWjVUM24Dn3SDl6zkQbwq2dpy5SaRWmxOjsNTPjTWuA/39Hl5FH4HDxFht4Ohe8xpyR9bvrgqqOEZssqFpDs4sp2/WBX0H6nzg7FJhMEaslOAz0vruT0aTaV2wOnpUHrtXXyTEAQ17Is3MPiwOOQk5M1eiFpkvthOUqhisY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=chipsnmedia.com; Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) by SE1P216MB2024.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Mon, 11 Mar 2024 10:56:31 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::ebb8:2043:fd53:303a]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::ebb8:2043:fd53:303a%3]) with mapi id 15.20.7362.035; Mon, 11 Mar 2024 10:56:31 +0000 From: "jackson.lee" To: mchehab@kernel.org, nicolas@ndufresne.ca, sebastian.fricke@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, hverkuil@xs4all.nl, nas.chung@chipsnmedia.com, lafley.kim@chipsnmedia.com, b-brnich@ti.com, "Jackson.lee" Subject: [RESEND PATCH v2 3/4] media: chips-media: wave5: Use helpers to calculate bytesperline and sizeimage. Date: Mon, 11 Mar 2024 19:56:22 +0900 Message-Id: <20240311105623.20406-4-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240311105623.20406-1-jackson.lee@chipsnmedia.com> References: <20240311105623.20406-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0127.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1::6) To SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SE1P216MB1303:EE_|SE1P216MB2024:EE_ X-MS-Office365-Filtering-Correlation-Id: cbdb33b7-5776-461f-5a9d-08dc41b9e8e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kbHkxL+Ball9Wc0on3/E3qCTEBMmb5yqtaEblozYb1nG7HSljW2y7M/MCmbWKPXlShstMENzoaZIA23DzMn448ynPQtzxcEKbdZZzry1i4wIjQXqQVdvQpX8NQ/nUqPyQrszaJidFqDZKwRJTmuLLZHbmzfJp2hZsI+Ad+i2HHyCk2j1mdCV4TKNzZp1CaK/oRiHnoqTDHDbZDvj4CYFP4Emz0KHb2jtfjcG/kABZ7kivICdv/NR9yP9k+rjBAnvSDSOA0xE79A0aeAtJWBR3ZkFabKbWQHstOFMn++f82dsLS5+5PnNKa9MPxppDBRC7BiIxy6XMADXQWmxAMK1XwNoafDtXpfvEIfuv4d0WePh+SU2BI+NjyCisVip6lVAzuNMUaWCOLPLdoXGJ2vq+dhNlTcVClr/ly6AdE/8ANzbe1lOCwUI717I0w49P3P+rLR+A07K7ST2IrfaxSSvXySsYcxkhfeEZfVPIsEsF7kDKPh12Yayuo8E2sNmQn9W9QUymbgfokIonVEJyUk+UhRZXsbyzrYx04slgRitP8sxf9zDIv1Uc20+YTWsMNkjFYBbHKrmTHyht1qcGxd20UaFdAA+RnQMPIgqzv0O3Id/pKefCi/1vj5Kv+rN29vZU873WU2cl3DNph856/o0o2BoP2Y+PZAzmU00ehKim4OExAeEsibYDgTWhSmhtg8mZ9h3iGgfplRbLjbhnu272YtOKWPh//JYc/x7ipqR15Y= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SE1P216MB1303.KORP216.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(52116005)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ga10kyAOV3xrE/ULiM3NUZ+gpZtq9d7uI72lIqBxD+MOGWdkafClGIUoqu0S8cHmYlxICjpEx9I90SqTwTSqt4MBWPoBiZOBD25ozl/idWZ5yOKs8RnUIYHbzOL0guKbeU+lafbtYAFBvb5N6MdtzDL74Og4dzawTKhTkhJXgaBVNH3k5J6BAu7khyCNlkAZrysEzmMhasgIOlTQ7Dnom45f6sVTvbqUbsmXn2R2BWMWXbXaG6qLzzsrSJ0coEhZI0fyzApYnlYfb8a1EJ+94aXhs5/NFu7AYixG8pcWTxyX8gDUly9Cs0JPYz48J1YvuA1Dj5wFIZcw22b8Em3rtqNw/pWezHpCJuOBp5xbCqtTD1M3xdx9akjcrD4pryM2zPt3X/c46zsxHkcKraHKg9IEmK9RvBbmE7Jduvz8MMCmOm4Z310J32/JSyUJrcaIY4054hn6OkIACtmWY07sjmj8Ow29Yxz6l/WedRtGjzECbKtJCp7ZZnk0gLfFF+UaL8oncS8qp6ctiRQtkHocunpEsmo5QKFa9kOlOSeIkAOqNcET/+rEevThrn/UMxLurz5UD5jEGLMAyHCa8OTow84/LYKVsx9uWBeDzpnWlldFQVG08Ikt5G2u2cZ+Povu3zVAilOaXdVUfKggszgXcj0/2qQLDcrdEfBJQMGjnymjXAqUswxLhZv9rm2AvGozml3zH9T8mJhsSOqX7H6E03shpjUOpYyVKeRs9y24D3ZH3y9CwsueaVGY2xDLPJM6jm36uQPkSSTjnsbJ6hDaVNU/8Uf1l4OW6GN5RCbFmQyZdht8SF+k88RoIg2ysajnpyy8hu53jzM0sQBQnlANxzXT0/11fSXwI5LxVUirl8HyyU5qx/UiMNKw1OWnOsNsGopecG35F3ZqPNRqrHa5CiitP1xenDemJ89L/34a48EsPBXV6vtg0bJzy4VfDyjQfIKCDNEZyxXhqiUkh+fwJey2GljgCeboO6pVpOpXm6p7Q0xyPyM9hc3nZFAs/qqjdh/hBHjMkYz1uo5qoOVYNEY7fmHOBUIvopdVfMbyW+yMOSGvJXAO3fFfnc4ACkNe5u7HZasL9rGJLL7ktxIEQ3aHxR+yOIv74L20tHA86aJv53sWLX91HY50vpQgss0aPRtD618zD0LSW2b/+MFsTv3e55/i3KtR5NebRw0pX5ZfsatTQpto8jxLS59zp2rVmJHRClGilDHclfNoEItU/eosYQhQ2RvBQLgsREsoTAyTw9axKAAQZNgS0zToj9XnWYs2lcLQa51m9J/wEtJ6WMwImSzh5gRAhWdEIT/qj4K2h9TY40/q1oq56bkb5YL3hDWxGZArrnrY4tmqxcvLpUVKt9aJ+u+JLp6+iwl5B1Hbf600Rs9M2B8Wkb06OdJ744BrR00stdhTersF1Tai1GS0Hok1fPAtagYNdcBY+SGYBRg75pyjTqxTgH2wkwrxYcfxNEYtHFve9oW0UQKkLKpCjAp6mu6+6M1N2sIw72dvI9izGMn6lPwVdWL5k645/lZauUw6ZirKkr4aza4x2zItdKybNvA92S4OPyQWvnQR+GFpW6FA/0NwDHgOBfklWmOtaUMKwOyuMz1dZiOkeAGKz7cNhuVupGBjdiG8EHY= X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cbdb33b7-5776-461f-5a9d-08dc41b9e8e3 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 10:56:31.3134 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4d70c8e9-142b-4389-b7f2-fa8a3c68c467 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: L3jQUapOAUixCWJWyHYC75K3tA3JhHU0j+/kGcloXYWQPmD83abRgr9gZQY7NKHup+ZC3u8Ta96Y2pj5pXI10CANUhuZaTtKvqGxuTIPdvI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE1P216MB2024 From: "Jackson.lee" Use v4l2-common helper functions to calculate bytesperline and sizeimage, instead of calculating in a wave5 driver directly. In case of raw(YUV) v4l2_pix_format, the wave5 driver updates v4l2_pix_format_mplane struct through v4l2_fill_pixfmt_mp() function. Encoder and Decoder need same bytesperline and sizeimage values for same v4l2_pix_format. So, a wave5_update_pix_fmt is refactored to support both together. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung --- .../platform/chips-media/wave5/wave5-helper.c | 24 ++ .../platform/chips-media/wave5/wave5-helper.h | 4 + .../chips-media/wave5/wave5-vpu-dec.c | 245 ++++-------------- .../chips-media/wave5/wave5-vpu-enc.c | 179 +++++-------- .../platform/chips-media/wave5/wave5-vpu.h | 4 - .../chips-media/wave5/wave5-vpuconfig.h | 25 +- 6 files changed, 164 insertions(+), 317 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-helper.c b/drivers/media/platform/chips-media/wave5/wave5-helper.c index 8433ecab230c..53cad4d17aa7 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-helper.c +++ b/drivers/media/platform/chips-media/wave5/wave5-helper.c @@ -7,6 +7,8 @@ #include "wave5-helper.h" +#define DEFAULT_BS_SIZE(width, height) ((width) * (height) / 8 * 3) + const char *state_to_str(enum vpu_instance_state state) { switch (state) { @@ -211,3 +213,25 @@ void wave5_return_bufs(struct vb2_queue *q, u32 state) v4l2_m2m_buf_done(vbuf, state); } } + +void wave5_update_pix_fmt(struct v4l2_pix_format_mplane *pix_mp, + unsigned int width, + unsigned int height, + const struct v4l2_frmsize_stepwise frmsize) +{ + v4l2_apply_frmsize_constraints(&width, &height, &frmsize); + + if (pix_mp->pixelformat == V4L2_PIX_FMT_HEVC || + pix_mp->pixelformat == V4L2_PIX_FMT_H264) { + pix_mp->width = width; + pix_mp->height = height; + pix_mp->num_planes = 1; + pix_mp->plane_fmt[0].bytesperline = 0; + pix_mp->plane_fmt[0].sizeimage = max(DEFAULT_BS_SIZE(width, height), + pix_mp->plane_fmt[0].sizeimage); + } else { + v4l2_fill_pixfmt_mp(pix_mp, pix_mp->pixelformat, width, height); + } + pix_mp->flags = 0; + pix_mp->field = V4L2_FIELD_NONE; +} diff --git a/drivers/media/platform/chips-media/wave5/wave5-helper.h b/drivers/media/platform/chips-media/wave5/wave5-helper.h index 6cee1c14d3ce..a8ecd1920207 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-helper.h +++ b/drivers/media/platform/chips-media/wave5/wave5-helper.h @@ -28,4 +28,8 @@ const struct vpu_format *wave5_find_vpu_fmt_by_idx(unsigned int idx, const struct vpu_format fmt_list[MAX_FMTS]); enum wave_std wave5_to_vpu_std(unsigned int v4l2_pix_fmt, enum vpu_instance_type type); void wave5_return_bufs(struct vb2_queue *q, u32 state); +void wave5_update_pix_fmt(struct v4l2_pix_format_mplane *pix_mp, + unsigned int width, + unsigned int height, + const struct v4l2_frmsize_stepwise frmsize); #endif diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c index a199877c643b..43d0a21193dd 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c @@ -11,115 +11,74 @@ #define VPU_DEC_DEV_NAME "C&M Wave5 VPU decoder" #define VPU_DEC_DRV_NAME "wave5-dec" -#define DEFAULT_SRC_SIZE(width, height) ({ \ - (width) * (height) / 8 * 3; \ -}) - static const struct vpu_format dec_fmt_list[FMT_TYPES][MAX_FMTS] = { [VPU_FMT_TYPE_CODEC] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_HEVC, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_H264, - .max_width = 8192, - .min_width = 32, - .max_height = 4320, - .min_height = 32, }, }, [VPU_FMT_TYPE_RAW] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422P, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV16, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV61, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV16M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV61M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, }, } }; +static const struct v4l2_frmsize_stepwise dec_frmsize[FMT_TYPES] = { + [VPU_FMT_TYPE_CODEC] = { + .min_width = W5_MIN_DEC_PIC_WIDTH, + .max_width = W5_MAX_DEC_PIC_WIDTH, + .step_width = W5_DEC_CODEC_STEP_WIDTH, + .min_height = W5_MIN_DEC_PIC_HEIGHT, + .max_height = W5_MAX_DEC_PIC_HEIGHT, + .step_height = W5_DEC_CODEC_STEP_HEIGHT, + }, + [VPU_FMT_TYPE_RAW] = { + .min_width = W5_MIN_DEC_PIC_WIDTH, + .max_width = W5_MAX_DEC_PIC_WIDTH, + .step_width = W5_DEC_RAW_STEP_WIDTH, + .min_height = W5_MIN_DEC_PIC_HEIGHT, + .max_height = W5_MAX_DEC_PIC_HEIGHT, + .step_height = W5_DEC_RAW_STEP_HEIGHT, + }, +}; + /* * Make sure that the state switch is allowed and add logging for debugging * purposes @@ -234,74 +193,6 @@ static void wave5_handle_src_buffer(struct vpu_instance *inst, dma_addr_t rd_ptr inst->remaining_consumed_bytes = consumed_bytes; } -static void wave5_update_pix_fmt(struct v4l2_pix_format_mplane *pix_mp, unsigned int width, - unsigned int height) -{ - switch (pix_mp->pixelformat) { - case V4L2_PIX_FMT_YUV420: - case V4L2_PIX_FMT_NV12: - case V4L2_PIX_FMT_NV21: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height * 3 / 2; - break; - case V4L2_PIX_FMT_YUV422P: - case V4L2_PIX_FMT_NV16: - case V4L2_PIX_FMT_NV61: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height * 2; - break; - case V4L2_PIX_FMT_YUV420M: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[1].sizeimage = width * height / 4; - pix_mp->plane_fmt[2].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[2].sizeimage = width * height / 4; - break; - case V4L2_PIX_FMT_NV12M: - case V4L2_PIX_FMT_NV21M: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[1].sizeimage = width * height / 2; - break; - case V4L2_PIX_FMT_YUV422M: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[1].sizeimage = width * height / 2; - pix_mp->plane_fmt[2].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[2].sizeimage = width * height / 2; - break; - case V4L2_PIX_FMT_NV16M: - case V4L2_PIX_FMT_NV61M: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[1].sizeimage = width * height; - break; - default: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = 0; - pix_mp->plane_fmt[0].sizeimage = max(DEFAULT_SRC_SIZE(width, height), - pix_mp->plane_fmt[0].sizeimage); - break; - } -} - static int start_decode(struct vpu_instance *inst, u32 *fail_res) { struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; @@ -397,9 +288,11 @@ static int handle_dynamic_resolution_change(struct vpu_instance *inst) initial_info->pic_crop_rect.top - initial_info->pic_crop_rect.bottom; wave5_update_pix_fmt(&inst->src_fmt, initial_info->pic_width, - initial_info->pic_height); + initial_info->pic_height, + dec_frmsize[VPU_FMT_TYPE_CODEC]); wave5_update_pix_fmt(&inst->dst_fmt, initial_info->pic_width, - initial_info->pic_height); + initial_info->pic_height, + dec_frmsize[VPU_FMT_TYPE_RAW]); } v4l2_event_queue_fh(fh, &vpu_event_src_ch); @@ -548,12 +441,7 @@ static int wave5_vpu_dec_enum_framesizes(struct file *f, void *fh, struct v4l2_f } fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; - fsize->stepwise.min_width = vpu_fmt->min_width; - fsize->stepwise.max_width = vpu_fmt->max_width; - fsize->stepwise.step_width = 1; - fsize->stepwise.min_height = vpu_fmt->min_height; - fsize->stepwise.max_height = vpu_fmt->max_height; - fsize->stepwise.step_height = 1; + fsize->stepwise = dec_frmsize[VPU_FMT_TYPE_CODEC]; return 0; } @@ -589,14 +477,10 @@ static int wave5_vpu_dec_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo width = inst->dst_fmt.width; height = inst->dst_fmt.height; f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; } else { - const struct v4l2_format_info *info = v4l2_format_info(vpu_fmt->v4l2_pix_fmt); - - width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = info->mem_planes; } if (p_dec_info->initial_info_obtained) { @@ -604,9 +488,9 @@ static int wave5_vpu_dec_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo height = inst->dst_fmt.height; } - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, width, + height, + dec_frmsize[VPU_FMT_TYPE_RAW]); f->fmt.pix_mp.colorspace = inst->colorspace; f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; f->fmt.pix_mp.quantization = inst->quantization; @@ -719,6 +603,7 @@ static int wave5_vpu_dec_try_fmt_out(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + int width, height; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u colorspace: %u field: %u\n", @@ -727,20 +612,18 @@ static int wave5_vpu_dec_try_fmt_out(struct file *file, void *fh, struct v4l2_fo vpu_fmt = wave5_find_vpu_fmt(f->fmt.pix_mp.pixelformat, dec_fmt_list[VPU_FMT_TYPE_CODEC]); if (!vpu_fmt) { + width = inst->src_fmt.width; + height = inst->src_fmt.height; f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, inst->src_fmt.width, inst->src_fmt.height); } else { - int width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - int height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); - + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = 1; - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, width, + height, + dec_frmsize[VPU_FMT_TYPE_CODEC]); return 0; } @@ -782,7 +665,9 @@ static int wave5_vpu_dec_s_fmt_out(struct file *file, void *fh, struct v4l2_form inst->quantization = f->fmt.pix_mp.quantization; inst->xfer_func = f->fmt.pix_mp.xfer_func; - wave5_update_pix_fmt(&inst->dst_fmt, f->fmt.pix_mp.width, f->fmt.pix_mp.height); + wave5_update_pix_fmt(&inst->dst_fmt, f->fmt.pix_mp.width, + f->fmt.pix_mp.height, + dec_frmsize[VPU_FMT_TYPE_RAW]); return 0; } @@ -1005,6 +890,7 @@ static int wave5_vpu_dec_queue_setup(struct vb2_queue *q, unsigned int *num_buff struct vpu_instance *inst = vb2_get_drv_priv(q); struct v4l2_pix_format_mplane inst_format = (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) ? inst->src_fmt : inst->dst_fmt; + unsigned int i; dev_dbg(inst->dev->dev, "%s: num_buffers: %u | num_planes: %u | type: %u\n", __func__, *num_buffers, *num_planes, q->type); @@ -1018,31 +904,9 @@ static int wave5_vpu_dec_queue_setup(struct vb2_queue *q, unsigned int *num_buff if (*num_buffers < inst->fbc_buf_count) *num_buffers = inst->fbc_buf_count; - if (*num_planes == 1) { - if (inst->output_format == FORMAT_422) - sizes[0] = inst_format.width * inst_format.height * 2; - else - sizes[0] = inst_format.width * inst_format.height * 3 / 2; - dev_dbg(inst->dev->dev, "%s: size[0]: %u\n", __func__, sizes[0]); - } else if (*num_planes == 2) { - sizes[0] = inst_format.width * inst_format.height; - if (inst->output_format == FORMAT_422) - sizes[1] = inst_format.width * inst_format.height; - else - sizes[1] = inst_format.width * inst_format.height / 2; - dev_dbg(inst->dev->dev, "%s: size[0]: %u | size[1]: %u\n", - __func__, sizes[0], sizes[1]); - } else if (*num_planes == 3) { - sizes[0] = inst_format.width * inst_format.height; - if (inst->output_format == FORMAT_422) { - sizes[1] = inst_format.width * inst_format.height / 2; - sizes[2] = inst_format.width * inst_format.height / 2; - } else { - sizes[1] = inst_format.width * inst_format.height / 4; - sizes[2] = inst_format.width * inst_format.height / 4; - } - dev_dbg(inst->dev->dev, "%s: size[0]: %u | size[1]: %u | size[2]: %u\n", - __func__, sizes[0], sizes[1], sizes[2]); + for (i = 0; i < *num_planes; i++) { + sizes[i] = inst_format.plane_fmt[i].sizeimage; + dev_dbg(inst->dev->dev, "%s: size[%u]: %u\n", __func__, i, sizes[i]); } } @@ -1564,20 +1428,15 @@ static const struct vb2_ops wave5_vpu_dec_vb2_ops = { static void wave5_set_default_format(struct v4l2_pix_format_mplane *src_fmt, struct v4l2_pix_format_mplane *dst_fmt) { - unsigned int dst_pix_fmt = dec_fmt_list[VPU_FMT_TYPE_RAW][0].v4l2_pix_fmt; - const struct v4l2_format_info *dst_fmt_info = v4l2_format_info(dst_pix_fmt); - src_fmt->pixelformat = dec_fmt_list[VPU_FMT_TYPE_CODEC][0].v4l2_pix_fmt; - src_fmt->field = V4L2_FIELD_NONE; - src_fmt->flags = 0; - src_fmt->num_planes = 1; - wave5_update_pix_fmt(src_fmt, 720, 480); - - dst_fmt->pixelformat = dst_pix_fmt; - dst_fmt->field = V4L2_FIELD_NONE; - dst_fmt->flags = 0; - dst_fmt->num_planes = dst_fmt_info->mem_planes; - wave5_update_pix_fmt(dst_fmt, 736, 480); + wave5_update_pix_fmt(src_fmt, W5_DEF_DEC_PIC_WIDTH, + W5_DEF_DEC_PIC_HEIGHT, + dec_frmsize[VPU_FMT_TYPE_CODEC]); + + dst_fmt->pixelformat = dec_fmt_list[VPU_FMT_TYPE_RAW][0].v4l2_pix_fmt; + wave5_update_pix_fmt(dst_fmt, W5_DEF_DEC_PIC_WIDTH, + W5_DEF_DEC_PIC_HEIGHT, + dec_frmsize[VPU_FMT_TYPE_RAW]); } static int wave5_vpu_dec_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index 013e2bb37fbb..5a32bb138158 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -15,65 +15,52 @@ static const struct vpu_format enc_fmt_list[FMT_TYPES][MAX_FMTS] = { [VPU_FMT_TYPE_CODEC] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_HEVC, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_H264, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, }, }, [VPU_FMT_TYPE_RAW] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420M, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12M, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, }, } }; +static const struct v4l2_frmsize_stepwise enc_frmsize[FMT_TYPES] = { + [VPU_FMT_TYPE_CODEC] = { + .min_width = W5_MIN_ENC_PIC_WIDTH, + .max_width = W5_MAX_ENC_PIC_WIDTH, + .step_width = W5_ENC_CODEC_STEP_WIDTH, + .min_height = W5_MIN_ENC_PIC_HEIGHT, + .max_height = W5_MAX_ENC_PIC_HEIGHT, + .step_height = W5_ENC_CODEC_STEP_HEIGHT, + }, + [VPU_FMT_TYPE_RAW] = { + .min_width = W5_MIN_ENC_PIC_WIDTH, + .max_width = W5_MAX_ENC_PIC_WIDTH, + .step_width = W5_ENC_RAW_STEP_WIDTH, + .min_height = W5_MIN_ENC_PIC_HEIGHT, + .max_height = W5_MAX_ENC_PIC_HEIGHT, + .step_height = W5_ENC_RAW_STEP_HEIGHT, + }, +}; + static int switch_state(struct vpu_instance *inst, enum vpu_instance_state state) { switch (state) { @@ -106,46 +93,6 @@ static int switch_state(struct vpu_instance *inst, enum vpu_instance_state state return -EINVAL; } -static void wave5_update_pix_fmt(struct v4l2_pix_format_mplane *pix_mp, unsigned int width, - unsigned int height) -{ - switch (pix_mp->pixelformat) { - case V4L2_PIX_FMT_YUV420: - case V4L2_PIX_FMT_NV12: - case V4L2_PIX_FMT_NV21: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = round_up(width, 32) * height * 3 / 2; - break; - case V4L2_PIX_FMT_YUV420M: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = round_up(width, 32) * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[1].sizeimage = round_up(width, 32) * height / 4; - pix_mp->plane_fmt[2].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[2].sizeimage = round_up(width, 32) * height / 4; - break; - case V4L2_PIX_FMT_NV12M: - case V4L2_PIX_FMT_NV21M: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = round_up(width, 32) * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[1].sizeimage = round_up(width, 32) * height / 2; - break; - default: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = 0; - pix_mp->plane_fmt[0].sizeimage = width * height / 8 * 3; - break; - } -} - static int start_encode(struct vpu_instance *inst, u32 *fail_res) { struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; @@ -360,13 +307,8 @@ static int wave5_vpu_enc_enum_framesizes(struct file *f, void *fh, struct v4l2_f return -EINVAL; } - fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; - fsize->stepwise.min_width = vpu_fmt->min_width; - fsize->stepwise.max_width = vpu_fmt->max_width; - fsize->stepwise.step_width = 1; - fsize->stepwise.min_height = vpu_fmt->min_height; - fsize->stepwise.max_height = vpu_fmt->max_height; - fsize->stepwise.step_height = 1; + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; + fsize->stepwise = enc_frmsize[VPU_FMT_TYPE_CODEC]; return 0; } @@ -392,6 +334,7 @@ static int wave5_vpu_enc_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + int width, height; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, @@ -399,20 +342,18 @@ static int wave5_vpu_enc_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo vpu_fmt = wave5_find_vpu_fmt(f->fmt.pix_mp.pixelformat, enc_fmt_list[VPU_FMT_TYPE_CODEC]); if (!vpu_fmt) { + width = inst->dst_fmt.width; + height = inst->dst_fmt.height; f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, inst->dst_fmt.width, inst->dst_fmt.height); } else { - int width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - int height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); - + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = 1; - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, width, + height, + enc_frmsize[VPU_FMT_TYPE_CODEC]); f->fmt.pix_mp.colorspace = inst->colorspace; f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; f->fmt.pix_mp.quantization = inst->quantization; @@ -500,6 +441,7 @@ static int wave5_vpu_enc_try_fmt_out(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + int width, height; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, @@ -507,21 +449,18 @@ static int wave5_vpu_enc_try_fmt_out(struct file *file, void *fh, struct v4l2_fo vpu_fmt = wave5_find_vpu_fmt(f->fmt.pix_mp.pixelformat, enc_fmt_list[VPU_FMT_TYPE_RAW]); if (!vpu_fmt) { + width = inst->src_fmt.width; + height = inst->src_fmt.height; f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, inst->src_fmt.width, inst->src_fmt.height); } else { - int width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - int height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); - const struct v4l2_format_info *info = v4l2_format_info(vpu_fmt->v4l2_pix_fmt); - + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = info->mem_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, width, + height, + enc_frmsize[VPU_FMT_TYPE_RAW]); return 0; } @@ -568,7 +507,11 @@ static int wave5_vpu_enc_s_fmt_out(struct file *file, void *fh, struct v4l2_form inst->quantization = f->fmt.pix_mp.quantization; inst->xfer_func = f->fmt.pix_mp.xfer_func; - wave5_update_pix_fmt(&inst->dst_fmt, f->fmt.pix_mp.width, f->fmt.pix_mp.height); + wave5_update_pix_fmt(&inst->dst_fmt, f->fmt.pix_mp.width, + f->fmt.pix_mp.height, + enc_frmsize[VPU_FMT_TYPE_CODEC]); + inst->conf_win.width = inst->dst_fmt.width; + inst->conf_win.height = inst->dst_fmt.height; return 0; } @@ -584,12 +527,17 @@ static int wave5_vpu_enc_g_selection(struct file *file, void *fh, struct v4l2_se switch (s->target) { case V4L2_SEL_TGT_CROP_DEFAULT: case V4L2_SEL_TGT_CROP_BOUNDS: - case V4L2_SEL_TGT_CROP: s->r.left = 0; s->r.top = 0; s->r.width = inst->dst_fmt.width; s->r.height = inst->dst_fmt.height; break; + case V4L2_SEL_TGT_CROP: + s->r.left = 0; + s->r.top = 0; + s->r.width = inst->conf_win.width; + s->r.height = inst->conf_win.height; + break; default: return -EINVAL; } @@ -612,8 +560,10 @@ static int wave5_vpu_enc_s_selection(struct file *file, void *fh, struct v4l2_se s->r.left = 0; s->r.top = 0; - s->r.width = inst->src_fmt.width; - s->r.height = inst->src_fmt.height; + s->r.width = min(s->r.width, inst->dst_fmt.width); + s->r.height = min(s->r.height, inst->dst_fmt.height); + + inst->conf_win = s->r; return 0; } @@ -1151,8 +1101,8 @@ static void wave5_set_enc_openparam(struct enc_open_param *open_param, open_param->wave_param.lambda_scaling_enable = 1; open_param->line_buf_int_en = true; - open_param->pic_width = inst->dst_fmt.width; - open_param->pic_height = inst->dst_fmt.height; + open_param->pic_width = inst->conf_win.width; + open_param->pic_height = inst->conf_win.height; open_param->frame_rate_info = inst->frame_rate; open_param->rc_enable = inst->rc_enable; if (inst->rc_enable) { @@ -1456,20 +1406,15 @@ static const struct vb2_ops wave5_vpu_enc_vb2_ops = { static void wave5_set_default_format(struct v4l2_pix_format_mplane *src_fmt, struct v4l2_pix_format_mplane *dst_fmt) { - unsigned int src_pix_fmt = enc_fmt_list[VPU_FMT_TYPE_RAW][0].v4l2_pix_fmt; - const struct v4l2_format_info *src_fmt_info = v4l2_format_info(src_pix_fmt); - - src_fmt->pixelformat = src_pix_fmt; - src_fmt->field = V4L2_FIELD_NONE; - src_fmt->flags = 0; - src_fmt->num_planes = src_fmt_info->mem_planes; - wave5_update_pix_fmt(src_fmt, 416, 240); + src_fmt->pixelformat = enc_fmt_list[VPU_FMT_TYPE_RAW][0].v4l2_pix_fmt; + wave5_update_pix_fmt(src_fmt, W5_DEF_ENC_PIC_WIDTH, + W5_DEF_ENC_PIC_HEIGHT, + enc_frmsize[VPU_FMT_TYPE_RAW]); dst_fmt->pixelformat = enc_fmt_list[VPU_FMT_TYPE_CODEC][0].v4l2_pix_fmt; - dst_fmt->field = V4L2_FIELD_NONE; - dst_fmt->flags = 0; - dst_fmt->num_planes = 1; - wave5_update_pix_fmt(dst_fmt, 416, 240); + wave5_update_pix_fmt(dst_fmt, W5_DEF_ENC_PIC_WIDTH, + W5_DEF_ENC_PIC_HEIGHT, + enc_frmsize[VPU_FMT_TYPE_CODEC]); } static int wave5_vpu_enc_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) @@ -1734,6 +1679,8 @@ static int wave5_vpu_open_enc(struct file *filp) v4l2_ctrl_handler_setup(v4l2_ctrl_hdl); wave5_set_default_format(&inst->src_fmt, &inst->dst_fmt); + inst->conf_win.width = inst->dst_fmt.width; + inst->conf_win.height = inst->dst_fmt.height; inst->colorspace = V4L2_COLORSPACE_REC709; inst->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; inst->quantization = V4L2_QUANTIZATION_DEFAULT; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.h b/drivers/media/platform/chips-media/wave5/wave5-vpu.h index 32b7fd3730b5..691d6341fcda 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.h @@ -38,10 +38,6 @@ enum vpu_fmt_type { struct vpu_format { unsigned int v4l2_pix_fmt; - unsigned int max_width; - unsigned int min_width; - unsigned int max_height; - unsigned int min_height; }; static inline struct vpu_instance *wave5_to_vpu_inst(struct v4l2_fh *vfh) diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h b/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h index d9751eedb0f9..e6a34ae7084e 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h @@ -30,10 +30,27 @@ #define MAX_NUM_INSTANCE 32 -#define W5_MIN_ENC_PIC_WIDTH 256 -#define W5_MIN_ENC_PIC_HEIGHT 128 -#define W5_MAX_ENC_PIC_WIDTH 8192 -#define W5_MAX_ENC_PIC_HEIGHT 8192 +#define W5_DEF_DEC_PIC_WIDTH 720U +#define W5_DEF_DEC_PIC_HEIGHT 480U +#define W5_MIN_DEC_PIC_WIDTH 32U +#define W5_MIN_DEC_PIC_HEIGHT 32U +#define W5_MAX_DEC_PIC_WIDTH 8192U +#define W5_MAX_DEC_PIC_HEIGHT 4320U +#define W5_DEC_CODEC_STEP_WIDTH 1U +#define W5_DEC_CODEC_STEP_HEIGHT 1U +#define W5_DEC_RAW_STEP_WIDTH 32U +#define W5_DEC_RAW_STEP_HEIGHT 16U + +#define W5_DEF_ENC_PIC_WIDTH 416U +#define W5_DEF_ENC_PIC_HEIGHT 240U +#define W5_MIN_ENC_PIC_WIDTH 256U +#define W5_MIN_ENC_PIC_HEIGHT 128U +#define W5_MAX_ENC_PIC_WIDTH 8192U +#define W5_MAX_ENC_PIC_HEIGHT 8192U +#define W5_ENC_CODEC_STEP_WIDTH 8U +#define W5_ENC_CODEC_STEP_HEIGHT 8U +#define W5_ENC_RAW_STEP_WIDTH 32U +#define W5_ENC_RAW_STEP_HEIGHT 16U // application specific configuration #define VPU_ENC_TIMEOUT 60000 From patchwork Mon Mar 11 10:56:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13588587 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11020002.outbound.protection.outlook.com [52.101.154.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 281F03A8C1; Mon, 11 Mar 2024 10:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710154603; cv=fail; b=IowkZcqgXhjiMTPA02u/owE7lGRPN2ff7QOFay21yhDqGwmcdLjtbB64CL7tZ8DDL6zuIgNedsWiW055Xda/fd3ZEVGkIeknNdmoMDZKlUuUUB3Xuw7nqJnBWsYu0UxpCHPqVUjfDiuZy1QOb7y/RQfM6fzoRAQ0SWdlP3gofYY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710154603; c=relaxed/simple; bh=yxNFp988MN/rGSkeStJyaW4sORGym2mKJNvRu9JwxrI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=m8EFmqlE8NY9w12GcP4Vl9HjCWW1EaMDMH3vxhfAASO6vxT+zX6MBgb3DjH/uPmqrasKQXfFUpIVvMBQkBmMgrSzRV+GOwRnag+x3+me62Eg9h2OMdlWxUoddqNyeb7/0e9AkGGowR+4HMso1lbZf1XRPLg7ygoSVbKNXBjjdN4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com; spf=pass smtp.mailfrom=chipsnmedia.com; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b=Bgs78w2T; arc=fail smtp.client-ip=52.101.154.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="Bgs78w2T" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O/imnr/Xm2GlbLAdKDkTPEMZoPQqCTrZZtzYZb/A6Tc+7hoOYu8DSC0UEtCmRxmxseM72bj3XnbnPxzWerI2O/91A4e8u5rvf/+ePJPQ10HPWcxjCSEQtIigYLIUnFs869Z/iNoeaqdz/R0xH9dkQa8YFeW2FOaEj4B98j4qaRVLlgoB+Z3MfYO8zDz2slnNbBEESJLUOjmvQEy4vz1k7rf+SNZP6l/AX8kLx2+r8uayIqxBu330FtDxpSSWumd4XsoocZuGa1XPXzBgcQlFGTCcwHxNmGmK71sg4pVHMjrezACKa0z7/Twfdbu5TXYZtPjegcNakW7EK9LbQVLwVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=5AOc2QOAt3qo30Tc77Pm7XC3tlB9nOy+F4lkE4s5kPw=; b=MHCUCkkRa4xrwqaWKqQiQFQLb5SOU/fugASXXk5r5EeInUaBkJbO1qlHoVfW1qbDpqk6WI3YsXKUMpK3dxvsPtq9LLVEf1CYI8LjyKvL6w/wxOiF67qDRvkTQu8nEFkvEx2bTWnyt5Psk6NfLlv2VbwCkje1huzxSo5zMiaRxezxMqOBDrDF4zXtfLuPcb4P4WQfcxFBmq+Svyh32RUmcHYXRLi9RX5VKAlKGvJYDie5EMsDoBJp+HiefKPhwMlF0vs+0nWdoYkZi4P5Aku70Bz5mN+mmMGYc+doysdVTpf4t6CEX02SMoaJ6hcCHoW92yzjEfDZGHh5UQ8/ep8ptQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=chipsnmedia.com; dmarc=pass action=none header.from=chipsnmedia.com; dkim=pass header.d=chipsnmedia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chipsnmedia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5AOc2QOAt3qo30Tc77Pm7XC3tlB9nOy+F4lkE4s5kPw=; b=Bgs78w2T57uhjhAPug3MkqG4hmaZgNjjEJn2SWusmY3LNBCUEtkJ0JN0W2D94hopegDua8d+dqq8W4YSswZQP2Her+VCIVBDnlKl5db9KtXEisoQJe0Z94Kvduh6QIp6q3YjBJVMNJnTlgLT04GHYOLQt8XWfYThSlFoPfJf2cg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=chipsnmedia.com; Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) by SE1P216MB2024.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Mon, 11 Mar 2024 10:56:31 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::ebb8:2043:fd53:303a]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::ebb8:2043:fd53:303a%3]) with mapi id 15.20.7362.035; Mon, 11 Mar 2024 10:56:31 +0000 From: "jackson.lee" To: mchehab@kernel.org, nicolas@ndufresne.ca, sebastian.fricke@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, hverkuil@xs4all.nl, nas.chung@chipsnmedia.com, lafley.kim@chipsnmedia.com, b-brnich@ti.com, "Jackson.lee" Subject: [RESEND PATCH v2 4/4] media: chips-media: wave5: Support YUV422 raw pixel-formats on the encoder. Date: Mon, 11 Mar 2024 19:56:23 +0900 Message-Id: <20240311105623.20406-5-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240311105623.20406-1-jackson.lee@chipsnmedia.com> References: <20240311105623.20406-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0127.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1::6) To SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SE1P216MB1303:EE_|SE1P216MB2024:EE_ X-MS-Office365-Filtering-Correlation-Id: da2880e9-1ddb-458b-e225-08dc41b9e90d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G1L5LpWatu5C9xrfDaMTvWoaw3WxmYp/x7XkbLFJJErni/KXKuEBwnL9zBF0drzJqggD6IJexvGqW3BDLqNaAgOGCMIhweyoyqeplJqLh2Yf4PqfzHY7sv4o7GV7a+ZNBuGftEnGgzpUJT39+CY4Cub1BJ0wTxyuf8YTpDJV9uBm50XE+v4oyeLYdtRfDiacNLEXrB3qoDrd+wD1jISnGSft+w7dWKNib6T3TdWkvACHK00h85THSwrXVig949Epk0Zn+zFMQxdNV8J0ztfdxbSMIHpOwkEBS23YGt+nVJPdcV0Bf9Iezqql/7xLXLSywrTvlDHOnE/ElIvECi8ZbcYFXT4+gHzKpVHO4HZfloNQ1iZaRPP4IVF1hQ82u4BNi1HJY20KZfZrna627sxXynOuJdjvMNjTleSGtRPS9p/2ytMk7OHrcQhRo0iqd6Iyg04xs3PRulRX6yrhY9Kwo0kq8yE/47Rvsj6/dwZPvuKcWRmDtP097V/eErLE4jVbTgk9OAk6+BTCLT62dgMHugoJ6hch1I9xLVTYeqVmQ08tKbXJ1LUMUiwa39JTg8yL29Ggxwwa4q+ROSJ7ht72h5J38x+6/3Si+gwj5p5WBkZeM8NxS56CNC0Jd6HjwRsHpWsAFd7ljfF417AXtP5hUrQIsvfd3XMIEItpCf38QyZyOXAsqKzHYNyrSwlTcPK4khyD2z/JTiQ1vIXUckYWCe2ymR95L1NiG6IaINg/3Z8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SE1P216MB1303.KORP216.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(52116005)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NxP+NFzny3H6BRWGp7EQ97yhu1GDNXoy+LcAbgZDUxtMUhxD39v3TQypV/7NKxrnEpNpVCtw8HOaqc0/dhY4NEVj3x9u85RBp99tLkS09amKhUhLNxxDMHIsdPkw2U4AthEeCDiNQGjAEqNoE0sDKzCuQjXMhSVrBRaR54h8FAXYVI3fA13WFL4ZnmnUQQH0wB0oe1pdt/4uar6hVMaGo2nDdtkRk09LcgdE7xEI45fkQ+1kZEcnCsA60S0RamCNsGTsL0RtVLsCgmjq03YM/zzpYoTQFfGVDSIv6MP2sbjsNGucyjXoCWavZ92lGMFy7f0ka0U0kn8SqxxoKbHLzI+FCxqA+l4z1OxtC5fR/U+ILRtJP2Osx+d59dVwgkdO8ni+V/v4L1Yn01upCBQqYNoeKzMgeGpTQzomkw8pG1342jvnh2mEHDzVQm745DGfKkHcvOYNbC7uaIuRYkFaqgK95jJHWe5iGNzaPDY8xyuVL9zBYwNJrlR1RMKQ3H/K7PpbVMH8C0pQWNpVPw3NY2rbGNnVV4KHdeQeEwo7HnR6mYY8dWmKHFj2zpvmrtk+yC8G9TaMSesNZr7stu0fR7hN2evG+Np1zZpligrCU+vvb4ruOK4RY3xTIcDdktkOB78jmQE66CTscRAG3J8yCiFRWQYgB0XgF0/MOWmr0RxpTi08bEuiLfJLNqfQDzF6dbIVIj6gR78KlMJD3DKGANwMZXDl0zWuSiXb10l7/qUX+EoI4NLWbWYvnQVzYi1gvmGPvsZmk9fZ95Bh5JMIC5vlLULlEq+WjZdYtfjK4fGaA5HdLTurwbllVIOkp1htfLXwVUq+sWGIox1HAyYifIGCn0gC65xB/U9nruPzj3cD/0iRweMqquiEnPOHnIq3d+lWQr3nVDhv3fYStZleNAPwxhpRX51l1buceKrSsaJQvz2msztQs6EKKv1tmyjQ+WW7B9lU92X5X3thvkon0VPuYei/60toKFxBzfXJnhOE8YQlLca4JTNzNEeWN71xmLaCj61x9KaMI+qPnUaNTi6E7jRViK1clFWlJsK+B9qRjR703DTW8uPWb5810AwJOFbdlpFZ/PT0pa7nvWWcMki6YQpuNNTw1RqDNpxuygna6QMhZQTjiMlpV7eo4u2dxkNv+5VgH31F/snaNOHSOPq3rSYmCl0cZPXjg5Pt4/V9rSwtYMOC8tQUHeq6atDMegQ591LaqaFaouKgzXdLhzqcULCtK98///yHYOgyzAZvlkWaWIHlq3HFoZh+m5/wZiz/y/WUeVKYFQUSoCbH7xU3gvajIyDwWlOpYeAZ8bwXu72ZGUkwLcmRSzxGNu+bt06e4oepIkzbhGvtYHQ/R537plrOciYyoHJ76+80UzrNPjgMSkzdXWvQG8lMIIghmCZDAOS3bOMlFBRS8yx0G+c/qUvjaYAWfiXUydxXDpKnHLTNDF39gyMXO5LUC4YIXAAUWqJOo/VPCRuywPQHQcWTZ4ryXXy/NcrTPKXpRTRYzJ/wXcp6w5G4vV9KrHJn/ckfpMRueRzLPULtRF9ce403TxOaHG4YmJVZkKTi5nCXh1zXhOsIDuKcwU7MBqg2Wa9YGfMxQIsqqOjAArzxkg== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: da2880e9-1ddb-458b-e225-08dc41b9e90d X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 10:56:31.5264 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4d70c8e9-142b-4389-b7f2-fa8a3c68c467 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ajZCkbccnSIgBIblDWoYyMGRr5LvfVDLsLElNz6cCloO9LpOWPVlMd/Ses/6kgbsJGE/yCf7hY7Ls1H6EV921Lamcc5v/oG0f4nbPHR5t78= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE1P216MB2024 From: "Jackson.lee" Add support for the YUV422P, NV16, NV61, YUV422M, NV16M, NV61M raw pixel-formats to the Wave5 encoder. All these formats have a chroma subsampling ratio of 4:2:2 and therefore require a new image size calculation as the driver previously only handled a ratio of 4:2:0. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung --- .../chips-media/wave5/wave5-vpu-enc.c | 59 +++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index 5a32bb138158..77657f63a169 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -39,6 +39,24 @@ static const struct vpu_format enc_fmt_list[FMT_TYPES][MAX_FMTS] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422P, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV16, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV61, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422M, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV16M, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV61M, + }, } }; @@ -101,13 +119,30 @@ static int start_encode(struct vpu_instance *inst, u32 *fail_res) struct vb2_v4l2_buffer *dst_buf; struct frame_buffer frame_buf; struct enc_param pic_param; - u32 stride = ALIGN(inst->dst_fmt.width, 32); - u32 luma_size = (stride * inst->dst_fmt.height); - u32 chroma_size = ((stride / 2) * (inst->dst_fmt.height / 2)); + u32 stride = inst->src_fmt.plane_fmt[0].bytesperline; + u32 luma_size = (stride * inst->src_fmt.height); + u32 chroma_size = 0; memset(&pic_param, 0, sizeof(struct enc_param)); memset(&frame_buf, 0, sizeof(struct frame_buffer)); + if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_YUV420 || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_YUV420M) + chroma_size = luma_size / 4; + else if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV12 || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV21 || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV12M || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV21M) + chroma_size = luma_size / 2; + else if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_YUV422P || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_YUV422M) + chroma_size = luma_size / 2; + else if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV16 || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV61 || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV16M || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV61M) + chroma_size = luma_size; + dst_buf = v4l2_m2m_next_dst_buf(m2m_ctx); if (!dst_buf) { dev_dbg(inst->dev->dev, "%s: No destination buffer found\n", __func__); @@ -490,11 +525,15 @@ static int wave5_vpu_enc_s_fmt_out(struct file *file, void *fh, struct v4l2_form } if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV12 || - inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV12M) { + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV12M || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV16 || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV16M) { inst->cbcr_interleave = true; inst->nv21 = false; } else if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV21 || - inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV21M) { + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV21M || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV61 || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV61M) { inst->cbcr_interleave = true; inst->nv21 = true; } else { @@ -1086,6 +1125,16 @@ static void wave5_set_enc_openparam(struct enc_open_param *open_param, u32 num_ctu_row = ALIGN(inst->dst_fmt.height, 64) / 64; u32 num_mb_row = ALIGN(inst->dst_fmt.height, 16) / 16; + if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_YUV422P || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV16 || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV61 || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_YUV422M || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV16M || + inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV61M) + open_param->src_format = FORMAT_422; + else + open_param->src_format = FORMAT_420; + open_param->wave_param.gop_preset_idx = PRESET_IDX_IPP_SINGLE; open_param->wave_param.hvs_qp_scale = 2; open_param->wave_param.hvs_max_delta_qp = 10;