From patchwork Fri May 10 06:58:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13660950 Received: from SEVP216CU002.outbound.protection.outlook.com (mail-koreacentralazon11022018.outbound.protection.outlook.com [52.101.154.18]) (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 BB1BAF9C9; Fri, 10 May 2024 06:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715324314; cv=fail; b=FumJeCvBE/jH0EkvSBu4hrZoir9YyHSVdlcSWEPkQu57UjV/+vorlIHia6Vm0J4g+rjFpiHMn+Nq6IPkKwyJ7p6FkJcd1Yg/r71oQ4Pw9ZAtkJzgSDF8oE5wu72rI+7VTvjUjjVmHF4jJyVqmtGeBKFxCq95Sj2ho9HuhdR/shA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715324314; c=relaxed/simple; bh=lrEi0r97o8Y/xoHGwh+4ip2R0DIFHkyP/JQtkN8aDZQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=mkPQqxEJdA648+0dO6Oafs6zUjBoP8KhneVO3MxZwnMhMOvXO7D3+jgVvuLewWSWwIiaodpdeyO3YpZLJuOWSjtBQKDf4o8uS0gys1ltDLW13kHYeG0RzVsZaZZrBPl85gVvz1MSa+9FAPolADyg1Mqou0oBqKRBZnXcC7KqtzA= 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=HiZ4I+7L; arc=fail smtp.client-ip=52.101.154.18 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="HiZ4I+7L" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TE7EgQYSxjV1Pg3CMsu7656JYjcAzK+XpBSpykjblTLRxmXKLi4dmgzqXaayIpl+C4N8OYIBuCNdxTfHF2YQKX5blD3m2yXQxdYUSqYsVRxkYVuP+0SIN86KELhS7Q+lFbLMFpdAaMONl5yXxKDtQ2vsI5Klw42lS3Hp5yGDc6k/SR0PLajEE1Xyr5i03KrtoFeZRLMFfEhFEPCi9Q2z8frdkk8tsh/TsgPEvL0q4hI2BX6HQL6Xj/4FZ3bSlSCd8EUEtpgaSXHKvzjTu40zef/t6ca/0gYwKcz/InqTDVAOM1GnexLwC63SeAkcYunPDCkDgrEHnLShD1B9cYgnFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vACLLSZhrmTQO90kzFV39ILswOgXNXFuEX/8TwheFwc=; b=HEFffC+U7DkQ72fTkN9AuCisQSKTU7z2J4njuaWs1LGCoipb46kbsO+U+J/7k7+/KIaWOE429/TWNTAKqYYHP7RbuIHe/jq1lvz7On7AHzxaOxMDHR7fJrJXrQdEkdK1fwYVwKcu8Rt59tLzxenM0hdNseraKRagWHpkx5k06xI0RM2m7pvVmFD0LBB8K7qavTWRnFBOPigfjFl1HbA5iTufagJlOILGe/qkoBUrNqDP2I6zgfRYgF2IC7fyg/KjcdGS6iScPMDE/h6zRhrRTgS6fFtjk2awqCWOyZuOGy4e4Neqk57ipgSLF/C9l9qGU1fUDM4z9494xKn8P1imig== 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=vACLLSZhrmTQO90kzFV39ILswOgXNXFuEX/8TwheFwc=; b=HiZ4I+7LGCzQC40Ixwt4Srv4+n1v986AuVlbnvSk1ykmra8yWUAZ6jwD5lIdptKVsHJertIgLRZ3ZxbJtrn+OETc8xlWoedCu+fz7imgbHAMDIOUNjuXu5Evn6gSPv19Y8fdweomithiXd6RQQmRoobbdKZnz3wJnjGcCSHnQdo= 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 PU4P216MB2247.KORP216.PROD.OUTLOOK.COM (2603:1096:301:12c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.49; Fri, 10 May 2024 06:58:28 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%6]) with mapi id 15.20.7544.048; Fri, 10 May 2024 06:58:28 +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 Subject: [PATCH v4 1/4] media: chips-media: wave5: Support SPS/PPS generation for each IDR Date: Fri, 10 May 2024 15:58:14 +0900 Message-Id: <20240510065817.743-2-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240510065817.743-1-jackson.lee@chipsnmedia.com> References: <20240510065817.743-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SE2P216CA0033.KORP216.PROD.OUTLOOK.COM (2603:1096:101:116::19) 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_|PU4P216MB2247:EE_ X-MS-Office365-Filtering-Correlation-Id: ae64c846-3e84-4f60-8393-08dc70be97c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|52116005|1800799015|376005|366007|38350700005; X-Microsoft-Antispam-Message-Info: srDc4y0PpdD3JNAHe5xY0UKXFkdxXNAjjqLzMZ35H4sGG+FrJggXMwd+XRPdClfkDzNs4WDrytwmYOFdAmwkDx9ZDKcim4S2aRXGvvCp6yy1T2w1mN6vZqaNZxToUju3NgOwpAt65AxtsnJVCs1njFw/d2bSN3B54VrMbi8AK/AY14xipIisw3x6zG7TQ3I5dp+oDO8ejUT5bq485dt0knhefi8ngKSfcdPbh9j7Wj6p3KNDi6UH2bxatckiDFNNeHwbuHdN37g4GR0+FG21H9YYLvK7wdzAG98XLKmvA5E3KXtCgXs1YO+eY0LSsPdzYPKJ0LZjnXd49FUSuDnbOdjkVUk0Swyrs6GKKAKxN0m24Y2+DDh618g23WMSr4FfBnjzL0AmELekwlNkTnBz5Cl3Q2GzkhjWOrJmZcW5IJAl2XKXTA+LlOEnESRVCiVTFA9frS3sSKfApv/sCNprqx/xGOJLbZnO5YdP9eLacGToyfJiZIfagu+18VzYAqgmv++2NJCyj8yy0qSIgH5paGf+T0HZs3EJzNqRtV07D4u2m7re6CAVPBBIrGYfeFB3PxJTtAL/T196GB9utcDblLdMxJuKcoWkpWAHTFUQy9ZgKZBTif2XGwa76U12Hnk6+XlOam41fG6J7TZjlqBhJgzbt0eertcIdOk0qSuh/jQ98bcFuO/oeUMWRaLM4r53n22Kbd/5vxWJA5Lg0b+tC5MnKeNaO8aWY5AnYLbnbEXJ4na8RO0VaupFG3Pn6X4RVZ5wE5ptkq7+bHd/mcKhuxfwsbIdeAy7r7OA/amWb66NBi9idqDJfa53jtcBx4QA7uw4IlG3gBnA6HAuytScld5YElRFpB05K/S27UKW8P/8i86tCIaKn25SC87KIC8VtuptR0WjgK4jJwu+QwR1JbHUoWpEqXkEPayaiGH0PziVrE5yf/FBBuiWf3brVWvPit0K3pB7Iz3SfDIfJGw2mF9uw8aIGKnxJ9eRq7bH48kBScN7TjfEZHE13JrKLWlOPu1GCE/2tqg0Mxn2Tu/Zdfx/uw+94n5py+EH0rYN0enkSZnFBIQrziOa2tUD72th9uHDIJsh3Z10Fn1g/KsuCkx5jfa4jR+9hamGr2W4TeXK1PVMI7KaUpywUpZ78Z/eHIgguJUU8RIXcleXioZU5Z1bli+mjyxpIzlDPMaKxsIVAiBtX/dtL6Rf7uwgFaOZRt75tCxh5D96n3u17PfpoXP3Za8w/WPUhPkPzCz89txY8ONWb3X/izQnEKE1SVMAqnMFExnK18EdwkNVFuH6in0sS654Rz2vsIzZbNWZxSlzbxvSQ09bEejvz+7L7+/7fm3hzYaYLUW6pvKutUm32Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SE1P216MB1303.KORP216.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(52116005)(1800799015)(376005)(366007)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4HfdnTcsr0k6Vj+VJKPla8xms4BdexhKrFByIvGjSvQQr60RP4jgvWUzVDxXWAEglEYICFln/1K/O+X6jbyIbd7fPWSKEgNscxoCBNQqvjYWfaUwbVwOt/GuzPO6c8kp+Hf4P1LhZkaJDcHV6RGnjHviaDkQSwS+6ZRDgFvZJe3HrOfY/O/pNnb7AT60WhXxSErCQZ3C8Rkq1NR9jHKVMqLklKZkHpw7cXlKHpcPHvP3eVV22ajc6ZSq2EVPNtu/XHmLpgQeyuMkCz5GEls4Nj+sx+YdYO3YU1EoO+nlbClmC66Gcs1lI94mImU2TmXVD0Vg1IWsLz2cLBasnAASy2CKvRNpQkxpURmi8e48ekqRMU01vfB5GG7Jg0pmrJt1VKd5lgj3XQsUB25lCjaqpcaHP6TWquqvIySd0oGOVYENpAmQZ6BQoN3zL09TXD3hJ0ohtNIwyYAgfJQXa51z6vn7+Fzb+hFKR5XkkaVk0CstaWDh0kQXmUM9piSvijmT973yXe8lvDUZM7gouVsV3N75mpRnACJTlEvcAA7pHc033Avt7XOw+s5iGIH3fEG7cd37ZM4SeIbcN8i10iHFPashtbjxJMPegFwUpsbq28IqTQtAfCVofIbyWWkJThNBsF6lTxhSUZ6av8HDynvPnL+WU8AB/j2xMXmlUkybuzBrBNHPhbp2U6jzHRu+wD3gpftv4tVd5JvvQWZFQNA8hQjBQTo80uED4NWkTZpfdS9ytlP5cIfEFTPPTcO74nob7WyD9JozNUm++hUIsSi5ktdQwAu6ywII1qDFljaGfOXp2BTibkANgGVDeA86gO1w4IPiWf8NvbfNGQXVBh7qGVNaohig6/C4ncKl+7zcDc1SURpTswZ+kk+r4A/IeX6O1kQAQrTvQ8ZgNuNsRAPqPtvt/0MpW0CkIzzVdMthKSlJS0e3aNHSd/Yek/3f1P2cSax+6t7WYfvMP6qe3M9wgHaZ0ACHbA71pHZAxHtnH7fBEE+UjRaUYnMXiDLo/nmZ5IedRON+M3ibjE+z9+e7bL1fKQmYyYM4/vQmCi9G0F2lJgfqVpWcWmAWZRXN1/S8bgapoWGhwWhylSX7/oyyC5GlilwlXDwY/FWlGUErMPbWTgPrrRZSudTn79Ul6Os5KSV1Sftdtx93/zEPRpxzrP5oezoWVuPaozwMxnDlfDRn23je5R0vrcPYjbwiD/dFMLy7XxGlGRpzdKIhXQN5Az1t4xphWhlvH7OA9XYUuexQY9jJywSV29NMJ/c0x9W2TITidB3xJn+xey0mUKQ+5bkXuoScKTIoz7hBLkThDQblj7kVphpvva1NNbC7uRfoXCNXUt/xSfH45jx64elQtrS9xArsHUXOfQFWtRe5oTYj5g25UdFevGq7niPc9yS1GdQK1N+HvF2s+b8Ggh1ox5n8loxmmWkYWFnRpivzydvJIOtIwMcVVJNbKwdwXaKXBLsyOGBJH5npHwCACYAnAEAiD2oL9y3Yd5b0cAJJU254PVyS3w4WUoVRycAy8u5XcwHwBL58ll4nDDopgLxrTN0OXTlsLwjb7AsMMQkpkdJOLxBAyU58/xDyRSa9NB0Mu1sKM5jFB0JSMSt3Ll+z1Q== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae64c846-3e84-4f60-8393-08dc70be97c2 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 06:58:27.3002 (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: 9E7XLRtv87sEAJmEw3oQ3Iw6fNTy7H1Bn/ll2Nke4us/3TwjXZbk8oDqvg8tSKjd2mDUX6QTX2ul+Uv5LvVaJ/qcieWm41Krk3lEV/GfRW4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU4P216MB2247 From: "Jackson.lee" Provide a control to toggle (0 = off / 1 = on), whether the SPS and PPS are generated for every IDR. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung --- .../platform/chips-media/wave5/wave5-hw.c | 19 +++++++++++++++---- .../chips-media/wave5/wave5-vpu-enc.c | 7 +++++++ .../platform/chips-media/wave5/wave5-vpuapi.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-hw.c b/drivers/media/platform/chips-media/wave5/wave5-hw.c index 2d82791f575e..fff6e66b66e4 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-hw.c +++ b/drivers/media/platform/chips-media/wave5/wave5-hw.c @@ -23,6 +23,15 @@ #define FEATURE_AVC_ENCODER BIT(1) #define FEATURE_HEVC_ENCODER BIT(0) +#define ENC_AVC_INTRA_IDR_PARAM_MASK 0x7ff +#define ENC_AVC_INTRA_PERIOD_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 FEATURE_AVC_DECODER BIT(3) #define FEATURE_HEVC_DECODER BIT(2) @@ -1601,12 +1610,14 @@ int wave5_vpu_enc_init_seq(struct vpu_instance *inst) if (inst->std == W_AVC_ENC) vpu_write_reg(inst->dev, W5_CMD_ENC_SEQ_INTRA_PARAM, p_param->intra_qp | - ((p_param->intra_period & 0x7ff) << 6) | - ((p_param->avc_idr_period & 0x7ff) << 17)); + ((p_param->intra_period & ENC_AVC_INTRA_IDR_PARAM_MASK) << ENC_AVC_INTRA_PERIOD_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 a45a2f699000..a23908011a39 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 edc50450ddb8..554c40b2e002 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h @@ -566,6 +566,7 @@ struct enc_wave_param { u32 lambda_scaling_enable: 1; /* enable lambda scaling using custom GOP */ u32 transform8x8_enable: 1; /* enable 8x8 intra prediction and 8x8 transform */ u32 mb_level_rc_enable: 1; /* enable MB-level rate control */ + u32 forced_idr_header_enable: 1; /* enable header encoding before IDR frame */ }; struct enc_open_param { From patchwork Fri May 10 06:58:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13660953 Received: from SEVP216CU002.outbound.protection.outlook.com (mail-koreacentralazon11022018.outbound.protection.outlook.com [52.101.154.18]) (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 E40DF15EFB7; Fri, 10 May 2024 06:58:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715324318; cv=fail; b=X1Z/hEkXCPDBVvnDBSDzCuGStU8Lm35zXCbjrSjq7Lip35mD3ZKD8VWOZNK9j2lzkbVXQkeNA3s7yliRAG28Ua9qRfbYIEgZhhS9J0DLhYZpouZL4UsmDKbveou90OdUwukl/CBuQ9MKhQzqhQ/yWTS7GGHn82tr1Um1Wt/DUc4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715324318; c=relaxed/simple; bh=xZjC5Ab4JmVwWF4Uog4CgivMX3blp6oRo08rwmQXU6Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=ORIBNuDPyW8Xiuv+GYriO1fYLmG4Icw8zcPk4zti+KCkWPHDLjCAPtpktU2MXV29UWbUjb7wevTsBer+7UFny+WnzJjwfAkDxpIieRerTXof19XQSBKcZL2ExEJlPQh40JL7D3ywD+yK8iML6R3LE+RRtz1aFWFPi+kr90QRfW0= 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=daPZQlR0; arc=fail smtp.client-ip=52.101.154.18 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="daPZQlR0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bRUCwCSHO8CwjVpUNcAcYVlsmr37suCf8/P57OE9ZTwwZBcsp/oD75nvl5JBTCifzAtqTz4Q9uh8rb/qIZleC2Zljitlvl5g/sa71eGgCbRtay8fI93xYsK9IMsbJbHcTCtNBIifqcnNJnKqxe0+uPQHn2m4hz5FTsgiOJFCiQPlx03zeoXZ6I0NjpXDyET3QXyUtT1vS++scXjZJRxaA/ZGc7PNYC0v4h796guYN8ssqLQ7+5WjfOTs/2jg1ebMdZoFZxf0qT3F3NaHMc0gcjVWEAIQY3gSpkIDx2rScxSqcN/ASqckmvDF9PlLkizuJMVtX0cVnUcD/jfKx7Bp5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TcO/zvPBzs7ZGOQScq+lMlN0ZObPQX4lYy5u7RowwwM=; b=nKbgF/Bf921jr6bjXjSpxqkF2pDvj7gGU6TwVcGLrJkClbbBJS4iJ4FD2lRSTsQvhorn4hhX/tJ8BRw12SxD/T6kFlcFesETzNfDz23aOqhwhHwL8CcCfaKde15P8L0hZcgGtp/yx4MOpYyc3OM59vehLpkHKd75oXGS8B1ilDnd9qJ4NrWPzhVjUi4pVgOt86O/1itD7XSht9mwbAOggfO3CjA4cfawehNk5ld1U7bGvKqLtkmQEnMLx2embsbyZGS4fDfbU2DVpLqwplvbDmImToQJqhhsuoswS1PGMUgx/08qsWaig+D1htkRAw1+ZfBOEA5vC2RaDnz7uRatHA== 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=TcO/zvPBzs7ZGOQScq+lMlN0ZObPQX4lYy5u7RowwwM=; b=daPZQlR0JYBpGE69/bXtomk9fAy6fcwvRbSgebWH2nVZkTKcolB/kSbnY9qNVFc8v7Oo28jC8y9d7DX5vCn0ag6fNBqgyD580yvFApAWs33+vjd3dUDTaLAsjCEaFUTi2KXW+rC+l0RX2dUNRJG9K+39jkgHOpqfVnfeNuzHve0= 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 PU4P216MB2247.KORP216.PROD.OUTLOOK.COM (2603:1096:301:12c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.49; Fri, 10 May 2024 06:58:28 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%6]) with mapi id 15.20.7544.048; Fri, 10 May 2024 06:58:28 +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 Subject: [PATCH v4 2/4] media: chips-media: wave5: Support runtime suspend/resume Date: Fri, 10 May 2024 15:58:15 +0900 Message-Id: <20240510065817.743-3-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240510065817.743-1-jackson.lee@chipsnmedia.com> References: <20240510065817.743-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SE2P216CA0033.KORP216.PROD.OUTLOOK.COM (2603:1096:101:116::19) 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_|PU4P216MB2247:EE_ X-MS-Office365-Filtering-Correlation-Id: 26b6b1d5-9589-4606-da97-08dc70be97ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|52116005|1800799015|376005|366007|38350700005; X-Microsoft-Antispam-Message-Info: 6xZWthwCOErxq2FPcINgdBMj7WeoCwtj80mqUDfYEUwwQL9cDHVAlH7CuBk643ZLaFWQL3gSQJc9I6MQpmnLti05jmjeakEQ3JZP7x+DZLGpH9eUpvlTwK9fRcsK7yB1JnzzNfCz2DWxH8RbJIRQfxlmDAzJedMyVFZP/UyMeMo11kWiKxh0ObeBlPMYBxb8jZF11k0BxvNNwY5KjgyJGJQvfmN7jK8JcbVkHZQJ5+7I3NKPXv4qQNrhbmG1pxH3PjAzqELq2m8OWWZoDch8pypYJhbuh0v+6sZlenO5ZwUYTV+HJl5bqL4bOmcggwTKIIV2mZsGPOC6IXHGF5qV2g1aMWfX7hoOb1vJwfhfMQpzlUGHKnemBa+PBAVNTGSGiqy7jWJn4jLXr8/FU2eholh0BH2bszx2bL436rW3klUBgybpdaG2FzvQxm3so4B39wEPefbAObUvn609O5Oj+rblksZxct3TBCYUi1AgfIvZv2KNhK2G++sna3uAqAmiDn+mOE5BrNeZqWEsJdrv7ofgxj2+yw1iKgm03G8Ae6lbvfuStz3rmAeRUMNl0hyCgjAdsysLhBht86CP1ar/e9KO24Ew4rqDB6hvIBFxzlJNVV2P2IKKkS7HPo33ZisvON1ysUpvEQ/eAANAPPjHrV+Zw1NGeujlkdu+lWgx3XhA29F44xf0hq/ojwZXbex8gAl5DR2lpr3mTGRxDfYDPm8F5J+iwhmUVFoX3pTIb0pbs8VZQenLHj24F7kKM14b9QSU5b3qtzXaLEf8FDfJAv7j6hxyRD5Wqy1JORq2CHzQ6AnCOkLjdKUe2ak7FKE3jDxnSOyOKrs5zRdM5Vd6fLYn73RUAC8/j1300zNa1IsaaA+B3Phqo2rNAy5Rc66QglEHeKkv6E4hKVLhnKQVgM4nGKYVr2dFONifVJ0sS5t1h0Phdr7qvgmU5z7UL7ZFYuCtooBJlb6rop8sC4OfnjINGo/IsyefTlCRq0NPTb71K9hTCeQwvZyoy5OScoEY4UereHzHe5aKAM+UUggz9jO/Ps/a+8QC/i8H8sQTz3tp7q3hv82smRwg5rfLPqe5FlpFnHc61NK3f7Gh0PiPRMlfk1w8P1+btlz+UCJG4E9CT2LtVwcHePUZQHkj5yWX1YabUCuOlYJDi/PSFG7SSeWQcqLbM9X733qSidNF64SaidniUL3sII38YDPQLxrLEfA7emwF5bzPOdQ/Vu8WTj8og8emqPXwdA9e3yhEJvnPdX6B14OmgtzPbu9DE1Nu1ka46zrTmHtJeWkc7ciZYjz6TAc78QyD6hY6gyxa3auFCAOP1qvP02TMBT1YL8Apkn9Wm4T1k+71jtkcprDNQw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SE1P216MB1303.KORP216.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(52116005)(1800799015)(376005)(366007)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bP9vRsiFloCOSOX4FpC8q/MnM5rLQFDNJGbWW/I5aDSQnBAD70+MRotqFzYZoqInMem92VTJpmeK4YHEAbUyryFQN30RvZNh2rYZ1fgKGRNG/KNtY/RdSu6X7ZO1LYADd/vc8ZftUmBP24HiVjMQ8tP19NgIRh4Dlqxs2jLqvLbJFDcqd/xN+N9X6YPCUYy3K3i4wTB3kGvYWWvpXycSUHOholqan/et9wVoOi7KAFHFuVgTiaQn198+3BFTBMGZioDreUYgs4Ddvvr+I4drXuawoXJ8BG3UmhSy4ri1j+8oZZNRPMnu7CuQZxTz7DQiZp6vgVvO6aYsaDGf8TGtFplWX9zoBt5BJImJ+fJD1V7Ig1cklalZ9L3JDDdptw2mMcWQKquvHMhW3ZdP5eL2LND/1RxORFeXQ9svgejxdYQxm7hcnxFCCtaVAINz5zsOyMhh4fAbkKYpbxKrDc4xHAY+EmybcNUfEYg34lIkJNCFHrhIJmI4csqd3XDKfpTPqfBaTI0wMbbXKYMu7MnY20/BQplwk+HjtjJJgTr60JBPU4hbE4V5BOBpin9Qha+v/OyO4zjPIBnsRwjw4YKCBFQbffOOWT96gjVvk4KKTikQG7Xc9U/Bf4z3zt/Qq2p7pOVCwWrZHuz11JI/2Y2IxCC2dCb8rSVI+tJlMM73x14F5VHFV1pKyQG/66feVqibijoL9E/6XPF8/tJYTkBTdk6MMhJgr8IoYoNexVA9Kp+F5LTrO2nkzpxiRpj4N4R006KJ97bE/Y/zVHScEZocjKqsm+KtYh/VNKMdsg77MaMwij6ZrdTyo4+KGL1RILm5LMUeTPBleiPjkxUw4Ba8PK5nUQj1yXxicWwHpzelFHoCcvHE1HEQppHp+aqJTcG+6wVyzdBuufn8uFliqwBlEYEpp44NDDyJi/1QuaynM6RHRwCJUpvsCS42RmMlogT2jsJLW4Nm8vhDVXpXt0wkp6h/MTB6E46IVx1UBSenZYewR7qOOi87kK74kdQOn1qyXyzcJRJA2OHmP1owo/krNGUn4wU/dhNrn+PrLD5SvzAlwijkYGTqjOHORU4zaQZ18o1XqElknROhcCUhYXmMTZXHoV1jfAtLNvaFF/Ox/JLDGUbrf3MMeMpFQ281v+W9lXF9ZGvwHe5ieZ7GUYRv0Gof6waME0U+LBp8XwvBPyoGR14ENE9MuYO9WVEWo/BBQ0v1iue+3kcbXMtWjtrjP/f26zBQ24gMkIpOk3oZ0GpBRmgRNGKgLQtPklT/uy1/PJFGJwmq8ISUa8AZK2m1xLrcgsS1arylgBIHasFp+Y6rC6wEf7j6pwH0zR2SOr98d//OJv7om16hTHUsO8ziE52FNrXlnCvigdCUB+mF8DKFdO5SG9q2eaYhsQlZ1DL0rRQ5XL9OHwCFHt2jSwyL0TaN2eRH4QZmVzMdwSge5C3pxK1bTFT0n/Gfx+Vda8Gb8axhma9soiBQ16DH21tIIVu1c3MMBjvxDHYcId8j0Tw/fjHj/2094B6eQEJFndt7pqYTGU7IByBpWHEjlBmIIbDgETRCi/6HGgTu7xyx3hfF7wcKM8MjvoJ1dx3Q7gdo5D0k/xXYcB/FS6h+p5hDwQ== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26b6b1d5-9589-4606-da97-08dc70be97ea X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 06:58:27.5437 (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: YtjtRK0qIzlV6+iKZpzujoVdY6Kz/YCPJRid0Ckt9Cm+ydjhXNR1+1baYJSoVs8WlNr1ibR6abGDcQCg5QtpX6d5t5i8J385YvNZoBtGenM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU4P216MB2247 From: "Jackson.lee" 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 --- .../platform/chips-media/wave5/wave5-hw.c | 4 +- .../chips-media/wave5/wave5-vpu-dec.c | 16 ++++++- .../chips-media/wave5/wave5-vpu-enc.c | 15 +++++++ .../platform/chips-media/wave5/wave5-vpu.c | 43 +++++++++++++++++++ .../platform/chips-media/wave5/wave5-vpuapi.c | 14 ++++-- .../media/platform/chips-media/wave5/wave5.h | 3 ++ 6 files changed, 88 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-hw.c b/drivers/media/platform/chips-media/wave5/wave5-hw.c index fff6e66b66e4..791b1f0e3199 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-hw.c +++ b/drivers/media/platform/chips-media/wave5/wave5-hw.c @@ -1084,8 +1084,8 @@ int wave5_vpu_re_init(struct device *dev, u8 *fw, size_t size) return setup_wave5_properties(dev); } -static int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uint16_t *code, - size_t size) +int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uint16_t *code, + size_t size) { u32 reg_val; struct vpu_buf *common_vb; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c index c8624c681fa6..861a0664047c 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c @@ -5,6 +5,7 @@ * Copyright (C) 2021-2023 CHIPS&MEDIA INC */ +#include #include "wave5-helper.h" #define VPU_DEC_DEV_NAME "C&M Wave5 VPU decoder" @@ -518,6 +519,8 @@ static void wave5_vpu_dec_finish_decode(struct vpu_instance *inst) if (q_status.report_queue_count == 0 && (q_status.instance_queue_count == 0 || dec_info.sequence_changed)) { dev_dbg(inst->dev->dev, "%s: finishing job.\n", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); } } @@ -1382,6 +1385,7 @@ static int wave5_vpu_dec_start_streaming(struct vb2_queue *q, unsigned int count int ret = 0; dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type); + pm_runtime_resume_and_get(inst->dev->dev); v4l2_m2m_update_start_streaming_state(m2m_ctx, q); @@ -1425,13 +1429,15 @@ static int wave5_vpu_dec_start_streaming(struct vb2_queue *q, unsigned int count } } } - + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return ret; free_bitstream_vbuf: wave5_vdi_free_dma_memory(inst->dev, &inst->bitstream_vbuf); return_buffers: wave5_return_bufs(q, VB2_BUF_STATE_QUEUED); + pm_runtime_put_autosuspend(inst->dev->dev); return ret; } @@ -1517,6 +1523,7 @@ static void wave5_vpu_dec_stop_streaming(struct vb2_queue *q) bool check_cmd = TRUE; dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type); + pm_runtime_resume_and_get(inst->dev->dev); while (check_cmd) { struct queue_status_info q_status; @@ -1540,6 +1547,9 @@ static void wave5_vpu_dec_stop_streaming(struct vb2_queue *q) streamoff_output(q); else streamoff_capture(q); + + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); } static const struct vb2_ops wave5_vpu_dec_vb2_ops = { @@ -1626,7 +1636,7 @@ static void wave5_vpu_dec_device_run(void *priv) int ret = 0; dev_dbg(inst->dev->dev, "%s: Fill the ring buffer with new bitstream data", __func__); - + pm_runtime_resume_and_get(inst->dev->dev); ret = fill_ringbuffer(inst); if (ret) { dev_warn(inst->dev->dev, "Filling ring buffer failed\n"); @@ -1709,6 +1719,8 @@ static void wave5_vpu_dec_device_run(void *priv) finish_job_and_return: dev_dbg(inst->dev->dev, "%s: leave and finish job", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); } diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index a23908011a39..703fd8d1c7da 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -5,6 +5,7 @@ * Copyright (C) 2021-2023 CHIPS&MEDIA INC */ +#include #include "wave5-helper.h" #define VPU_ENC_DEV_NAME "C&M Wave5 VPU encoder" @@ -1310,6 +1311,7 @@ static int wave5_vpu_enc_start_streaming(struct vb2_queue *q, unsigned int count struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; int ret = 0; + pm_runtime_resume_and_get(inst->dev->dev); v4l2_m2m_update_start_streaming_state(m2m_ctx, q); if (inst->state == VPU_INST_STATE_NONE && q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { @@ -1364,9 +1366,13 @@ static int wave5_vpu_enc_start_streaming(struct vb2_queue *q, unsigned int count if (ret) goto return_buffers; + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return 0; return_buffers: wave5_return_bufs(q, VB2_BUF_STATE_QUEUED); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return ret; } @@ -1408,6 +1414,7 @@ static void wave5_vpu_enc_stop_streaming(struct vb2_queue *q) */ dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type); + pm_runtime_resume_and_get(inst->dev->dev); if (wave5_vpu_both_queues_are_streaming(inst)) switch_state(inst, VPU_INST_STATE_STOP); @@ -1432,6 +1439,9 @@ static void wave5_vpu_enc_stop_streaming(struct vb2_queue *q) streamoff_output(inst, q); else streamoff_capture(inst, q); + + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); } static const struct vb2_ops wave5_vpu_enc_vb2_ops = { @@ -1478,6 +1488,7 @@ static void wave5_vpu_enc_device_run(void *priv) u32 fail_res = 0; int ret = 0; + pm_runtime_resume_and_get(inst->dev->dev); switch (inst->state) { case VPU_INST_STATE_PIC_RUN: ret = start_encode(inst, &fail_res); @@ -1491,6 +1502,8 @@ static void wave5_vpu_enc_device_run(void *priv) break; } dev_dbg(inst->dev->dev, "%s: leave with active job", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return; default: WARN(1, "Execution of a job in state %s is invalid.\n", @@ -1498,6 +1511,8 @@ static void wave5_vpu_enc_device_run(void *priv) break; } dev_dbg(inst->dev->dev, "%s: leave and finish job", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); } diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.c b/drivers/media/platform/chips-media/wave5/wave5-vpu.c index 68a519ac412d..325e311cdedc 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "wave5-vpu.h" #include "wave5-regdefine.h" #include "wave5-vpuconfig.h" @@ -145,6 +146,38 @@ static int wave5_vpu_load_firmware(struct device *dev, const char *fw_name, return 0; } +static int wave5_pm_suspend(struct device *dev) +{ + struct vpu_device *vpu = dev_get_drvdata(dev); + + if (pm_runtime_suspended(dev)) + return 0; + + wave5_vpu_sleep_wake(dev, true, NULL, 0); + clk_bulk_disable_unprepare(vpu->num_clks, vpu->clks); + + return 0; +} + +static int wave5_pm_resume(struct device *dev) +{ + struct vpu_device *vpu = dev_get_drvdata(dev); + int ret = 0; + + wave5_vpu_sleep_wake(dev, false, NULL, 0); + ret = clk_bulk_prepare_enable(vpu->num_clks, vpu->clks); + if (ret) { + dev_err(dev, "Enabling clocks, fail: %d\n", ret); + return ret; + } + + return ret; +} + +static const struct dev_pm_ops wave5_pm_ops = { + SET_RUNTIME_PM_OPS(wave5_pm_suspend, wave5_pm_resume, NULL) +}; + static int wave5_vpu_probe(struct platform_device *pdev) { int ret; @@ -268,6 +301,12 @@ static int wave5_vpu_probe(struct platform_device *pdev) (match_data->flags & WAVE5_IS_DEC) ? "'DECODE'" : ""); dev_info(&pdev->dev, "Product Code: 0x%x\n", dev->product_code); dev_info(&pdev->dev, "Firmware Revision: %u\n", fw_revision); + + pm_runtime_set_autosuspend_delay(&pdev->dev, 5000); + pm_runtime_use_autosuspend(&pdev->dev); + pm_runtime_enable(&pdev->dev); + wave5_vpu_sleep_wake(&pdev->dev, true, NULL, 0); + return 0; err_enc_unreg: @@ -295,6 +334,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); clk_bulk_disable_unprepare(dev->num_clks, dev->clks); @@ -320,6 +362,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..b0911fef232f 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c @@ -6,6 +6,8 @@ */ #include +#include +#include #include "wave5-vpuapi.h" #include "wave5-regdefine.h" #include "wave5.h" @@ -200,9 +202,13 @@ int wave5_vpu_dec_close(struct vpu_instance *inst, u32 *fail_res) if (!inst->codec_info) return -EINVAL; + pm_runtime_resume_and_get(inst->dev->dev); + ret = mutex_lock_interruptible(&vpu_dev->hw_lock); - if (ret) + if (ret) { + pm_runtime_put_sync(inst->dev->dev); return ret; + } do { ret = wave5_vpu_dec_finish_seq(inst, fail_res); @@ -234,7 +240,7 @@ int wave5_vpu_dec_close(struct vpu_instance *inst, u32 *fail_res) unlock_and_return: mutex_unlock(&vpu_dev->hw_lock); - + pm_runtime_put_sync(inst->dev->dev); return ret; } @@ -702,6 +708,8 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res) if (!inst->codec_info) return -EINVAL; + pm_runtime_resume_and_get(inst->dev->dev); + ret = mutex_lock_interruptible(&vpu_dev->hw_lock); if (ret) return ret; @@ -733,9 +741,9 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res) } wave5_vdi_free_dma_memory(vpu_dev, &p_enc_info->vb_task); - mutex_unlock(&vpu_dev->hw_lock); + pm_runtime_put_sync(inst->dev->dev); return 0; } diff --git a/drivers/media/platform/chips-media/wave5/wave5.h b/drivers/media/platform/chips-media/wave5/wave5.h index 063028eccd3b..6125eff938a8 100644 --- a/drivers/media/platform/chips-media/wave5/wave5.h +++ b/drivers/media/platform/chips-media/wave5/wave5.h @@ -56,6 +56,9 @@ int wave5_vpu_get_version(struct vpu_device *vpu_dev, u32 *revision); int wave5_vpu_init(struct device *dev, u8 *fw, size_t size); +int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uint16_t *code, + size_t size); + int wave5_vpu_reset(struct device *dev, enum sw_reset_mode reset_mode); int wave5_vpu_build_up_dec_param(struct vpu_instance *inst, struct dec_open_param *param); From patchwork Fri May 10 06:58: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: 13660954 Received: from SEVP216CU002.outbound.protection.outlook.com (mail-koreacentralazon11022018.outbound.protection.outlook.com [52.101.154.18]) (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 1872A15F41D; Fri, 10 May 2024 06:58:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715324321; cv=fail; b=fvx9CgpCR3uY6K5PunxrihKlaSKvfz4DjiYrKUSBzdOFrDnUI5FejtZc9mXzWAyCzugxrm0JPLcSXn22PVLFFPGMoE1o+EALJqZKb32aIsFLFPo/0OqmrR4JeE5s70DYk2jxDLYRYEJykx+3qKYjQBTEposCPVGkh53fNABMYYM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715324321; c=relaxed/simple; bh=iLlXNG2PIIx+T+C2n+6SEH1YJri7KU76SWyIbHTJfGY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=WvoMHT3GXcviGrU5/Jdk16/KEESJpAZVQ79XPOG1tQgzfmyhgrJxYgUxSIOgZ4ZRQp9oSE4r4DLTARQZfpnvyC1gA5yP4Gv5uYvU3+gzF+dIQ0EtvTTbSIo1f97EukPgIsoQimETRJmMGRMhgS5ObO5BTcm1wL6fNaTNCAWXvuA= 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=FNAE3BtC; arc=fail smtp.client-ip=52.101.154.18 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="FNAE3BtC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PZtp8oRM9KpGvs+RdGjzueDQzw8EOEtlddTFuXIhfsoL2RHYQFL8ozdZhJ8XhcuKdT+Nav6NRp7YOMswiholrVhl5pl35Rzef4a4FOgkYp7E6bgHadAh/OtiuAuittqFkU0SMKpPBu+iEzcB6+6xmOamJcNe9Q9Vg8ZuLTQvL2TXOxGF1FnsVw3vadJeSkUGPW3IV4BcEu5YX6tMXHHx/lg1W4A5xtqpeJpZBVVdooz4U4Pqg0usGX1JtTDdU8RhU7gc/kGt6WGxzVv+P8YeAVAsKQqhhXeHEId5ZuWy6CONLm+mWyjeLzWiJOTDtNDfqMrlLEveJ3CLXYwLGav6Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wN3e1j6LQP7KFaGLTrEhzYsm/r+C6mDQ+1o2ezW5wGQ=; b=oMiNmTlF/rH69bVd0zhiwgzk/L7rSfRJKMD8a2OpvQyjEjNQgiM0yuzmpsDhQLF7zfObCCXziuvidkt0TUdhfb1R9259FLWG88EfME3d+Wej82Xa3jWWOI57Kw7AdhV1kmTniY5kt0uCd9E49AGL3/dLmWOnIcO74EspawAGWXaX2cCbmd9gBhaq5jD5cwROhkydI1jmRaEV3SWYzmW62oaxgLuJKw3peFdHkFow/z8ZD28heKJfLJtrJy0LBipdjIhEVG963pOx0ydBxhRs0CI+dd84V49kTWxZUhSaTrK5XrA0Z9Ew7f5N62hPJ9IYcs75XdPlk7RRwBXCpD9n2w== 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=wN3e1j6LQP7KFaGLTrEhzYsm/r+C6mDQ+1o2ezW5wGQ=; b=FNAE3BtCHhHNvRIMaQQxQQiuU+OakxNB6rI3EYMP+d8U0Ljcl45zYmzHMVeIOlHYaoV/2Z33JNld9oW9ZncW8L43j6UqpVxsN8blk8A+Y6AVsZN1DSR1WphtrNi5N3Zl2Tiyt7tM520MJioSAo97ltV4KZzK4nn5BDzc8CriFrc= 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 PU4P216MB2247.KORP216.PROD.OUTLOOK.COM (2603:1096:301:12c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.49; Fri, 10 May 2024 06:58:28 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%6]) with mapi id 15.20.7544.048; Fri, 10 May 2024 06:58:28 +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 Subject: [PATCH v4 3/4] media: chips-media: wave5: Use helpers to calculate bytesperline and sizeimage. Date: Fri, 10 May 2024 15:58:16 +0900 Message-Id: <20240510065817.743-4-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240510065817.743-1-jackson.lee@chipsnmedia.com> References: <20240510065817.743-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SE2P216CA0033.KORP216.PROD.OUTLOOK.COM (2603:1096:101:116::19) 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_|PU4P216MB2247:EE_ X-MS-Office365-Filtering-Correlation-Id: 66767795-6915-426d-c506-08dc70be9811 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|52116005|1800799015|376005|366007|38350700005; X-Microsoft-Antispam-Message-Info: kEM5lpPYpJqHKMVcNAxbtKkq+iopP8ag821xutZatqrs3QuhlEJ+Vp0eFOITuYVDBaZLNGBkoMeivTh82u+QQzsb4ElH43Vq/jzsnoylBaHSBxeDl1MjVjLrxvIfRwktBZ3OfYe7iRsEXRNqvRc1UVQsSIPvkEZdXNC7lNorf/15SUOxCXrqQcwihiFlatQQ5o5houS4sAtm+ZFmcoXkjQs0ALQIGqFojPD3NbcVwgYeRUqAQtwacMrMDk9mb+7amJrkMs7Wa7w8RPKLyJfdzZyvbnzoUBcL9Qvd2QVDzO+yzeUaGLktqmvE9q+4krHt0FJ6rttBaFlBo+UnUH+1z3wK3nzD8xSRTvrzF18oDno7dP/yVhQnYeHx7rKk9CIv39yNS8qo2mCCu0HdqZfW204Esek4EU/whhXzpfe+hJ6ODj8JPAeGa6lR8MBr4gkC4H1rL2a+gdyoKJz6SuaWL8DDkiELaxsrf33mcoexhE2qJokYG5Y6yQsrYfJPs6f/FmO4Z5WD/dUCEt4AR1utIjjLC2CJJzImyJJ0w3OX2NbbZpb3KTVZocnGwX4u5jSTFXQZsMim4YtuAXWDDJ5+WckdagreCBF7vJk2gJuBqlnVtwAvEEKMDQOC81MSbg2HhHpEEVrIU74QlIZK4FANpXyEUMwoVzSkxOCR962+FVUc8CcbjnbUM8CZjiCc/yyP8NsAB5DwgI+mV31BAq7dpYajOhSmtvmK0HSok9zJ3LeaRoRhhATahnKBjAuU/WN730XnrOC1IZCTh1qLgIQmmCM+WxgjhXlMtN9GQnZE6LLBgpX6yYeXYoCG5Ksu6CnRtLVBwzUydtcyyPerHb8Cb448+q7Lx+/NtXTWQnzhPjavS14n4DyqHkOYIE27cfq8M5mOClEo0mpGGAWo2Xzqpofk/vFL2imr1uamWuqLEKoA2VGf1sRJ1rYKzsHCZcS1XrCdMebwytfwgwtQO+GMsonkTyEP1J2X2KiO9SlI6TMHTsIKarFG6hBuY3D0BZV7KgFlpO/WMS+EnBR3Yud7EKcCbTlaEo8VBBG80zYPZEYYuqgdbgzJu+j+V7u35AHB/BmcvxkVgD+tJhaHiPfHBmk7zfAqvkrkeakNa9TqC7tmW1D/gqEigTynQGmyjEbxWOyvN6FGLVCqt29+xh1bWiiXXRNh3DezaVvKvnlMR3PVXktk/SgDvZLL9G9EckuZco46wRT3EegfCI01o9Nng/OeD8Ql1voPivauwTgi601zwm/A/XC2OnF46y375kllxGzSk2E2eRk2zwRPCyzR3BX6n6D021pZKEUB9+QZQ/iwn5WZ3lnAgOwxf6Fz7XWARfcyMT4SNDZTNDoUbCM69A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SE1P216MB1303.KORP216.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(52116005)(1800799015)(376005)(366007)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TEErrFZL1H3btSO14gPkvemCeb74J5fzaxCGT69eP13+nTjheH7S4wOnI4ZERuHKxClY+53ZwkAny3oFei36NIV7nDNA7/azaT/lCfjzpD7JNuEP07Vi9aYHFEBOWmHUffqy7MYIpruSEQbiYAbrblA5vuTC8IcsdxsLYOSnhDvKHWdT9wDZlu1l/U2eAOWcDAkTebToNKGxZqrCACtUVintL/DrT3Gm4wT17LR1l3DIOq1h7Kj3qJXeyohN5KQAYmJbq1fPv5GnWqLkEtyEMZnBv8HkGEQfxFwMTpgcIzsst2htSF1npUKoQxN7IdcZ9yBxuC12nfWKIBnzrA/pFgxvrcbEaZd9SssYHrC/3eTH1DhBlTH70gDYjmK4FIYhB5i7dunEsl/qLGyY/GH2c2sucOFV7wMJ/zXhwhkYkZ3i7gJZ22xNBI9h49MERs27wGRdGTjmXOMl6EFilbtBqfeyAhAljabE3ZbpFfmjRRjrTY13kspH9tXTUcqUhD2H8rFBFo9qjN5Lk287LQH0f1ScxQbYidSqXxtOjg0xk2nvYDwOzLujaGILYZrLO4eEA+MfG+NPt73GSrbSsZ3LV11V9rG+Q1/InQG4qmsLpk3ThF15qigRy5rtQKWZ0dS/3d/OLH4dcG6B6lp46zjw5ZVVySBmlq7Ro8awe9njgffkfjJKKcvcFadxbEmRtZd7VU52hQxDWPzHTealPJfmyY9fN+8ybZcfgmYw9HCH60B8JUP0ITeV/E8IQnFRcVJvwluaP8a4vTbyhQaCJR2jaiesXwj/EXfylmpz5oBrlaGZh+GJW2SFOm7R6ZjSW2KtZChSuEkoZEUoXHIIDLrGhv9Qe2Z661ZbmkPTE/qwpA0glqUFjEX3ESiOeheoH7sWHRq7jdrMrmYlWlu91vhJfVISs6irtWgVWJDTxHgWMGGviifzFwVkD59DLwlxyZWDgseAeNJtq27e6B9C+LK8RaByeh0Avvdj0xINRNMnDzt1WR/LSvCO3EfN/r0GkJP2D/W4Q3Dn2yby+znr/qOxkkxjnUf1eBOxS0Wty6gQ4Vn5gl7NZ4uu3j93R7Jxkrf3k7csSrMCqgkwcj/bQiwaOa0o41UENg4OvLu3v43jnvS9GZ31j9a7gF6ZizJF+xsMvFyOzvGuREp7HQyCAlwB0iPV/NArxvjztEvPcwKw8Aj2rsPLeIUEbIQzGVBdnZAYttvXNHX8qppPHd2Uqqv8FzsqKpFHIs9S8OypS7QuHOxT9DEDFxjngtjfTGI5PjrJLvS8hLH+6BHQsn5B2KszZ7F0P6sBMqjxZjJtKYcDSm3UmKRogImNA+mL3IjYJAsyDG/KMHUp/gBzXmGLi4boOBXHS6C++kxu1ZNlSbvIzHS7UCt0Obct4t57vgeE8aOKY7A8Po6w0MA1jf77MEqWIAyWAKGohfm8VnuDucZlk5pwhKx3rkhIHyFzXVCWbEsPNo71TVEyJgbxoKLgJ1nOdmvYf8li2H3d2VpAmRnZXF7CYgXeZUn1wrQknQiX3vBmkqgbiBu4VqiuZ4/dbgWcCVjEOBBp0Wa4OqrR3GYXAthYc0KtfcdFNIir9PlhffTA+NlqHwhd2CMiAfi034Kqdg== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 66767795-6915-426d-c506-08dc70be9811 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 06:58:27.8225 (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: qtvnSQuX/tle3sxdFxJQFy+KigL/S+a4V5XRTZyVh3o/2WvnoWtq8HnhWL1c2OEdbl6MmdFQR06MeoLSOKE0jh7Jwjt1Xt+5LA38HlVpR9c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU4P216MB2247 From: "Jackson.lee" Use v4l2-common helper functions to calculate bytesperline and sizeimage, instead of calculating in a wave5 driver directly. In case of raw(YUV) v4l2_pix_format, the wave5 driver updates v4l2_pix_format_mplane struct through v4l2_fill_pixfmt_mp() function. Encoder and Decoder need same bytesperline and sizeimage values for same v4l2_pix_format. So, a wave5_update_pix_fmt is refactored to support both together. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung --- .../platform/chips-media/wave5/wave5-helper.c | 24 ++ .../platform/chips-media/wave5/wave5-helper.h | 5 + .../chips-media/wave5/wave5-vpu-dec.c | 296 ++++++------------ .../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, 236 insertions(+), 318 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-helper.c b/drivers/media/platform/chips-media/wave5/wave5-helper.c index 7e0f34bfa5be..b20ab69cd341 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) { @@ -224,3 +226,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 861a0664047c..733c770fb049 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); @@ -548,12 +480,7 @@ static int wave5_vpu_dec_enum_framesizes(struct file *f, void *fh, struct v4l2_f } fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; - fsize->stepwise.min_width = vpu_fmt->min_width; - fsize->stepwise.max_width = vpu_fmt->max_width; - fsize->stepwise.step_width = 1; - fsize->stepwise.min_height = vpu_fmt->min_height; - fsize->stepwise.max_height = vpu_fmt->max_height; - fsize->stepwise.step_height = 1; + fsize->stepwise = *vpu_fmt->v4l2_frmsize; return 0; } @@ -589,14 +516,10 @@ static int wave5_vpu_dec_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo width = inst->dst_fmt.width; height = inst->dst_fmt.height; f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; } else { - const struct v4l2_format_info *info = v4l2_format_info(vpu_fmt->v4l2_pix_fmt); - - width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = info->mem_planes; } if (p_dec_info->initial_info_obtained) { @@ -604,9 +527,10 @@ 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, + vpu_fmt->v4l2_frmsize); f->fmt.pix_mp.colorspace = inst->colorspace; f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; f->fmt.pix_mp.quantization = inst->quantization; @@ -719,6 +643,7 @@ static int wave5_vpu_dec_try_fmt_out(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + int width, height; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u colorspace: %u field: %u\n", @@ -727,20 +652,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); } else { - int width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - int height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); - + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = 1; - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_CODEC, + width, + height, + vpu_fmt->v4l2_frmsize); return 0; } @@ -748,6 +672,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 +707,14 @@ 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 +937,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 +951,9 @@ static int wave5_vpu_dec_queue_setup(struct vb2_queue *q, unsigned int *num_buff if (*num_buffers < inst->fbc_buf_count) *num_buffers = inst->fbc_buf_count; - if (*num_planes == 1) { - if (inst->output_format == FORMAT_422) - sizes[0] = inst_format.width * inst_format.height * 2; - else - sizes[0] = inst_format.width * inst_format.height * 3 / 2; - dev_dbg(inst->dev->dev, "%s: size[0]: %u\n", __func__, sizes[0]); - } else if (*num_planes == 2) { - sizes[0] = inst_format.width * inst_format.height; - if (inst->output_format == FORMAT_422) - sizes[1] = inst_format.width * inst_format.height; - else - sizes[1] = inst_format.width * inst_format.height / 2; - dev_dbg(inst->dev->dev, "%s: size[0]: %u | size[1]: %u\n", - __func__, sizes[0], sizes[1]); - } else if (*num_planes == 3) { - sizes[0] = inst_format.width * inst_format.height; - if (inst->output_format == FORMAT_422) { - sizes[1] = inst_format.width * inst_format.height / 2; - sizes[2] = inst_format.width * inst_format.height / 2; - } else { - sizes[1] = inst_format.width * inst_format.height / 4; - sizes[2] = inst_format.width * inst_format.height / 4; - } - dev_dbg(inst->dev->dev, "%s: size[0]: %u | size[1]: %u | size[2]: %u\n", - __func__, sizes[0], sizes[1], sizes[2]); + for (i = 0; i < *num_planes; i++) { + sizes[i] = inst_format.plane_fmt[i].sizeimage; + dev_dbg(inst->dev->dev, "%s: size[%u]: %u\n", __func__, i, sizes[i]); } } @@ -1564,20 +1475,17 @@ 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 703fd8d1c7da..75d230df45f6 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; } @@ -392,6 +342,7 @@ static int wave5_vpu_enc_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + int width, height; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, @@ -399,20 +350,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); } else { - int width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - int height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); - + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = 1; - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_CODEC, + width, + height, + vpu_fmt->v4l2_frmsize); f->fmt.pix_mp.colorspace = inst->colorspace; f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; f->fmt.pix_mp.quantization = inst->quantization; @@ -500,6 +450,7 @@ static int wave5_vpu_enc_try_fmt_out(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + int width, height; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, @@ -507,21 +458,19 @@ static int wave5_vpu_enc_try_fmt_out(struct file *file, void *fh, struct v4l2_fo vpu_fmt = wave5_find_vpu_fmt(f->fmt.pix_mp.pixelformat, enc_fmt_list[VPU_FMT_TYPE_RAW]); if (!vpu_fmt) { + width = inst->src_fmt.width; + height = inst->src_fmt.height; f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, inst->src_fmt.width, inst->src_fmt.height); } else { - int width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - int height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); - const struct v4l2_format_info *info = v4l2_format_info(vpu_fmt->v4l2_pix_fmt); - + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = info->mem_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_RAW, + width, + height, + vpu_fmt->v4l2_frmsize); return 0; } @@ -529,6 +478,7 @@ static int wave5_vpu_enc_try_fmt_out(struct file *file, void *fh, struct v4l2_fo 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 +518,16 @@ 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,17 @@ 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 +1696,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 d9751eedb0f9..8e11d93ca38f 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h @@ -30,10 +30,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 Fri May 10 06:58: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: 13660951 Received: from SEVP216CU002.outbound.protection.outlook.com (mail-koreacentralazon11022018.outbound.protection.outlook.com [52.101.154.18]) (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 BB20F14F9DB; Fri, 10 May 2024 06:58:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715324314; cv=fail; b=ZlR8NlzYGhipdyEZVllEP2t1k2WSv157kB7FfxxTCHbS08PCsZcqnMm85UhHNpfMvYd2tbHhrmvjeOhmx8/oVtrPaY3FcEf6aL+j2BoKK6iUC986j/8h/1rzA6szFXow39qm9Or+soI9b92Oqc8fC0gvdg+hDN9amuL8BGNN2tk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715324314; c=relaxed/simple; bh=g7GnN3v5b7brU1xSRBE+yINneysTTH6RhFrDZCOc82Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=cvhj9rYkcRwOAUplYMKiVbKzWWSiZQRIBVOX//94+P+/AeX3c3Qiu8EQBjMZsDY3KIWWUTaUZv6kz/3FFcXHG/aGqGTo4EM1yjvdJU5xpeF21S5YsrZS8nzkWN7tAs5KV1U2uAIu9HhzdinnQ7o+1IJJH2z8eZES6dWm0f5Ds2g= 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=MEkuebch; arc=fail smtp.client-ip=52.101.154.18 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="MEkuebch" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ht4frguCLA4QrfDsxVT2eackJH5FQjWbzaWQSbwrPVQGdIGn5KbpZ3NulC/+n9PW3yMibnqwfLsQKQTTF/Lu4rjViCZf3YtPaG/gc5lD+N1UbKw24BLXzR7Hgkq+YPO7w0pKwSecJxD+So/YUziHRZME5rxjgkkzmCXDDaQ0YLnPI5VltPnNGNS0L8CG9kCY5ErYz6LqaK1oPPpoGsHe5lghv4B+TNEhTEto1RstzuKoIIRBphbXlsId9RMKNgCVEVA63nkEaHZzSbPDopSVcAjKhiErCVAfqQ33vx7bt6+HqK3GSUNMr7iSrI9Jpfc8vYLIE0lggGvRl5K4ehRQLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SSBCqniFhGfdDtbG2A0I0Ml3S3aWDzVpm/x23WOZIfU=; b=IGv7lFetTu3TXGpxhgRxo/nLbxDdXrRqqM/gU/fpF5YzKDEswFSPG7h1CkgIIlp/9P4i8/12/IrUOVYvyGaBz3T2138j1TC1jSA/j7isbZaXobKhj4Re4DmVUCnD9mnm5QYj9T2m423WCkwXAuAqCye0YT1iNRryfMp+a/H40JraObAs9r4G9UkS5aAcf34drqPC/A8H/33nWBiGsWOGskBe4Br5eo1effz7s/NSapdQbh/aZe4NwfXqYIB4IlPenNFR8b7Es/pBx/T4fKF35tMOdVIcpnb7YQ2AW9kQUfjzU3+uSV23uIuKGEPWRC8IjIljhSgauv6EEXDGLMPLYw== 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=SSBCqniFhGfdDtbG2A0I0Ml3S3aWDzVpm/x23WOZIfU=; b=MEkuebchaBvV3uNjUS5xgpi3IxiptVdoNcoAQsQELDzBscO8PhxyCXf441VkO85oAVcCVZODB9jbhJJvH13+GeBEyEvgyXiBCuGP61xT4iTEybSIVCy5ZnLn1dqk/bqQz2OZnvMkuqNeumt/pRCQwAdlq9y1XZesQzB1re1+fpk= 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 SE2P216MB1826.KORP216.PROD.OUTLOOK.COM (2603:1096:101:fc::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.49; Fri, 10 May 2024 06:58: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%6]) with mapi id 15.20.7544.048; Fri, 10 May 2024 06:58: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 Subject: [PATCH v4 4/4] media: chips-media: wave5: Support YUV422 raw pixel-formats on the encoder. Date: Fri, 10 May 2024 15:58:17 +0900 Message-Id: <20240510065817.743-5-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240510065817.743-1-jackson.lee@chipsnmedia.com> References: <20240510065817.743-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SE2P216CA0033.KORP216.PROD.OUTLOOK.COM (2603:1096:101:116::19) 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_|SE2P216MB1826:EE_ X-MS-Office365-Filtering-Correlation-Id: b5b5e913-2bcc-4a1c-6512-08dc70be9836 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|52116005|1800799015|376005|366007|38350700005; X-Microsoft-Antispam-Message-Info: jAEpZAE+D7cFYbW6M34Wnv6SoWwtDbMCmgglZkxkkw48Rrtgl51TOOPBU58AlYntk0PaDZUDrvw4npniNvVSDeXmsZQdTNtBnGBLRwg9rBy6p9y2CY0+vb4Jcl2LnKeVyhW+mAYujEti4IVboke07rUSNKfZ8/4fT9dfnBEeRCO/t060kx/GcmPufUd1L/10mhbyAtIbJJsOfvezHoT4G2sTBas84CA5s7atn5Kw0ZqYbWRORRtecqCYlX5oJGNrXmO6iOPnm5EQvFcFGZtWvnUu1EmZ66afno9PP6oWUQEBupZ35rI3LNlDngDy4kT+Lsxtnduiwc+Bre2Z1wrlcXkndAsQstySdGOVj87FpSees4Nl8GbrAzBNAK4JDDB1lL20FwQ/TDA1X+gdGe3SK8HoEdaBBhG2NwvTHCGcDoJYEmVJmrirN/tWGgLJG59PiS6N0fgIgC3kAckh5eh9QLFVS7Mx2AEyWqpiT3t71Dpi75uSGhXkCM/zhovNxAyqm6jZAHyglt2RlG50WbRKivYKgcB7R+SeLrIOQZ3loqNDatSYOZKCgTR0MJyjUU8O+ht7i1AWk15+pR/+hN+AgUgB4lAp1fO5Ejiq1z1pIB14OD4PO3JDDwaSPGODXRK4aUUH7xQaQ/vmfMEQ19OS8Mi/I+CnXowtOx+LhOENIaB0LYjf3EIMH3rztXg/oFHZyVpGiQLDZ9tz9cozZHG6y20IFbULAJ/DMNIMp+K+2IwhH1GvKhQLdim7n7gA14JJHIYW5SZm99neMnypYJvM5rkMuYnc23NkDLteSb8qmVIg0Y4Y2m2E96ziecBX9nZ+BFuVMYCSAgMsIuSApfKoSNtAp9VfOFtfl6XBytjPPQoQ0XZAwsTZ1gNYcyzNx8TH+gofXiS8oXJWpGErWo90QkEG1tmIa9yyt6BaFuoXX5QZ/JZXsHtL4m4wZLb9pIzkgAmluhEzt5UQKJ+ngHgeoMKUFFshBWEoFZS8vDQWFyMETOoWvWeclsqEzJwqy/kSlw/1Pc+tQ2MJXPeUXx33wpRVwtDvQwRh7jSWMxyO6QA8/uIzkZKbQAGwT2WnoBA1UNkHh3n+NoE4DwJ3lc63C1J8MuNgiFez043TLHD43GOjG7Fk7io8+0ZQB+KDErGTdNtjNwo/GkJhLNWOq62IUj1OUS6VSoCnV32wrJCkfUZOEZkFty0TFeqM8JXJGs5PNZj0GWYnjgb5pYcR53LhbAIQU0MJbvW1iByYoHh4AyFl9Y4LQLVpCIjjFY9x6+q1JQHQDNm1ZcXS1BmYKdh0mpsqL3ixENraufEyd44CDcDQjeCYeXNaicF5q8rXZZy8Ei3l7q2ewNOwSqP7/U0NuA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SE1P216MB1303.KORP216.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(52116005)(1800799015)(376005)(366007)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8GvZeOFW1I7RseFastZZCeFHLIMTbFUpeQ5XkIVmpeGykkZaLA+kQK16WIIA72GXpMQ9ELoIeJ5XQHuheBxt66Yy3j2xk+0MR1tASBFXdikq1+d4no6aqw4KrI/frazKxmZDrKImvN2zSe6WraGxCinnvtbPOaEShGp9JKGBuyq+A1hiXGUmElRTg68lGKiahYV0LWumcchYTiXIgbqz6XKWqESZPVVgEXFaGo14MvPYAL7MD9Tp4jW8M9FKdivtEwXK2CrKYaBMp+BPDRUYdTxpPMmBlnvp1AOnTb6tkplyRG89ZeEMFi491yd1f6j+5jxIvUdxzoB8MKe6oW/bXk3Zn1RcxA000uQdZfPETziRf8WqdjITLlq9X61lyf16846jBA8HMJf+04wJiUIAIylY1+GdIq2Be8S0zIpma1kMN4ZidqnZEKyONv5tJzEAPfNCyY60EJOZeKEbEnYcxRp6euHrMN96bWDEy4209ZBZnq2FShzW+reYpZmHBWSYz25bKKNf4B+yBP9/2wkXWJZ8kT0s8sjbnDI8sOohBt/gUEHpdymdj57U9qiDdQCpbnt+DH/VgCOWMCZrwt446sDQgZyWAdNwBZRPsxpz9GnQJM0foTXW6dAaeNo4z+ZUvZYufPmjKmsVprzeV4P9ZSM/ddC2C33TDzIR034wGkpstT4wjTKhs/oNcnHho1/0I827X976XnyiXsAAQXP920soFZ+iduOFnS246PM6sf1ontoHpYvrL1GlNAX71MyfoxAQsAKmueKC8m8jxYRs9z4F9dfjEwu6d9O1nMtkQUUHz0Zu09ybFf+8B/aCdM4S9WA8mjdqZAithzWjlDXEdIPRkjYf8Hths0THxWsaPaXc7He8rEhzIkAiXs8mEUXuSXG73LW0xlM9FrwQuWdmQtAz5tlupM4qzuv7x9U6gXHMg5BB5/HtiJWD8Lc00sh6Zy3JDpy2YP2lMokEa15UJvzm+dtFCvG0adH7Ds+Zv4feQY7T0n33SdZgN7L5osSWagNgXWk2oq3nTAs9D+FBZyWkAex690VdpMxT/n3+D8dNL31eiyR8fDioVEHy1PDoMw3Hpfcx6pwscJp4mOejcfnSEFJbhVF0C2JTpbYj5D3bq3XpayPo2cJuUJRkXX0W3C7RcLSCkCx56iPLviX+vSgetF4BXuhJpoqMjFLzFM16bsMHJt6CAYD5qaxBxcP17/YnaekdaaeaBbObJXkIL19qAynauYAvIWOA3Dg58/eiOQ6gJotrKuEYFA7O04AjYyfoz9pG2ka3+ThR+mJ0FlmR2RSd1PJijs89pduos+1J4CjzBAdtCLOH5Nl5gyR0C8VezmxitAdbaJ2cBIWXKQSowuc/W1JoaoMg7Ue4qJnm1jCQ8JUPocVagta/XCHCXIz9zGTD9EA1fC15C2HFun1W9yEem/Z5osIpnVoXSU1XYzCNd13Wb+vcdresQ38Ndep5tXnZbtAyZjpQTo46G9O4vpE2eH2Fkx77FADgDmdK9y3VAe27urLGkD7VaZbnRC9ERcquhs3QxaHFFXDbvW+m4kMB7GeLCtt+xtEGlF9N25TktOUbhAzdc6+Mg4bG+DPTffnU9cDA5iE8VP+JxQ== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5b5e913-2bcc-4a1c-6512-08dc70be9836 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 06:58:28.0291 (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: orDuLAgidwzKr3BiL+qJOjLt3aXdV0SJs7ZIKs/H4uX2LXUl3q6PTOnIexZkAxiN+l+hzmAPj3zrIcE9StN4tphxkP3ClNeAr7n346q0ceg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE2P216MB1826 From: "Jackson.lee" Add support for the YUV422P, NV16, NV61, YUV422M, NV16M, NV61M raw pixel-formats to the Wave5 encoder. All these formats have a chroma subsampling ratio of 4:2:2 and therefore require a new image size calculation as the driver previously only handled a ratio of 4:2:0. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung --- .../chips-media/wave5/wave5-vpu-enc.c | 81 +++++++++++++++---- 1 file changed, 67 insertions(+), 14 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 75d230df45f6..3f148e1b0513 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,24 @@ 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_pix_fmt = V4L2_PIX_FMT_NV16, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV61, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422M, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV16M, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV61M, + }, } }; @@ -109,13 +127,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__); @@ -479,6 +510,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", @@ -500,16 +532,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 +1131,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, +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 +1236,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 +1333,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) {