From patchwork Mon Aug 12 06:29:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13760167 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11021079.outbound.protection.outlook.com [40.107.42.79]) (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 8299C8F47; Mon, 12 Aug 2024 06:29:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.42.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444176; cv=fail; b=JhuaNhEfU9Dw4riMYNXPpKUClDJH8K2JPU2yyJiLCoe4H+Lj2i37uYVOmH9/nSaOre51vy9CkbJTemJvALpTiXF1EIGP2qeImuBKDXX7RLa6geqV0UCdkAkzc1BfaCePN+J66DLEh7fs1NWDuuQ/l881cH4tsPwDQBlYqkKzbzU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444176; c=relaxed/simple; bh=kSDctqTnLEaMTcIwVIkXuc+h23dPmZ7zEJMLWdW9WEs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=RGospDe2qwB+QhsUsAOald1Cq+3DA8OyqTNJrQoE5Aq5lrvVB3f1MXAASuu4oTu0lWXjr4chixaU3CZ4UkH8g9JkoqflaJTlTzQkZtzz3KrAMOGqfsJELaUgJgKwtEN4YqcAuYIznOAC6BabIwTI602/KSlj3VD4H05U5TW9Ocs= 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=dQkNs9W3; arc=fail smtp.client-ip=40.107.42.79 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="dQkNs9W3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cujPzahlxwVhW/FJFYDIpkBPW0Vjzx6T9I6RELzc12La/PX7xwC/Oow+Uylh6UvsBqjA+FyZqZLIJzctvcfKDSoT33Hxx4ErYUaSlDNa2R0cnJ3ZdTuG47rGTPMuM4NuNuFha7f02znqvGZCye9vkamPFh2fuzE5cduEwAQFcFMzvht8f2ZpUqP2zr4WAVV4xnN0vZ3oCAIsnbKaCaMWWTEbVQW9AUD0SWMTzzU3Wf0Xbe3bcBE+Dn2IsEIGCSYbTWjpWijURdTIPbQvwK9COkoy1gTyjFg0tifDBAvd6Y23PP4hBjkC6NSgvpoj2bFEN+0XGY+QmzvudDIsOJN5pg== 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=UWbNLWskET9h61KXYtOCGImr7d5KzHGfun3x8NvAomQ=; b=R0qSrm8if61XXP66DsI7Kv7In2xIUBYpolDSbKEAxo3+u7YTTwxMKlzu9QSXH720K10ID2v0KSmWSUsxjC/RR7JHGMwmOEWVpGCIsNpr8GannHlT9IGdol9Ajgi/tvfimaYSPeRGwpA3q6lPRXj2sFADBzxOzZqpmkpKDas++9PdxbEBU7x5A0gz3v0mgHYXpgAkKOyyJpS7e6Fuu9+5G0DBJX3xqbhD7wgpfojTvYImm9EhOKXie0jYi8fbAwg1N0ZX+nuoFzNoUu70JUulJOxNzfZdx6Y6msg4k2D28bUagjRuZDWBpD9mNnJJ67H0TWCIeVfgsyW1ZVhDQ3Xxfg== 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=UWbNLWskET9h61KXYtOCGImr7d5KzHGfun3x8NvAomQ=; b=dQkNs9W3iuOoYTf6tEQyxm7O0d5RfY5NNaW0QPDrEeuvfRZF3t6/XjsV/zbxsyJdStndRWTkLjDHw5HcvdfzTlq/9J9V5ukxRfzeblmTyGVmn5N9czdBHopYg8Vi7Sy5diRtdZfdAUJ8Owcdh0/RyR5+BP3lXSuUIH9tj9DfOrY= 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 SE2P216MB1812.KORP216.PROD.OUTLOOK.COM (2603:1096:101:f8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.20; Mon, 12 Aug 2024 06:29:29 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%7]) with mapi id 15.20.7849.019; Mon, 12 Aug 2024 06:29:29 +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@chipsnmedia.com, Nicolas Dufresne Subject: [PATCH v7 1/4] media: chips-media: wave5: Support SPS/PPS generation for each IDR Date: Mon, 12 Aug 2024 15:29:16 +0900 Message-Id: <20240812062919.78-2-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240812062919.78-1-jackson.lee@chipsnmedia.com> References: <20240812062919.78-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SE2P216CA0044.KORP216.PROD.OUTLOOK.COM (2603:1096:101:116::11) 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_|SE2P216MB1812:EE_ X-MS-Office365-Filtering-Correlation-Id: bea6bc08-a6ea-4841-059a-08dcba981edd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: kdReRfAM5itYkpYc/x3iAPrdj/ZnZrU0DTH9UPL+E7KBUcwb5b7J7osyA4rNmoNGe+Dt4nVJakNRv4GugyvrSF7CzCzwSDyO3uhiB6daGrOzPanHNuAyA4qIii7C/+5d3nxFECzdFZsnxYUJERptZLkfh6s8Fa4cdOI3L9htgIY239GvuTAEjW9pf+t6GgiWxppEpZOacSEWJV1XMLDgceOWa4q7BO9lwxzRbQD6OnF4hBLn3cqN6fXB6Ma79oSiW7WBcTTEj7khs3LPbqwOeNQOXtfDERqd6Od/D9WVTMwpbNvTXAbYRoj+bJs9vNWXpX+5nTC1m8kwha5gJKXoll89NOfiIkorGXogLLRIXdyZL/UF0tH/Ea1q2c2e49NeIjpw05QCEpc+udoAz/5g1SBLHV5no4jcK9qD7mcres1rpwC69ajt9ltkTRsVcnPItDdI8fFWTLCnKL3OwWq2bGtgE+HKbbGqEXdYBkewi19HVrduNYE7TQv/2fzp4tTLigJh9mMxBBRt0iNfGYCW2bQVhDQr7BHVs8ED/AhOn1FQp9udlP9sykgaH9LPZzjJWtZc0QDBiAF0himPl/nKne3cYGygBUnb1r4VSLFtgoVH18kD53KA9bulJ6X90dGz1YurEchnkeW1dm8fNOd8amUHJ+bV0iBf74Sb/WsRgWjdIBxHowFsXDK6d9gzIWpHseKOrtEdbkhDFr6AhoYpqqJU8IZC5gzN0tsjYrqEDlPRQxZlDtdQwiu/8m/RfR34fZopKNUbHYWHsQIAz6l2klh/fUy1WmX9sLiSqLnK2RDn1BPSczn96xPyt1+M4Mngfuthkdx5YqBOCbps2R18gnFIjonUjyyrxawrElXQhDSVNzUb4nCbo1fNxnYAZhoisn4gbEFM55rpAHBq4yRfUaK70d9dT9I3l+W18SFPTvWTiossLHve7xMypTE9ajw26bTVfOrOgeXuy15tVi2nixbxRiD9rdd7y9s2bGwW1/O2gs+b7BpVdE1MBYxCsG6UkZb/uX3dUIsoL7Ggxl6bm5EH16tXveHeFxwSNlKXhaHdtHNEjmUaqOSxyIRQq8cQfBCe3Ge6VCHt5RyukhPE2jB6UAyZ53FrzSEwPSHEoDMV7XeDh2h6sxevfrojMzrc8NT46MpY9K4Zq4KYMNO3Z8Dxg/yjzop85tbccue2kd2bqpr2+23lKCIbUwNRHn75uACIPkKW1P8xha06vTb2gnjvM8eTu1PLwYa4Tdw6WTYWgYV17nclnGcdzuWKc1faCbSfGiJqusvDcUQ3Hp2xAXa8V5xaIM1cD6GkXsh+Uc6HTrySrYU4rAoZFfkGz1nMBPGWJ0DnQbn76xIirV07E4AuUeyDECpFovYRIr9nRfAf0zgAxhBntkqfakJjJ1QUueypNU8atae94xvGrmNcsg== 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:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bGM8aZw7XXscPW0dY65L68vRcXdKMkflcbn5/JUKms1trMnEV5S+FY1WqZ4qSVwOwclDOjy+yrS39gvhJfRGzqCwPnJ33p4QEG4dtEBsDFcqu7CiUlkL1F4AuEs/j9krCcNgO7ufLbqO9Xg+ZUFV/Chp9YBXfBo4VCZZcRDr58nz+YnGhChOB6jfOCxyBFN895Zo0aMtxGZ34DAbANZp31zuCvAA1x5hxCVFq5bo84eZGxMuIXilK2YOt2/3FhoO7vSgr+yGkZSmbW9VN6eYyb+OeNcwaAn6bhKfZxnF4gkGkgKE0ULAhW+l7XKC4G/+TQiYVkSmGHupRNdRWJomMsd/mQl/1KhVrKlfjurRxPCYO84HfGPkVE5w6dQfEbstf8tsOzoY/YXwzk9iFAbbyl8zIvMIL1ev7ouHTXtK8y9L4hzUKaN8W+6WkE+21O4TqkNI3U42CEZg5PR/TaqGEtyQooe9+BiipPCCM3dJxSWaS+DuQA+J3+Tb32nsSfCPYiSPQLmBjmferHoehM8pnoshjn7pmN6K4vQMZXoHKhBxfqYuedR+NkD9G7Lo+E2ydRlnZCTl5LDqpfQbtK7nPQV1JkYAbevupjZnWoMzHgoZZCC3Ppokq+8UFetES7iVtxYUxWTGx5rCHaKblfT1eZ1jPUqenq21Sev9v7Go2enM7tQLDDGwFAlbot270iOGTptWe9z/Yhxcw9zPWpsGLHBxDgNW2ceVeZC7+0GQDyLnXTuwByBDbbT+dccBOK4oqFeqnNB1NzVto0XWG7+zmgL2wuU+zh2yiM+NzkDxqkqVIJMYs+BzSjOhz8EaREIhJiuEySX0PsCnHl8HWMlKDr2btvXpOkV8tbcmlO8a6smuFnjPvJK+4uYxVKzqXgUlKdJknbCl3eP/bYUFdfR0UL6jSSjyIKXhiTAFlIEsmayW+EtHvTwHynrkTaie0CQLeS55jfLPDehTGbYMk4kVdLpIGSMsFENpavDhHA3IaMLnV5pRBwYmM75DIIQz/rd1cYlw1Vbl9GN7ThbMP40WqQCp5N5BfcDITSY4iQMfDW7C+EfoeKWcSvkMh9LBjCvRmvqzSk7qZLmicP4+JhkxtJJFWiA5FIj589Bs2HccI4OOaMBgb+0nv9s0Ncpq4EF9oAuIWYKVIiuv232S+iCVKQBWEfkoEfOmRFVI8DmW2yCvzwr+TGgGogVt6n7A1XaBxS2TUmbc/ubeH5sFklAF8yRu5t/ficOdJRvE3DyZyiohb29x790zrO8EYjFYCoSCEQH6V2exx/BmygUTefCb7Uv5s1BYb1YeL+Xd5vqMHVOTwtFasJWeA8L36tsdKzCyTCwIPxYrh1lhheID4VMzublfh2PtEHLS0POGa0Rc4EyhEG/cH4s37PIhG4rtu/MxNsVUUMZNlByImb2QGNcVIUqveA40ptSnlUuQhTaahg9qbunnKwor6Zcy8ifEW1JFRLr5yN/9Rah2C/Zm5WOCQFBkPPcPOpZFQAEW4KcQ3uEkBgCFMY3Jx0TOblNga2iUu9jPOVS/RUGGcS2BUSoLP/jAyNBOGoeq+AfDh5pHPH8U3PGLmuodCcY03eyMhTenDktPaOb7VvBWukKHCSBWbw== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bea6bc08-a6ea-4841-059a-08dcba981edd X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2024 06:29:29.6219 (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: lMqhqj8oP2LdJWHkIYa0LOD6vmNh3xDzsNsXxBT+9q0/DLQ48xv5wz/yGsMctHO7hydYMNTSTYR3of54Txe82VTHfy2xpBYC/ihQZITtKgQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE2P216MB1812 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 | 26 +++++++++++++++---- .../chips-media/wave5/wave5-vpu-enc.c | 7 +++++ .../platform/chips-media/wave5/wave5-vpuapi.h | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-hw.c b/drivers/media/platform/chips-media/wave5/wave5-hw.c index c89aafabc742..2a98bab446d0 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 W521_FEATURE_AVC_ENCODER BIT(1) #define W521_FEATURE_HEVC_ENCODER BIT(0) +#define ENC_AVC_INTRA_IDR_PARAM_MASK 0x7ff +#define ENC_AVC_INTRA_PERIOD_SHIFT 6 +#define ENC_AVC_IDR_PERIOD_SHIFT 17 +#define ENC_AVC_FORCED_IDR_HEADER_SHIFT 28 + +#define ENC_HEVC_INTRA_QP_SHIFT 3 +#define ENC_HEVC_FORCED_IDR_HEADER_SHIFT 9 +#define ENC_HEVC_INTRA_PERIOD_SHIFT 16 + /* Decoder support fields */ #define W521_FEATURE_AVC_DECODER BIT(3) #define W521_FEATURE_HEVC_DECODER BIT(2) @@ -35,7 +44,7 @@ #define REMAP_CTRL_MAX_SIZE_BITS ((W5_REMAP_MAX_SIZE >> 12) & 0x1ff) #define REMAP_CTRL_REGISTER_VALUE(index) ( \ - (BIT(31) | (index << 12) | BIT(11) | REMAP_CTRL_MAX_SIZE_BITS) \ + (BIT(31) | ((index) << 12) | BIT(11) | REMAP_CTRL_MAX_SIZE_BITS)\ ) #define FASTIO_ADDRESS_MASK GENMASK(15, 0) @@ -1772,12 +1781,19 @@ 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_SHIFT) | + ((p_param->avc_idr_period & ENC_AVC_INTRA_IDR_PARAM_MASK) + << ENC_AVC_IDR_PERIOD_SHIFT) | + (p_param->forced_idr_header_enable + << ENC_AVC_FORCED_IDR_HEADER_SHIFT)); 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_SHIFT) | + (p_param->forced_idr_header_enable + << ENC_HEVC_FORCED_IDR_HEADER_SHIFT) | + (p_param->intra_period << ENC_HEVC_INTRA_PERIOD_SHIFT)); 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 3e35a05c2d8d..b731decbfda6 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) @@ -1701,6 +1705,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 d2370511faf8..45615c15beca 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h @@ -568,6 +568,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 Aug 12 06:29:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13760171 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11021079.outbound.protection.outlook.com [40.107.42.79]) (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 6FCC5152199; Mon, 12 Aug 2024 06:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.42.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444180; cv=fail; b=VZRzJXr5mxexT8S54LjYycCGlxuQLDfsKScCtzFYB8R7msYN+m6mYNTi4/peseSiZIVQ3Fqd+0vZZQ7rL/bGiIPfi5K/HkwiJ4qSrJhH2BuAD+EVRGbuq0m8NtFj9PEHvHajvT5aVkozeQ/Pe6hSiZ42EUvccjcjcrenUT4CyZE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444180; c=relaxed/simple; bh=1gH8Kst5AyvyREmhJnzJ4WA7ZLdac2yMvVZzwSm6PP4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=L8XEY08xVtxlTxytyZwYIp71JaO5KV8J8YDULN6sTVUWdi6p6AONUqRrDjahexAj8gNB1sLzUqJhHq9RfkMwOxGtV/nYfIpesDjIr2jeYbd9oHKYYHG0uZBqQsSdtRQu+21C68t9nCuAbTRqA1rLVXWggnUfIL8Md4dpp5YkYBo= 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=GmJ+iL50; arc=fail smtp.client-ip=40.107.42.79 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="GmJ+iL50" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KENj1CnjA1gIyNFqHOmpbWn2Idofi6gOLkvH5AKv8iEN3ErRhk2UkdHhfjCpcGiwXfAoHRgo9x3d69VW+/GyU+JyQZI/gK+o1pEBcUnDT8FR3wei6Qwn8ZZ4bgUEZoWwjJAwJ/8j4+bfUMliWU8I0HMRW8/SzCB3Ja523/n7isv0QD3s6CVAWbOScMGOVioNUziK8+7NxuOs1v85G6Y8Zar2b3Bguw2/AJiFtyLcqjMkc2BDRMVTiQGevaN3vabl7tkQSYzg24qQZqalc2vxbNZvcHnBuOMvZwgV4xAtD0hxY1jUyFqeuAFbd83ywMIxhXHjsQn5rPELCU9zUsFlWg== 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=EsuiMHgkIfdA/t5ukV023GxxCFgVF8UHfqk1OSNTkb4=; b=m0qMIQiRTslrHT/ZIAoAZuyuLumzycEV64MP3+YNT3SwO0IflyX9AG7+zj5Y2fgiSqB61TCXWoyuRzQTlS5AafK7J69Bpa+XHNtQ41GtjFL47XP7v2TnAGIDnl1KYooJQ1uRGxdLYCgRuZeLcvWNdIau+Lafvsk/FG8eWwbVvfoNjZ5eZGnn05u7xkFc4U+i406LggMowiZCou1iMA1nMW+HbvUhBfdIVKmQwTg6ILgB3OeePVLkzJIiCBa1i/T56eOhltX2ypWO/7f8JKeQ9a81Vo8izA9TYRtuS7J9au4k8cpuvF3NTNu13XDtPuw8LeJ3WuujF+xgV0U7SX+ydQ== 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=EsuiMHgkIfdA/t5ukV023GxxCFgVF8UHfqk1OSNTkb4=; b=GmJ+iL50N9vl7gTVXbKujiOaVWP9h78PtDDAhWPluQ9yLNiuyOII+H3uYoC2+sb6us19TIKR1cp2cIPYp6rX6TWGJUB84WtH3hWX0n/RJQJIzQobzkP3L1FI1/bA+jAvO6mIdjNarYko9bgv9798MBA4Me3U2YJY6OG5Dhycof8= 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 SE2P216MB1812.KORP216.PROD.OUTLOOK.COM (2603:1096:101:f8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.20; Mon, 12 Aug 2024 06:29:30 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%7]) with mapi id 15.20.7849.019; Mon, 12 Aug 2024 06:29:29 +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@chipsnmedia.com, Nicolas Dufresne Subject: [PATCH v7 2/4] media: chips-media: wave5: Support runtime suspend/resume Date: Mon, 12 Aug 2024 15:29:17 +0900 Message-Id: <20240812062919.78-3-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240812062919.78-1-jackson.lee@chipsnmedia.com> References: <20240812062919.78-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SE2P216CA0044.KORP216.PROD.OUTLOOK.COM (2603:1096:101:116::11) 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_|SE2P216MB1812:EE_ X-MS-Office365-Filtering-Correlation-Id: 60563810-c75f-4c5c-67af-08dcba981f03 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: Z+SHIWSKZb0kW16qUhBi1phNYx2CE7CUT5ixcoJU4AelTX0D/OvE+NR39FT2lEwtmOwaLzl25JAJy5W042furBIGJs8bnnLkmoaE8VCL5z6n/tYiE03Q9NKPOpXBU2U6IsOazD3vc7QM+ioHwfYE42RZaPqcYazxJB70Qxq7c6VC7V5aiLiFJmPfqUpFUXXx14xCtRxSUaMO1urpPSQLH3yNSXEcy/98W6xxtxP6sxk6p79oK+fyoGE5Qqk4asQovwmH6kQI3GX7OsxtQYx3RQ77oyZ4/0Re+1cy6JF2PI0/s4TFPz+H2NMNinDJvQHpN6wSBIVfuXR0Vc5k3W4u7puMNE1AKo4JK74sRgXcd6Wh5eWLqzFYL3a5T1MAcu9dbZSj4kxWFVxckZ96bP8WVl9wcgUPrx0o5rjFMwt1A/rKvaMy4Tv4hiDH2bsUkgnD8euY5LwAMAnFI8LF7gkb1yXGtaiHnSSvLAm7Gp2Oti9tN5eM3JwTtNP7mwayOgLyBzaMxnE+RN9JIaUjF+fDp5kUK3j9QxVP0cpuaqGZ0SbE11SFn0dqmGPL2eTBGQfEm3YWa3byBAltX5OtMIeDRXnpEdWxOJnKiPLwFDXi7cTR5haAc5lbSbhrGHVtK3YiYiu6hpFATAtytw+X9WyU633OkzGByHH2zwnWTE5IiBVJ75xxLagRmmYzjSWrhTL3FAAo/8JmH334oxay6z4i/9vd0x014Wwbk5yb/h/a6yjJGeijEivY1ShZpi6JBM758XQhi1Fw4TkjWbOinnYSwHDJGTBddGjbwGDlXv7oTqfMF4UFUeN66AzcaCr7wpCJURoMq0+a1jIfqW63EF4lHSgPww4lRqWl9F7g+7g6lBc0LRmo+yNc+OWwmUZM4OJqRVcVAhkfsXMELlbvWkL9+IYG9hyAqCL2XkXyy1hazdhBICp2QAm85RdcVdtNwllCD8UIV4X3vEzxSw7YPoRoAwb9j4YTHSfTYKDw6y9OtxGpRsvoLysybr2XmhEqVEyogtZSaqtgPTYovtc7fF0eDexRr8+EzhXhaByTqnyo9FZBd+UYa527giv8jkLy/p4V9hYCKhkErocwmWkVt2gktTgTiCADcL5g4oO2k0BXvDx3DIOwO2x0KQWe1t56MDK8jFfRdk6ftnf2LUpRV6nkCbU3hjPDKeeDXQqZ3To87BEIvYv/Nb+gFiH/4fxOvtXwMkTBudbTiipHVA0JBUiY2IQUEe7t79hF4/Hi0f93BRpyvvB8efSVHNI6lso1inaDejG010Er7TBzfysY5M2meOwsj95bKSooRVPCv0sPNUn58ah+p3CKf8HDFNo9b1mIlK6Lvcaf20cVqSG1IRH3C5pwEEvvFy1RoNRuOH0jhDLW7zeL7vGGltmNtqzz1CqPTqk53oOdhvR+td8ot9rjhA== 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:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NhWn2VVpzUM1TYz2CDFrKmnCy12kwF+Oqi9PU+TVipYksuyeFbXE9q3MXDiNJOwN1tP/ocEP8v2oWqxiR+58AlGhftI+XK7xUxk4ERIkH1fbzMFn0q+3ZUhTeSkqG//GXJUnZi/L8jHuhQXKQkx8zzRelizc/I6bolTisZkuIDeYiaF1/eNLkxmXQ5QFkpQEC8+r3SfTIOUZT6MaDspqYQAdRLPC2KKTy1jHhWWWzhwq37eI6xJcEuWgqWIIvq+g3p7mfPoN2n2DqXTbAMH4wyhm6cFB2rJ46ak4VkurFrjVEBfU0ODbCm286B1i2VEk+ryDPEZ4lXvma2rlrV9XEhnjNjDpTfMOHNcmCZ9GxnsFSWj/zzEIJYJTRvybsRlrasmhYodx+aS7IZjNmScMAz611OqCGC3rctqCcOGXY+XRvzGWA1xT6LJzSfki+RlgRlUeFqens0kKijw6wcTpGPhSkFX2gTNE5MqvKpWEGJWq9wBmTq/T9UGGxumg3AxIDMrOwHUZCnIoOJXtd/xu3d3oYp/yryscpY5c3waFwhWaf+okobxvgmtOrhoQs+tFGhcWTpoB4xc0HAQWSDbqdyFUilqD/xVE76YxsNr1rW/uP53juzLe3Nc9+E1x45xL/oyHhVgjvFVfeLtHzQDRV8A4e4RZIrAaUWx9mV1Ceqt1er4SKeoVSfzHXDfYEBRndlNY82MkMBGqRUgdGn1CrpkC5viZvKbPFgPGJXxy2RfaBi6/G77uTE/BZVlQeXXW4MzFLlui9GNX2bNCu5HGLAvmP7vYR9+VvzwihnubeaGv7zv7deg6WY6pIuv+nDxv2GwLAhZu/VLi3ukNcoZAlIiR1wIMtDFuxbTx5I1QhPmvCqiwHqb4ugGy5s/dj05XwnmWY5JROZQ817yEJb0VuR7oHMSPcyRQ0SlO2ORGqP1CwDA9i1gSqbxQJ941VXYysSJndEjcZGBLk7fQThbEVHu9phkDKa1JZbAjTa+nKV0JjejYHCQKfMOqBLdhs6DIDR5FSHuO7zVdm8s4Dsjch0caDvo4fer79wc3FuT/BFmuWtg2JWrG71KgX3TyA3W679/u7YXciFtp+nrL1WtBJGL56CkTABok+Ho1Srs4RcY/8V4RBc2j1V2R5x8Z85dQ9kGEIl6XGyQwH1zx3iBGWuNnPMDbxxEaERCmQRmk/OIaLVLdtSljAi4ZMaylXy63uext+AJrVc3VtdCmqzzGgVjKfHyQMkMBJnAdbzQxIXNwFl3navXCG607Tup5WYZ4DLGhY1xB8gARMOWuWWZ0nkOsSRA6n7f2Alg1lPWXqOHMZPLFjdEgP1/ihBREHbb056eBsyh8LLdWQn7/O8ma6TVXUL9H1e4A8X9J9VVBEdbqTMtyx4tS4rsETVNPHjE3p8Hq880wNWB579Fkrw1FEFuIdFsbkImXJ44eldqFw/oJUdSMiRjgrokVvmGdyn7uzjrhIJS+ppxDcFRfy/MiOanDQtsBPKxdOOi8nTwJsWFTeVZZibY2tn/4M8g+mARysjyAgyGve62bxvDitolsaUelC3WUxKbrhQOqE8gcgbzHBATA/rQjLvN+ZG6AdNuemgjep7Npiu3ubLKik8PTfg== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60563810-c75f-4c5c-67af-08dcba981f03 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2024 06:29:29.8767 (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: xMKT/QT7m7sIqT8Oh5wxr6vc/eymfXEAEEtDsFIP5FvrOLOtd8N7sU8rl2e6wVQTWsVc+rHjvzK4UypxoIOvpTKJYIxRW+D9YVoKj1E+Eg4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE2P216MB1812 Add support for runtime suspend/resume in the encoder and decoder. This is achieved by saving the VPU state and powering it off while the VPU idle. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung Reviewed-by: Nicolas Dufresne --- .../platform/chips-media/wave5/wave5-helper.c | 13 ----- .../platform/chips-media/wave5/wave5-hw.c | 4 +- .../chips-media/wave5/wave5-vpu-dec.c | 21 ++++++-- .../chips-media/wave5/wave5-vpu-enc.c | 20 ++++++-- .../platform/chips-media/wave5/wave5-vpu.c | 50 +++++++++++++++++++ .../platform/chips-media/wave5/wave5-vpuapi.c | 33 ++++++++++-- .../media/platform/chips-media/wave5/wave5.h | 3 ++ 7 files changed, 118 insertions(+), 26 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-helper.c b/drivers/media/platform/chips-media/wave5/wave5-helper.c index d60841c54a80..a20d84dbe3aa 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-helper.c +++ b/drivers/media/platform/chips-media/wave5/wave5-helper.c @@ -58,7 +58,6 @@ int wave5_vpu_release_device(struct file *filp, char *name) { struct vpu_instance *inst = wave5_to_vpu_inst(filp->private_data); - struct vpu_device *dev = inst->dev; int ret = 0; v4l2_m2m_ctx_release(inst->v4l2_fh.m2m_ctx); @@ -78,18 +77,6 @@ int wave5_vpu_release_device(struct file *filp, } wave5_cleanup_instance(inst); - if (dev->irq < 0) { - ret = mutex_lock_interruptible(&dev->dev_lock); - if (ret) - return ret; - - if (list_empty(&dev->instances)) { - dev_dbg(dev->dev, "Disabling the hrtimer\n"); - hrtimer_cancel(&dev->hrtimer); - } - - mutex_unlock(&dev->dev_lock); - } return ret; } diff --git a/drivers/media/platform/chips-media/wave5/wave5-hw.c b/drivers/media/platform/chips-media/wave5/wave5-hw.c index 2a98bab446d0..c8a905994109 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-hw.c +++ b/drivers/media/platform/chips-media/wave5/wave5-hw.c @@ -1228,8 +1228,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 0c5c9a8de91f..698c83e3082e 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); } } @@ -1398,6 +1401,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); @@ -1429,13 +1433,15 @@ static int wave5_vpu_dec_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 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; } @@ -1521,6 +1527,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; @@ -1544,6 +1551,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 = { @@ -1630,7 +1640,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"); @@ -1713,6 +1723,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); } @@ -1879,9 +1891,8 @@ static int wave5_vpu_open_dec(struct file *filp) if (ret) goto cleanup_inst; - if (dev->irq < 0 && !hrtimer_active(&dev->hrtimer) && list_empty(&dev->instances)) - hrtimer_start(&dev->hrtimer, ns_to_ktime(dev->vpu_poll_interval * NSEC_PER_MSEC), - HRTIMER_MODE_REL_PINNED); + if (list_empty(&dev->instances)) + pm_runtime_use_autosuspend(inst->dev->dev); list_add_tail(&inst->list, &dev->instances); 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 b731decbfda6..985de0c293e2 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); } @@ -1739,9 +1754,8 @@ static int wave5_vpu_open_enc(struct file *filp) if (ret) goto cleanup_inst; - if (dev->irq < 0 && !hrtimer_active(&dev->hrtimer) && list_empty(&dev->instances)) - hrtimer_start(&dev->hrtimer, ns_to_ktime(dev->vpu_poll_interval * NSEC_PER_MSEC), - HRTIMER_MODE_REL_PINNED); + if (list_empty(&dev->instances)) + pm_runtime_use_autosuspend(inst->dev->dev); list_add_tail(&inst->list, &dev->instances); diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.c b/drivers/media/platform/chips-media/wave5/wave5-vpu.c index 7273254ecb03..41c4bf64f27d 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 #include "wave5-vpu.h" #include "wave5-regdefine.h" @@ -153,6 +154,45 @@ static int wave5_vpu_load_firmware(struct device *dev, const char *fw_name, return 0; } +static __maybe_unused int wave5_pm_suspend(struct device *dev) +{ + struct vpu_device *vpu = dev_get_drvdata(dev); + + if (pm_runtime_suspended(dev)) + return 0; + + if (vpu->irq < 0) + hrtimer_cancel(&vpu->hrtimer); + + wave5_vpu_sleep_wake(dev, true, NULL, 0); + clk_bulk_disable_unprepare(vpu->num_clks, vpu->clks); + + return 0; +} + +static __maybe_unused 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; + } + + if (vpu->irq < 0 && !hrtimer_active(&vpu->hrtimer)) + hrtimer_start(&vpu->hrtimer, ns_to_ktime(vpu->vpu_poll_interval * NSEC_PER_MSEC), + HRTIMER_MODE_REL_PINNED); + + 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; @@ -281,6 +321,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, 100); + 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: @@ -310,6 +356,9 @@ static void wave5_vpu_remove(struct platform_device *pdev) hrtimer_cancel(&dev->hrtimer); } + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + mutex_destroy(&dev->dev_lock); mutex_destroy(&dev->hw_lock); reset_control_assert(dev->resets); @@ -337,6 +386,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_new = 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..e16b990041c2 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" @@ -195,14 +197,20 @@ int wave5_vpu_dec_close(struct vpu_instance *inst, u32 *fail_res) int retry = 0; struct vpu_device *vpu_dev = inst->dev; int i; + int inst_count = 0; + struct vpu_instance *inst_elm; *fail_res = 0; 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); @@ -232,9 +240,14 @@ int wave5_vpu_dec_close(struct vpu_instance *inst, u32 *fail_res) wave5_vdi_free_dma_memory(vpu_dev, &p_dec_info->vb_task); + list_for_each_entry(inst_elm, &vpu_dev->instances, list) + inst_count++; + if (inst_count == 1) + pm_runtime_dont_use_autosuspend(vpu_dev->dev); + unlock_and_return: mutex_unlock(&vpu_dev->hw_lock); - + pm_runtime_put_sync(inst->dev->dev); return ret; } @@ -697,25 +710,33 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res) int ret; int retry = 0; struct vpu_device *vpu_dev = inst->dev; + int inst_count = 0; + struct vpu_instance *inst_elm; *fail_res = 0; 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_resume_and_get(inst->dev->dev); return ret; + } do { ret = wave5_vpu_enc_finish_seq(inst, fail_res); if (ret < 0 && *fail_res != WAVE5_SYSERR_VPU_STILL_RUNNING) { dev_warn(inst->dev->dev, "enc_finish_seq timed out\n"); + pm_runtime_resume_and_get(inst->dev->dev); mutex_unlock(&vpu_dev->hw_lock); return ret; } if (*fail_res == WAVE5_SYSERR_VPU_STILL_RUNNING && retry++ >= MAX_FIRMWARE_CALL_RETRY) { + pm_runtime_resume_and_get(inst->dev->dev); mutex_unlock(&vpu_dev->hw_lock); return -ETIMEDOUT; } @@ -734,7 +755,13 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res) wave5_vdi_free_dma_memory(vpu_dev, &p_enc_info->vb_task); + list_for_each_entry(inst_elm, &vpu_dev->instances, list) + inst_count++; + if (inst_count == 1) + pm_runtime_dont_use_autosuspend(vpu_dev->dev); + 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 2a29b9164f97..2caab356f3e1 100644 --- a/drivers/media/platform/chips-media/wave5/wave5.h +++ b/drivers/media/platform/chips-media/wave5/wave5.h @@ -62,6 +62,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 Aug 12 06:29:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13760170 Received: from PUWP216CU001.outbound.protection.outlook.com (mail-koreasouthazon11020119.outbound.protection.outlook.com [52.101.156.119]) (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 37F7514F9EF; Mon, 12 Aug 2024 06:29:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.156.119 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444180; cv=fail; b=lEMVlZJ1nIgwGrWG21zT8QO5CKN9YvjG9cOdaeUPoyYiL2LVg35kJCl9jEgCkuzeuA4TJ5nOPTnxd4dEydVB7F1CaoGk2i8j/zTOb1zV/Cbc7tdNVqmwnnrSHkBwd+JEL3+jZMz5oVvq3c1+DQoJF9jW88DmFY0rs97obzjxoUY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444180; c=relaxed/simple; bh=ZjbiecUtfz34AcvWzNF0KHkLi7n0+2IdiTTl3P9ld0g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Yy9Yw9p8qrNx6NNPqPyJauYMAtCUnSpH6jbC0iGSNYfEmIhRVk+1yIGV+uYNC2p7fUkndHiR/d9dlKE4iE0ROMqCMnW17lWpD0b1f2lfjrt18m+JwtCG0YiAb+Q51XR+B7GzoVPREapa3sEMpF1Xe/IBOSzJen++bztCHjYUAXw= 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=Lf4Qq0rb; arc=fail smtp.client-ip=52.101.156.119 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="Lf4Qq0rb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jmGy+O7MBqgq4Jd7gnp4h7CTUw8+zr58pJQwGWQuAOC3/ZQeaT9suSkLxivr5kgTZyMZjA5QZy4WMn6sIgrlghefI1IGYOrWHyRUCk27aWaXSqgdlpTUgM8iEIZVlMye+Usf6bHMq0uTB9wBrCv2BDT5Dj1flVdoys1Ej5qAIzwZhtOQ1irOCCm/QoOSsry++qTOUKw/J5mWFCqD3lC5l6wARj1E469zV4a1CBnD6xS0DNKPVUY5nGvbKkYM6JwvyD3RjF1Tg+0ZPS85UER+B8C6BQvwHOd51aqrFPrhGUEWjm3UXyMr6Yo2t/qvrGFEM8xVpq28l6LNQmYqyUE8Yg== 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=qrdYPBptrcx70T0L1oyYy/761PBMY5fM0piZwIZYMc4=; b=YqBdxxcoIWVIDYrJWTmmk5JNZTuX4i3m1D7IBEaKeWFMvnxD3rhU2KSKcl0LwP7ce3KMa6/YXcmIN0+XfoWYlwhKgPFcMltBMwRCwXuD3msqcXZUQnegmEDIGWl7z3TIeObw4faRw3awKVfaLRoDygXzyHLyrsm6QN2+QSQTaxTBC7tdsTR3DKVZKFh8Xxv0QrXCIeIJAtSqC2f2cvJ8fTV8CLAObK4j2peWf0LKkUwuFgp9o9W9xQemHIdnOVR+rB9JhCwcbmetmNUtgSWkhtfVB60xSCtmMOusJwoaOOGmgSfRwy+BNtmPmMDJJNPwZbuuSbbVs298j0qQCw843A== 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=qrdYPBptrcx70T0L1oyYy/761PBMY5fM0piZwIZYMc4=; b=Lf4Qq0rbdTW6yHoTdTnrZoDIce5npdDTXhUJjOTBh34WqRj4fQiC7lVwl8Pk0q6oChLMKQnIj+zO5DtchrVRxTQjVCpey1Xmy7JHad3NnM8I1ogXIcg9MIaAazhIaHG6WwH73sBRpJ12tnXGr8oz1PmVhG9l/zYMVico5palVks= 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 PU4P216MB1820.KORP216.PROD.OUTLOOK.COM (2603:1096:301:10a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.20; Mon, 12 Aug 2024 06:29:30 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%7]) with mapi id 15.20.7849.019; Mon, 12 Aug 2024 06:29: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@chipsnmedia.com, Nicolas Dufresne Subject: [PATCH v7 3/4] media: chips-media: wave5: Use helpers to calculate bytesperline and sizeimage. Date: Mon, 12 Aug 2024 15:29:18 +0900 Message-Id: <20240812062919.78-4-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240812062919.78-1-jackson.lee@chipsnmedia.com> References: <20240812062919.78-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SE2P216CA0044.KORP216.PROD.OUTLOOK.COM (2603:1096:101:116::11) 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_|PU4P216MB1820:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f37e5b6-0e96-4a56-fcf7-08dcba981f2a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: Eo7gtVx+NMigycVRWLaiuq7l6oEjdn0GrEd3E2vSxi7tjCb0fyqJlGe2Aly96f+qKNAs6kSW36CqhOMeacGE0thil4tsuRHi2pEH0ODhP7ocgSM81HTPP4ptauFKCfr9qicOSRgYysaPanoqCBMsc+XyF1432h+43yLDz+sT04c2k69QicX76oZU/VW1hysCAifaZRJyDy+sg5aiMpZY/lICJ+MBg6hgAPtpPeArY4pk+S02SzzL6nCVjG8twUiegrFC6N4G0DaL0oJDEssta8GsMxzRvsQ4kZvIvCLlXze5Z4YhTKVdF8wyK++JNxmyIoBjUaG4RKsgAX6lmm9K+GOmEqUWH/6NF1zMYD0S/mNpoaWpeXZDvTCzHps3pesIqogJKsyj+/MbCuLdMxRgKyVgxBkkcgt8FQgGv5Sh6jvNRdIUiGBMeQX37yCMOe6hcQbKiKEtoqiZ2Nye0HcEImvxj+jpH6bv8vbeh8WnIKtOaAAn+v2N+witWk3il0oJWu2246oWTluholwuJFBPseQ3ZFc/A02kHdnqwe/LSYsaDuRR+ygVBPUAOaVjFnIoHNHnsWYx885aM+UvyjCju6Fy/A/g49ndx6NRRLtFxfwKi/bwPkCGU5DIQzifW5zEQ+eqtyKhdp/Pf4KVciKbhAmOzhvkHf86eFel4OU82zGMc42At8G3Hm/GR2rR3ywdEZOZh386NpdPoOfAou2a9NJl3RApV0vI07PI+Sdqp4DqyqEx7H1r49kPiHdSZizmK7LMfVWoHo0VzQxuHt2gg8niuoYAY9FQklRnm8ExsfPLwDPRUFUmUHm2edWoOiWMmS+qwzAKVcvqZsoDgztTIbq1R11frPbTX2ZuETVgQKJQRbadQdijLMd3tpnyACzZpyDFJa1min7n31Rw8V3KsBdMXsVTmUa1T2+lkxMLcaG2aLYL88P4a1D4L/061uOxHQNZrehDd0KCimo0kdfMHqmnEYaw1V1C9w/J8RFySdDcAlufsFCBnTQHPKKqsEZM6JpXQG+gna3AJjpUS7Hzv1taHFSz2zgo3t1+YC0peHm/+SLzMPO/i34ljmCkuNPMMDbMRnFjpjkro7dbB3eqsdgCXdvgkj/gGAb9lNx7q94daTpvlRti4hxxd5kVvi5O0QlMUPKJ0A36t8RkIu4mPCf9MIQ9qDFnDa9l01um052CB0Ok6FQO+GWzt+jMop9nUeBx/ZjIXCQS1Ar0zMyoOE1fFOvJU70194leOzpM5xic3V6dIjIHwGcsFVwGPqcmiJJNA8Z1PIV7nykZs3b7YtL9aWX1/6uib/ac738pJZW5AczrFJTp1P3d4cq0n7aOCdDasTHSYzeOPShS9W+y/QmmWiHT9Xlvk+b5vUVojyqfeJG1D9HvKKH5MbGnOU0ow4/UlyWfUvWwn5/S2Dy+5Q== 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:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bSWNGwmLq5244ggOn3GAmNd5I55PnkZ0mEZ/kAGxVCeaNxyKDQhCQV5WlAKQgqEvUf2Lq5uD8bnZY5qz1vc1RPob/eC5aNH8w4rAcdy197N3re4w64A5iTJMANGYIM3zIHC77lXYaKeXRAWMmJbZ9HZOiixec1zbxAy2GrhmhDsn8ydbbmLcF8xuWcngEaOCaFlG0HjCqpsaem+NLSCYq4veLSXpnvqLJ5giOgX1NAW49QyUCWzT2dyoYZVGW4I31YSdMSRysPuzah3O6m4Nx1fUNOh7lj+g63OnSV5yIeQmNq7RGnIjKWPlWBu2dBViagaw90Qu/b01G02zrGa4BO6BWXTAPKAYQdphIMGma7/zKDOYyS6BTmv32/8b51Tc4IdXqOGg//BZwLR9UpO2NpgFVTfRLQgQeLTmq+Ojm7f6eNyIvyhaF7cOtYXK1CGxVcqk0EhbKGGgwv6aDz+o/VScOsUiEPF6H8KSph07SRUW0b+LOByI2Lq1b6PvzeU21q4+AvOq2M/waC3LjQ2iruZ06Ti+opTpczjs8UUOiBi9Vl/92GsT/SOZz7m5+e+jqoIh4czff0sccgZ7Ao/p7h48uWTDhekJAIPGWT0qAMRu3JHgT/hRjlzyC89SoHvQmnYtHtiFFoXDL58b4aD6pdXyRF0vlRMNCVWr1InC1P3Mx9i1buxkfFOI7hDzc1PIVYExNLSUNRjuuA/uiqx4wIt4viotO+Kb6KW3/EYEyl03CQsSTyuqEA3fPpZl/kqakKScp28OUMjB7oaCXbmGphe94Yrme6RX05PAmNggOsOUvvraP78GpS5ShV9OesPRZCyQehzCzYAoRmOS2GCsc6gClGWqLJ4Wh29eLycXRkOPoFbzMnveBdKbyP8AExg5/oL+vVgjoi4Oe2W4u2D4phm4dL3LiTfrebq9MN6JRz/uU/7y8/p41VBVaVbfaO9A1/w1ctHyMSlstknds2BRKy+K+q8ma0NE8zc+u8RhrYE5S+fOMaRHHgbZkADOcFqshJSlwi1hBhi+7MTDgEuBU63nT/wGeNO9FrfI7MA/NoiF6gE3uFEj8XQ0LaQaK6JH+hjhk24nwCZL8KV+9IP2kmNCQdtjrOnsPbor7WvrnUtejwi5QYS59C4V50dD6J9Due8fUvEHn1x8mwnOiemtB0Bhu39AqRqxDgV5NHA5JjHuI2pPMGVt9rgFPaHnzJ8pRONGGMooaNKYfler7tarRaIgZzMZDJ7vV2lxdvV9Vv/NMqmqPV6IQ6MJ1t3Kd/ySu7WJVAnKAoneEBHA4y7Ps5wH7mmnVtsnPsdes1cLrZ9FkAvDdNNZnoRWLf4Al29qpYJIh1nVkbxHs6bRkyeTW9OhPV2YdN3jDhvijkcxLMGj7ns0zQsidOKAbPrm49JgMUVxPuP6aAo5UlpBJ7hrWsh5Vy8LJbbwTgzVRTwPbgBY+xgGVtnu7i+2fZQK9XV7K3fuBhy9JarfZdOLLWwgcqdjLEtcNtNVSpEz5YoKZL6WMYRsxF/u9lBACNo9vfKrNg0WHbiPRpsb2agOQ1jlaG8bdve0XOFW9MOwugWD6IRAqe6+VsOkE1LeT26dpD7gvxHtbwSQ+45qwMgbGpDoaA== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f37e5b6-0e96-4a56-fcf7-08dcba981f2a X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2024 06:29:30.2179 (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: mLe6U/bDG5LfsYu8lhFPoQjSlakX5KhKK9azmbCqK/+awatY0q3VW5Wv1GYJVqOmKxhbSzFk4moYya44eDBoMOoC1na04YA5i8MWNlzicQc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU4P216MB1820 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 Reviewed-by: Nicolas Dufresne --- .../platform/chips-media/wave5/wave5-helper.c | 24 ++ .../platform/chips-media/wave5/wave5-helper.h | 5 + .../chips-media/wave5/wave5-vpu-dec.c | 301 +++++++----------- .../chips-media/wave5/wave5-vpu-enc.c | 197 +++++------- .../platform/chips-media/wave5/wave5-vpu.h | 5 +- .../chips-media/wave5/wave5-vpuconfig.h | 27 +- 6 files changed, 240 insertions(+), 319 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-helper.c b/drivers/media/platform/chips-media/wave5/wave5-helper.c index a20d84dbe3aa..2c9d8cbca6e4 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) { @@ -217,3 +219,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, + int pix_fmt_type, + unsigned int width, + unsigned int height, + const struct v4l2_frmsize_stepwise *frmsize) +{ + v4l2_apply_frmsize_constraints(&width, &height, frmsize); + + if (pix_fmt_type == VPU_FMT_TYPE_CODEC) { + 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..9937fce553fc 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-helper.h +++ b/drivers/media/platform/chips-media/wave5/wave5-helper.h @@ -28,4 +28,9 @@ 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, + int pix_fmt_type, + 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 698c83e3082e..01423daea78f 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c @@ -11,111 +11,92 @@ #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 v4l2_frmsize_stepwise dec_hevc_frmsize = { + .min_width = W5_MIN_DEC_PIC_8_WIDTH, + .max_width = W5_MAX_DEC_PIC_WIDTH, + .step_width = W5_DEC_CODEC_STEP_WIDTH, + .min_height = W5_MIN_DEC_PIC_8_HEIGHT, + .max_height = W5_MAX_DEC_PIC_HEIGHT, + .step_height = W5_DEC_CODEC_STEP_HEIGHT, +}; + +static const struct v4l2_frmsize_stepwise dec_h264_frmsize = { + .min_width = W5_MIN_DEC_PIC_32_WIDTH, + .max_width = W5_MAX_DEC_PIC_WIDTH, + .step_width = W5_DEC_CODEC_STEP_WIDTH, + .min_height = W5_MIN_DEC_PIC_32_HEIGHT, + .max_height = W5_MAX_DEC_PIC_HEIGHT, + .step_height = W5_DEC_CODEC_STEP_HEIGHT, +}; + +static const struct v4l2_frmsize_stepwise dec_raw_frmsize = { + .min_width = W5_MIN_DEC_PIC_8_WIDTH, + .max_width = W5_MAX_DEC_PIC_WIDTH, + .step_width = W5_DEC_RAW_STEP_WIDTH, + .min_height = W5_MIN_DEC_PIC_8_HEIGHT, + .max_height = W5_MAX_DEC_PIC_HEIGHT, + .step_height = W5_DEC_RAW_STEP_HEIGHT, +}; 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_frmsize = &dec_hevc_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_H264, - .max_width = 8192, - .min_width = 32, - .max_height = 4320, - .min_height = 32, + .v4l2_frmsize = &dec_h264_frmsize, }, }, [VPU_FMT_TYPE_RAW] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422P, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV16, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV61, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV16M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV61M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, } }; @@ -234,74 +215,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; @@ -389,6 +302,8 @@ static int handle_dynamic_resolution_change(struct vpu_instance *inst) } if (p_dec_info->initial_info_obtained) { + const struct vpu_format *vpu_fmt; + inst->conf_win.left = initial_info->pic_crop_rect.left; inst->conf_win.top = initial_info->pic_crop_rect.top; inst->conf_win.width = initial_info->pic_width - @@ -396,10 +311,27 @@ static int handle_dynamic_resolution_change(struct vpu_instance *inst) inst->conf_win.height = initial_info->pic_height - 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); - wave5_update_pix_fmt(&inst->dst_fmt, initial_info->pic_width, - initial_info->pic_height); + vpu_fmt = wave5_find_vpu_fmt(inst->src_fmt.pixelformat, + dec_fmt_list[VPU_FMT_TYPE_CODEC]); + if (!vpu_fmt) + return -EINVAL; + + wave5_update_pix_fmt(&inst->src_fmt, + VPU_FMT_TYPE_CODEC, + initial_info->pic_width, + initial_info->pic_height, + vpu_fmt->v4l2_frmsize); + + vpu_fmt = wave5_find_vpu_fmt(inst->dst_fmt.pixelformat, + dec_fmt_list[VPU_FMT_TYPE_RAW]); + if (!vpu_fmt) + return -EINVAL; + + wave5_update_pix_fmt(&inst->dst_fmt, + VPU_FMT_TYPE_RAW, + initial_info->pic_width, + initial_info->pic_height, + vpu_fmt->v4l2_frmsize); } v4l2_event_queue_fh(fh, &vpu_event_src_ch); @@ -545,15 +477,16 @@ static int wave5_vpu_dec_enum_framesizes(struct file *f, void *fh, struct v4l2_f vpu_fmt = wave5_find_vpu_fmt(fsize->pixel_format, dec_fmt_list[VPU_FMT_TYPE_RAW]); if (!vpu_fmt) return -EINVAL; + return -ENOTTY; } 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.min_width = vpu_fmt->v4l2_frmsize->min_width; + fsize->stepwise.max_width = vpu_fmt->v4l2_frmsize->max_width; + fsize->stepwise.step_width = W5_DEC_CODEC_STEP_WIDTH; + fsize->stepwise.min_height = vpu_fmt->v4l2_frmsize->min_height; + fsize->stepwise.max_height = vpu_fmt->v4l2_frmsize->max_height; + fsize->stepwise.step_height = W5_DEC_CODEC_STEP_HEIGHT; return 0; } @@ -576,6 +509,7 @@ static int wave5_vpu_dec_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); struct dec_info *p_dec_info = &inst->codec_info->dec_info; + const struct v4l2_frmsize_stepwise *frmsize; const struct vpu_format *vpu_fmt; int width, height; @@ -589,14 +523,12 @@ 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; + frmsize = &dec_raw_frmsize; } 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; + frmsize = vpu_fmt->v4l2_frmsize; } if (p_dec_info->initial_info_obtained) { @@ -604,9 +536,8 @@ 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, VPU_FMT_TYPE_RAW, + width, height, frmsize); f->fmt.pix_mp.colorspace = inst->colorspace; f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; f->fmt.pix_mp.quantization = inst->quantization; @@ -718,7 +649,9 @@ static int wave5_vpu_dec_enum_fmt_out(struct file *file, void *fh, struct v4l2_f static int wave5_vpu_dec_try_fmt_out(struct file *file, void *fh, struct v4l2_format *f) { struct vpu_instance *inst = wave5_to_vpu_inst(fh); + const struct v4l2_frmsize_stepwise *frmsize; 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 +660,19 @@ 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); + frmsize = &dec_hevc_frmsize; } 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); + frmsize = vpu_fmt->v4l2_frmsize; } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_CODEC, + width, height, frmsize); return 0; } @@ -748,6 +680,7 @@ static int wave5_vpu_dec_try_fmt_out(struct file *file, void *fh, struct v4l2_fo static int wave5_vpu_dec_s_fmt_out(struct file *file, void *fh, struct v4l2_format *f) { struct vpu_instance *inst = wave5_to_vpu_inst(fh); + const struct vpu_format *vpu_fmt; int i, ret; dev_dbg(inst->dev->dev, @@ -782,7 +715,13 @@ 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); + vpu_fmt = wave5_find_vpu_fmt(inst->dst_fmt.pixelformat, dec_fmt_list[VPU_FMT_TYPE_RAW]); + if (!vpu_fmt) + return -EINVAL; + + wave5_update_pix_fmt(&inst->dst_fmt, VPU_FMT_TYPE_RAW, + f->fmt.pix_mp.width, f->fmt.pix_mp.height, + vpu_fmt->v4l2_frmsize); return 0; } @@ -1005,6 +944,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 +958,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]); } } @@ -1568,20 +1486,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, VPU_FMT_TYPE_CODEC, + W5_DEF_DEC_PIC_WIDTH, W5_DEF_DEC_PIC_HEIGHT, + &dec_hevc_frmsize); + + dst_fmt->pixelformat = dec_fmt_list[VPU_FMT_TYPE_RAW][0].v4l2_pix_fmt; + wave5_update_pix_fmt(dst_fmt, VPU_FMT_TYPE_RAW, + W5_DEF_DEC_PIC_WIDTH, W5_DEF_DEC_PIC_HEIGHT, + &dec_raw_frmsize); } 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 985de0c293e2..ef9aa1562346 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -11,65 +11,60 @@ #define VPU_ENC_DEV_NAME "C&M Wave5 VPU encoder" #define VPU_ENC_DRV_NAME "wave5-enc" +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 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_frmsize = &enc_frmsize[VPU_FMT_TYPE_CODEC], }, { .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, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_CODEC], }, }, [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_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .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_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .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_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .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_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .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_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .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, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, } }; @@ -106,46 +101,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 +315,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; } @@ -391,7 +341,9 @@ static int wave5_vpu_enc_enum_fmt_cap(struct file *file, void *fh, struct v4l2_f static int wave5_vpu_enc_try_fmt_cap(struct file *file, void *fh, struct v4l2_format *f) { struct vpu_instance *inst = wave5_to_vpu_inst(fh); + const struct v4l2_frmsize_stepwise *frmsize; 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 +351,19 @@ 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); + frmsize = &enc_frmsize[VPU_FMT_TYPE_CODEC]; } 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); + frmsize = vpu_fmt->v4l2_frmsize; } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_CODEC, + width, height, frmsize); f->fmt.pix_mp.colorspace = inst->colorspace; f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; f->fmt.pix_mp.quantization = inst->quantization; @@ -499,7 +450,9 @@ static int wave5_vpu_enc_enum_fmt_out(struct file *file, void *fh, struct v4l2_f static int wave5_vpu_enc_try_fmt_out(struct file *file, void *fh, struct v4l2_format *f) { struct vpu_instance *inst = wave5_to_vpu_inst(fh); + const struct v4l2_frmsize_stepwise *frmsize; 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,28 +460,26 @@ 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); + frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW]; } 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); + frmsize = vpu_fmt->v4l2_frmsize; } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; - + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_RAW, + width, height, frmsize); return 0; } static int wave5_vpu_enc_s_fmt_out(struct file *file, void *fh, struct v4l2_format *f) { struct vpu_instance *inst = wave5_to_vpu_inst(fh); + const struct vpu_format *vpu_fmt; int i, ret; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", @@ -568,7 +519,15 @@ 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); + vpu_fmt = wave5_find_vpu_fmt(inst->dst_fmt.pixelformat, enc_fmt_list[VPU_FMT_TYPE_CODEC]); + if (!vpu_fmt) + return -EINVAL; + + wave5_update_pix_fmt(&inst->dst_fmt, VPU_FMT_TYPE_CODEC, + f->fmt.pix_mp.width, f->fmt.pix_mp.height, + vpu_fmt->v4l2_frmsize); + inst->conf_win.width = inst->dst_fmt.width; + inst->conf_win.height = inst->dst_fmt.height; return 0; } @@ -584,12 +543,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 +576,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 +1117,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 +1422,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, VPU_FMT_TYPE_RAW, + 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, VPU_FMT_TYPE_CODEC, + 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) @@ -1733,6 +1694,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..3847332551fc 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.h @@ -38,10 +38,7 @@ 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; + const struct v4l2_frmsize_stepwise *v4l2_frmsize; }; 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 e4bc2e467cb5..1ea9f5f31499 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h @@ -32,10 +32,29 @@ #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_8_WIDTH 8U +#define W5_MIN_DEC_PIC_8_HEIGHT 8U +#define W5_MIN_DEC_PIC_32_WIDTH 32U +#define W5_MIN_DEC_PIC_32_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 Aug 12 06:29:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13760168 Received: from PUWP216CU001.outbound.protection.outlook.com (mail-koreasouthazon11020119.outbound.protection.outlook.com [52.101.156.119]) (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 6398714EC4C; Mon, 12 Aug 2024 06:29:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.156.119 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444177; cv=fail; b=L6ZYnAN4c39a2vzaloVwUH/AL13/0ZboOleX45iPrqSFE046VvqkJ89GsxojhcLM5kXy9y85Kjr/4JN+5pDICBgCwGv0RVyvhqyvxISfvc/3zkLxZiEmUjSFCTnL77qu0FzCMuHI9B1UUwxIYVXKlSjS3aXYjERk/95t2Moi5JU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444177; c=relaxed/simple; bh=UiTOsuIPdnjFiy25DGycvOoGT0s1iFeQjnnlxcQCqy0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=LRo/tAezfMNIF43410TxDcHK9RxeRbgRz/Jw3YFwv1DJlQ2jdlotpjtutIgoRYN8mPbsUQy1f/ahtW7FgcjU+6J8lvsa6lzo4XWO83HCK89HlQf1FEcNEXER7RB8O768X+KZ3WpjpvyI8aizoztJePiGGugoVH/1F3XxmTjvNlI= 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=TZVJBcmG; arc=fail smtp.client-ip=52.101.156.119 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="TZVJBcmG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D1q59LUIwziAYptdqRhrM60CFmGnXrv5iUXlAH1hSEOTpnMQMNPLbmCQYLGAdGy97D/mBqPef8N4r2hhjU0W6JQCdcNwlsbKrUWZIgdqQbJkKdMqPncKZFBxsCqftxiLRfOMS1Az0/lGd9NPPEFXQl+7XZry7iz4okWnOye7sSDD4nrMfItm/kYbYpeTKpqxKaXtb8Px8HVUdQgR6N0b47SUm9NH8yfXCQy0LaSBnNUqq3tQH4ivQYKqXPvaE4umuzBzVx4QYS69AkMp4KCf4s5u0+gOOANMHKX9cPpyQ3VpFGgHkEYhZ4VyWSf3qzZ+l2TbwqK6D/YCcBtWcsEfHA== 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=Jo09o0f7cArhs9nmYI/Ipzy2U9tnqhbP6xrDVuSq5UU=; b=l977/YEY4SJ5SKFb7YHtq+WivAIsFXbGvT6keaDkpOjt3KJ6OHzbapxBjq5M7pU2iuJbazGuqeZbjo9jAu/dLxul7ZjuKipVv1EqAY9ea5aRMyHgrVlyjpV058VwFtfXOwejB644NRaJgeB3PnUGc7HnhqM6k1lgBNTww2tUWdchugX1v3IFsoEIRP7PtKOghGe91ohvHH7vp9Kq9u/ASkVmS1B0j3UzgE2eUBmHcK8CKkbR6N1Bggz0+1XS0T/F0BZJyyxbcfdaaU0tDjAIBey7LmYBKcECq2CiiPc90P/Rtqyod+SBeHij0CPWS3Khpb+nep2Mx/iF5CQBF8CHyA== 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=Jo09o0f7cArhs9nmYI/Ipzy2U9tnqhbP6xrDVuSq5UU=; b=TZVJBcmGtysyePzS9+vmhdmwjeQxEDwBP4Y6oNIO53ze7udvaZm4izlZCAQ5e7QFMf7Lj4TerMpWOfviaDsPsBnD1GhtS1uXZpQG8D2xTdosKhk5XfLld0GmY4DVP8faCV/0RBRjeGFBUdGSi4Tsopv6khvpFAMPfLAdKxpNOtA= 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 PU4P216MB1820.KORP216.PROD.OUTLOOK.COM (2603:1096:301:10a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.20; Mon, 12 Aug 2024 06:29:30 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%7]) with mapi id 15.20.7849.019; Mon, 12 Aug 2024 06:29: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@chipsnmedia.com, Nicolas Dufresne Subject: [PATCH v7 4/4] media: chips-media: wave5: Support YUV422 raw pixel-formats on the encoder. Date: Mon, 12 Aug 2024 15:29:19 +0900 Message-Id: <20240812062919.78-5-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240812062919.78-1-jackson.lee@chipsnmedia.com> References: <20240812062919.78-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SE2P216CA0044.KORP216.PROD.OUTLOOK.COM (2603:1096:101:116::11) 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_|PU4P216MB1820:EE_ X-MS-Office365-Filtering-Correlation-Id: d2ecd6be-7308-4a18-e2eb-08dcba981f5c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: ezaOQYpAA0kGWgIQsS2fUrTDH5J1aZafntAr+cyF6KATs330GcQU1AYXJF3h362gp+3ZEZGR1DWSM7d+/6OkvmD/BWCryQ3kxXinEXnMaUYY9/my9M5TShkWVUTEK5nfKiMipHROPrRMAqgsQXtEnPA09bXI9ia51V1fZANx0tqOuKuVpaBc3hK34NXOaF5gei6vZFNhz1i/OGnmeUs63yZu+PDv6ZaDgkRUTaWxQCZmJiHLU8fsMR6WTs8WGbOt6N0/1W9WSmwO+AM28AtfE91gASqYwS5KeULADoQ6Xv4KGtG733R4rI+I77ogH26n5sh5brGtJ2R5vpM62UrPd1xRkBQx/3MNTPHxvdmZsqaWlZa4XHCN3y9CicuYEkx5LrpJ/yE2Lou45nQCZVFIf0WAU2IR+kODl2yjRK0o8qwTW7vbXga8RGWJCf1zm770N8syjWtc37no3R4rtusd1ak0bxWYMyenSLIxadUy7AU1CrGXlP6BmWodh8z7+Ep6hdRgePFJw6y/KM6ont4CeUQIoVO8kfLg14ZuFjRq3/tmCY0PMOkksUuHDLAiit+Uj4mA1PzebModB1SxVs8ZUug3IfIzyW0PWIQHIn0jpsEx4F1096aMKlZX0nBs8xSNCG3+TTwPfKvAw0y8EABZFZo53XW2Jj+IbbwKtlK5rDldS0l2SvS2SJu9U05hE1qvHZtC9gIrjt+xwpBAptScMVkIEWc0PrCt2ICYji0lnuiCLPJhGZaHPMVywV4iDa+hwbdNuTlA19xiJcE4S95SpmLNB0QsQpLSoi4LNqePCUeph7dP865/+m+b95bFDgrXEct4ECLtWyY0CG9aosbPzPZEbVFXyxrRGu5fheK5MWdV1sKYaJDAfB1vNwYTwM3l/flG1ckiHHpnmzy3iRoNCe1pAR/kGZ7b3mc+cqeH8dcXHiSbNZE3c+kdrx5IJHYAQbgDzdXICrkfeXtG+QHyiVj0XnyTmfe9samOmgvWxfn1/ozAIHjGXWSlajPfyF77arVtg13UeQRwI1WRqPuoVVKooA/B0yAUPqAN84yZlqX9tvUkPoOUC0SA7b1ljwfVwBJvTKmi0suR6S5GPmgrXST2eIHPjbcCFnOocpklr1xOiji2wnJcNLYaC8nwm2XA7iAnNqcq1DkJl8TvBtnC2sltJeg5435czAblh5w8ctl45Y/sZGBrdkiRV0KZ8KigVLSTTrPTfYYA7gBAt/uNFvorQerYp5CQu4DtiGzabZU640U3n4YHQ+7Vy0i68oiV0ISEJiyV5fO5YSGrrPf0oLgKWagdDrIYPmbxuxiPmnK2vL5GVxktqGaEuBgT5LSXf61Y/7JGgxl+g5OTtp6Ry9yTI9GZmKuI8JPk+q5Z3UIoZF5bO2T6SSBLymfSpONCSmalF/lIc8cLUx95yoT1ag== 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:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VAETeMK1vkV1wwwdAUP3WUmISaeKOXF5hl+EI4+2Q0ek68ctmjJey1e7/xYlhdrvIp6fVlStKq1wJDCEAd728ApW1eeE53VNkeY9DYuokw/Qv4xHWM3fHB4ux0KZRaZFTK6VxBpkloccqLSmJdAQncRcWKL1dcOzplZ9CxKtk8WQbEz7isUGn6pP5C01Gh8ua2K33r4W1k6eakAP21yM6R/QXS+EjNO9NmJv/G8mz6f62IBEvN2F97mVUOirFXIvqq6TVfVALd8uxSbU5StZDWu+OGrC3siC/TGoVEXzTao9MN8njvRzfqNn6lcsB70fquOFpTpAxvNx47GxcmdTRUwgl29Qh8LDL8DTGrSp+1GcTwZ14IHS+pZj18rBtm9txWeG4M9IAr/9iI8jV3w07TbPnYLX+9QImCyDh/vsQ1gmUfVy4UtUYGi+Zl5qm33Ctoqga6RNUt2yWja0RSpdTPuXLR/A8yhvvhqEESrd9ESiK5Xg3yrlsvpRMkx3i+BtuzT8XHSS9wptJov3SlqLGQ4DFEBwn4RoNkRuqO8/le3rSKuOClPA2x3tXAohZZrB7O/ik0Knt3xl+aRZTjCgbgBbQ5njJ5BNaKrOV2pZy8R0qFObXcVB1+kc3Wq6xv5kyJH/jbKej8yEXc952zI8p19mgPYSy5ETxSiUPs37t2EzFqtj7KOCR0pOFu31Ba5uajsQ3VlzeH+33v4fGlTqRLru7qodRQN/WOKKHBWATmfcvSZQHFlwCcEwP+yv7C0HKDn93bxn70khv2e9uVqasxRrB6bgcv7UfQmT9xtbimE/5WvzZKxCooRDxgLNMM7f0b6kpDQ15/8XQequxmIVue7V0BAjxBUVCJF2y9Rl2JK0wQFmKW5+y7hvsrJLs/WYrtFMwGicG8UcdThUDIdrSGEiBE9LVpBjfAdnpSZnP4Xv20NXFUq0stTDBT+7P+bK8jG6Dn5OYfJ7VI1v0HDK4Ligebjymt0ZwAcjBBe2jnJn68iwNsp1ODt4KfkPDdv7dEC/C35zC84LlQ4s6t7lRVzLcjGH6U7cbqjLBpURrxf4ebA9SMbXt5aNsK8v4jTjEP9dgqFs4JNmi539O2JzrcF2hsqT5AIq/8fyRoH6BTWCArmhgs1OeDO9BCD5s7l3cv65wHbMEcqFCzkI0GJTLTF+o7EI7tcrQh3WbPAgdjvmvdAls4Vkl9IhCb36shAsSnTPLFpLvtuzUTDmPvTm8IJIdv2m28m1YhVMDciGpp60jM7VRTsEbybu39J/fpkYMCer5HeEbRCI5+jL8mecUstIzy1IpfeHgCxqO/b+0B4AkxAW35H9y+7lgaJ/7TMrkSYJHB4I1PquzajUilI3OlAHmpmnmCwA2kc4DG4+0ojaC1GL4p05rv9e0uRsDu2a77ZdkM4z7ri1QsoT64xZE9moZCH+ezKEFAAavPVfRQDDVHvAjf/vbBj6lXJqduPkPYnTA3MFleS+Wtf8N+0S4f6l5H/IjoXVGlWLGvdwy0trynYQtylMeMB7MY3gxBEqMzkoXOK5rRPXIqriJrW6xcNDFBN5lyVncmZ/SixJ/dD3WQPkKb0hnjc1uOea9M/DMDFsyYybp2gUy76+Lk4WWw== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2ecd6be-7308-4a18-e2eb-08dcba981f5c X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2024 06:29:30.4611 (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: vDAXNhe058SEoIlARkU7Fc5hsG2gadU21D2Z0xVUbsiVU3Vmn9Un/zjsNQzlYjLdkvEX/yfrWtC4yvZ6JX1718yAIgrvTd9AWFPMWnRuH3Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU4P216MB1820 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 Reviewed-by: Nicolas Dufresne --- .../chips-media/wave5/wave5-vpu-enc.c | 89 +++++++++++++++---- 1 file changed, 74 insertions(+), 15 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 ef9aa1562346..4e1c8a4e7272 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -66,6 +66,30 @@ static const struct vpu_format enc_fmt_list[FMT_TYPES][MAX_FMTS] = { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422P, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV16, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV61, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422M, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV16M, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV61M, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], + }, } }; @@ -109,13 +133,26 @@ 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)); + const struct v4l2_format_info *info; + u32 stride = inst->src_fmt.plane_fmt[0].bytesperline; + u32 luma_size = 0; + u32 chroma_size = 0; memset(&pic_param, 0, sizeof(struct enc_param)); memset(&frame_buf, 0, sizeof(struct frame_buffer)); + info = v4l2_format_info(inst->src_fmt.pixelformat); + if (!info) + return -EINVAL; + + if (info->mem_planes == 1) { + luma_size = stride * inst->dst_fmt.height; + chroma_size = luma_size / (info->hdiv * info->vdiv); + } else { + luma_size = inst->src_fmt.plane_fmt[0].sizeimage; + chroma_size = inst->src_fmt.plane_fmt[1].sizeimage; + } + dst_buf = v4l2_m2m_next_dst_buf(m2m_ctx); if (!dst_buf) { dev_dbg(inst->dev->dev, "%s: No destination buffer found\n", __func__); @@ -480,6 +517,7 @@ static int wave5_vpu_enc_s_fmt_out(struct file *file, void *fh, struct v4l2_form { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + const struct v4l2_format_info *info; int i, ret; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", @@ -501,16 +539,20 @@ static int wave5_vpu_enc_s_fmt_out(struct file *file, void *fh, struct v4l2_form inst->src_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; } - if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV12 || - inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV12M) { - 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->cbcr_interleave = true; + info = v4l2_format_info(inst->src_fmt.pixelformat); + if (!info) + return -EINVAL; + + inst->cbcr_interleave = (info->comp_planes == 2) ? true : false; + + switch (inst->src_fmt.pixelformat) { + case V4L2_PIX_FMT_NV21: + case V4L2_PIX_FMT_NV21M: + case V4L2_PIX_FMT_NV61: + case V4L2_PIX_FMT_NV61M: inst->nv21 = true; - } else { - inst->cbcr_interleave = false; + break; + default: inst->nv21 = false; } @@ -1095,13 +1137,23 @@ static void wave5_vpu_enc_buf_queue(struct vb2_buffer *vb) v4l2_m2m_buf_queue(m2m_ctx, vbuf); } -static void wave5_set_enc_openparam(struct enc_open_param *open_param, - struct vpu_instance *inst) +static int wave5_set_enc_openparam(struct enc_open_param *open_param, + struct vpu_instance *inst) { struct enc_wave_param input = inst->enc_param; + const struct v4l2_format_info *info; u32 num_ctu_row = ALIGN(inst->dst_fmt.height, 64) / 64; u32 num_mb_row = ALIGN(inst->dst_fmt.height, 16) / 16; + info = v4l2_format_info(inst->src_fmt.pixelformat); + if (!info) + return -EINVAL; + + if (info->hdiv == 2 && info->vdiv == 1) + 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; @@ -1190,6 +1242,8 @@ static void wave5_set_enc_openparam(struct enc_open_param *open_param, open_param->wave_param.intra_refresh_arg = num_ctu_row; } open_param->wave_param.forced_idr_header_enable = input.forced_idr_header_enable; + + return 0; } static int initialize_sequence(struct vpu_instance *inst) @@ -1285,7 +1339,12 @@ static int wave5_vpu_enc_start_streaming(struct vb2_queue *q, unsigned int count memset(&open_param, 0, sizeof(struct enc_open_param)); - wave5_set_enc_openparam(&open_param, inst); + ret = wave5_set_enc_openparam(&open_param, inst); + if (ret) { + dev_dbg(inst->dev->dev, "%s: wave5_set_enc_openparam, fail: %d\n", + __func__, ret); + goto return_buffers; + } ret = wave5_vpu_enc_open(inst, &open_param); if (ret) {