From patchwork Mon Jun 17 05:59:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13699953 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11020002.outbound.protection.outlook.com [52.101.154.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 815AE17F39C; Mon, 17 Jun 2024 06:00:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718604012; cv=fail; b=qRC62RU+0HA9AkdixwJzXVjfnxmnxAIjzevn5OKF6Wu3QTrv3f3iEZYQ5WeZAZcPZB3o9J1Ty7Jbj8FDrCwKFdwnl8P9xJmL8ktWck/cQfjnZfX4dQjHzPVgEut7mpKnTdLfIsmsmUAmrD1NInOCPJ2NKlfsI7GbbGDwudY9JF0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718604012; c=relaxed/simple; bh=Jh7NMn5Ffi08bvNN1CoE3ShnyByaBguMtO82WgWG96c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=LbMFaLJHONOZVUGXJUFWKyA2b34W3THxsJy0dwtjPVkvN4TSSmd7jMcXlrkm42yZ9nF3PgjULs9CkRI/7DyX6bbDeG7yTHwdn8HW6rsq935HriScq+/0e8hHxhYe4otVWNito5Vk/A4UJaFw7wxB8s2UeN1BluP7844luPqPcC4= 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=gHhjQIUH; arc=fail smtp.client-ip=52.101.154.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="gHhjQIUH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fdoA6/cvwBetz48ZwGRuy3Vohvmq3PxQGicZ7sf5cmiUWpkLlsxpARJOUj7n6XhUgD3R6pMi/QrbPlU6urj+3rpDZbH6+ukfevQhtQS6Hztw2M81kYKpC+aFYIxF7q5eXZR/IrYNWPBXzA0+vF4uvj4DYGVLCZ6/WR9mqalYuvmGc29VQNwDCKTCbgmB4dZX1BnDtvYQ/lNWpwKD59Coidd1nL5wTv/HNafmMn24RMX4ZYaw4zT3Z+QOpGBbKkvhUhY6Z94zQuZIuafHIF8tWci+nJDwg2uRelaDE/lCfMExn4cKFJ1/hThyV1atQszgVXLHz4aY4bF1H/beqq/PTA== 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=wbHaY/RN3sriw+PWqSPfBhyDm6vcvpDz6rCL7/jkTlk=; b=khUb4c2KCza5pJka1rj78nhand6jGzVDfWk7za0Uf1mdWMwxpeq2HSYo28K1c28rHQnqvXUkOb3kusHGxeRf0EIDhu7QfZJrCclVJAPoHOfXretjwejvKjB2QrT5mHY7bSfXqXfX/25Zj3yOUvGDH1luJRNsGt437bwWmbGYHxPrnK7/nO9IbNOgUhIGw5J8iFhmZe5zQVZBTGnw2z+R9GTLa1pkFNJequwC2y8tn5ZWNdTcPfC27fnEswmBj1r8egYq6ZqAJJVQJpDL+TU3FN+XvZITAUTcG8yQkmiAaWcK63HOxuyfhZFG0e6HXDxBeULzk26GOVVn6EMTxaRHLg== 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=wbHaY/RN3sriw+PWqSPfBhyDm6vcvpDz6rCL7/jkTlk=; b=gHhjQIUH83yqA3K8NonBpNmSQhHzO0XPhy86ZRI7Uh2bKlNF1BCm8WsXg0bpGDuWGx03H2Ss3bdrw/R49Fg7WeKnLoCqmWjH15BYK9AfHmEbxvFp2tEdg4o+5yeB4NAaV2gxfQkDG8+sc8mOcwk6KfDZJLPBatGiv61xtg1cOQM= 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 SL2P216MB2063.KORP216.PROD.OUTLOOK.COM (2603:1096:101:152::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Mon, 17 Jun 2024 06:00:05 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%4]) with mapi id 15.20.7677.030; Mon, 17 Jun 2024 06:00:05 +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 v6 1/4] media: chips-media: wave5: Support SPS/PPS generation for each IDR Date: Mon, 17 Jun 2024 14:59:54 +0900 Message-Id: <20240617055957.135-2-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617055957.135-1-jackson.lee@chipsnmedia.com> References: <20240617055957.135-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0153.KORP216.PROD.OUTLOOK.COM (2603:1096:101:35::8) 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_|SL2P216MB2063:EE_ X-MS-Office365-Filtering-Correlation-Id: 7108f426-059e-4109-3809-08dc8e92bc0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|1800799021|366013|52116011|38350700011; X-Microsoft-Antispam-Message-Info: WxChFrUbV63onWN1Btp/kYA2ckrbZ41/2KMrwjXt2zJiZGHBuUIpu0ivaKpF0xfAjTD6bnsMtdq3kdyPNPtCNe8JeAOLQ6ooEbbtGHkI5kM8LYWJ4Yuo7frvgmlj6o+41ar5N+YPnvCoXyp1fupuBBh9gOKlKxuPfFEmYX5eLjOU0bhiddxzuSVN6YzuI484qar2gV6KQKHWlMkcwMHIEsfMQDm03wxKJH1ezA87Ko/ysmvZsiYXejcPF4pGGvGZMIyB0kbML3OIsT+v6KYmR8a9YblRRFtX7eY1heLtbTUBlXqR54fEBY9EPyZ9A8SF1GVkm5zRuPkMDF379FXEH19bIJ0oYL/k1jeYJABbtf0w26Eci5naCNspA6DCxx7pCtY8+8t4y8R+c9xx/DsLQ+VpjqPB4cWviQsBuJvqAlAgEZZDbGFBy78F5ZyTRFzJrwP3a60uIuWH6Zx7+eVvARAOg1WmNgLgfwsgXiO6eW7Hows/fuZ9mI4ispDWXQh+mpFcKsuJiPeT3Gr4yJlwMVHM/E66krm6UBsgmZoIenzrVcBRT8RvZEVOVZ1hLRK9KgXYYt+n1igwG4EkVXifYVXpVfClQREZYrfGiWLd5RIoEgm7akU/ZAqclxHoq10poVIrkHVujznQO6hSMM/Oh6RvPBKWDAOeWdckK4Llfti9jv2zq+ETav1IDVd6QPeGzpwgXeTTxrXDW0NTZY4YqWV638Fc1792Mij11Pg6YzG2Y7de9645b5YN8xMBvL9bsBA+h/BaeoDL0vH11dZlL0ld/Zbijc+DBl2tarKF2H/IRFzHj+7dacGIFKWq9KrIeyLnMwTZOmbrnhE063ghRSZWU1HNHvntT+3uoSwCoQ4oXaImXcG1A0ZRj7IetoJgYPoVqjWTMQ7ILPRoE+r9+uW7DbMEIAyWYWUypYmuSdWqQrdIGVihaa9BpdvQiYtCDYgjoHk/O9gx/T7ftRyVOdE714ZAFGfAYKiMmC75pDhSyvdMHZS7v3hQ/uROH/f55sRFlhzOoQxhsfToHHXAkzW5Ph6E8+DiMP+qxyqNKDAQAT9qd1Yrd8P3fuU03BRePF8GhU3hcFO+1jJdnwBAVkQe/noTTY3vEZGvUz7ZVQJ0x7xfmKe1wOmzCEAJz4CQXT0H1DV3iIBZbEjnhMQTJvra1ACNfoa/FHBUac69uiL/lTRjF+1q6a+Qr7XzpizjEuTLH3j8WBPBlantmYuwz7pnB2foAdvR5Vd3jij7dUGu2cT+Q72v/jif4IEAVdKtZeDmu8NjIbhoOBOC2NNm9NAKFVD42974S7Y8CwA8Gv5Fzj6MPoXEUiGoDSFcX38VHYocBITN0dSEjb/Tl6hOR2gMEMst171ciHI0evjhmPQ= 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:(13230037)(376011)(1800799021)(366013)(52116011)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rUCw9eroukbGrjR+SxbQO0NjCodl/waneicPDqWgp09MPLg66xiFvjGy/h5frEbO7e94j437ziogGGCY/vPRs4Bb7Yka4aOZbto+pfO86ECzxLzt87Thm8vJ+o40mbhUQFq2oty0ugi1A8Hkz2xDFgnligXUCDgAks5xF2vRnd3lkPBFl3HDRuGoudiD2OOLI1i6fbIOyCUwiFRJ4G/3LBEJSIge8V2+Tq2zkl3e50GRn1a/JPBRuBH4nHlcdt+Wwvzs6uEOr/Y82mS75C4E7Ea/ihF0VXEV0W1PlbgJyzdVZhQQBEBL5dL9E2vqV8zdcnDaBhAJZq1A8LoNorFWyZd/8U6LXpuz75t4UPE3GX9QUD31F7ZI0vhqjt1K70DmzUiRQGFQgVGJ9RiGMEl8u8fygeFdOOitF1AEcMup9PicZye6aTCNX62W9Ysm6o4r6jWzfzY8i/Raod0PWa8ifPHbfHloQi8q+zvDZoT13eJxZHCE9c2B71pAmKbYKgdcgg/dOoiEnPOzgHhu/Ys4MXaUp2Eg7d0aVPILBIiTIb+9QAvtZGt3w3elI9CsZlugkWTdV+B2WhLF7hCNpuZhesaBd71RwdCuOA22GUAM1JpCXrpSlNBdfgbdfwpAcVvPkfTvpYawDtAa7kWEADOmr18Xs3hmwhjkLX2Es5CFEZ7XzL7u1U1AVc9HmqGeqB9lYf72g7JjxTUTKVUNQ+pzxwQ5p+8m/ZIJtZKa1lL3f1m7OrnW7YxU95LvyOX2QzBGY/dPFdzFApLPYZp6XORsru0AboxcI/v2/eTwxe1kHK5Y7zsiDQpTmrBxuPozFo05iEF9LV2WOSekMdxK5C3B8VkKDCJeo/WPvl5mFMGnepK5X+BaUeGtLDiCfMJhqtOycLy2r6Wqff6vbobKmcumnYWmyRuV6k/GeW4I1zv2TCGPk7YSYCOydNTJ+9U/J1/4qo0Hvs1ewnwhJhGD7k0Msfa9FxhWDadd0tfGvAo02Eb09kFBgXRPaDl6v/aTstwKPDlbQNhidy7AYC39JL23K+gFeQtUAw3z8Xh+iAuOnCnEeiloI6r3svI7fuPaSoLE9d6QtViIZlerUnhKmpkOapfAeCHtmJ4p2t1/KeOuKui0glR9Rkuat9cjPHzy9Pswfo1mmp8OmNHtoEm83xXboL/0wzASs2v/pa8/Mw4rvzsgclStaR/wnGZWj2Tmwq/HkPKKTG+csOFZrtQ9ZEySZK0UD+P9bVEHyd/jqOFdUrLt7NqRr8CNIJOyxnj6wJlVbSdwJAqYIR/tWjwogxP0zv5QvOawZxRB+qsznEv3uJviqzUI/nf66zuzQ0ysOwmDzVqSByLY4kUuhCUzbUA9xDGqUwedMKkf7yYm5E1jVYHO9HpgoUt1EO+ujNgVG5Q7HzutyJ546iOivZJD7RmtmrTlk8WuVozcsLViJpm7TKrI1a09nfzQi1fjve4h+zTunTDmEREveQli5lExJyxjtXvgdUG81Hj7dQkZ5a2Kptu4nghOOps45UyNR9zsn5NIy25BHd2bVTXoeS9Ywa0mVkJkEwsWco0Up3AeL4OVu/De+ngdzIJp3FRSd9T4kiat2jDZALU0/Hk224uKOdDmLQ== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7108f426-059e-4109-3809-08dc8e92bc0f X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 06:00:05.2340 (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: UdDq+PoRuO5URgY6C1zv0nH/WZEUaXVajPnZ771jwbmvJd3FLaVIqlFNyhKTG6uNk11byG8Zv98X7b3qwcqGUtRRdR5eeVqkFFwqCekFOAU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB2063 From: "jackson.lee" Provide a control to toggle (0 = off / 1 = on), whether the SPS and PPS are generated for every IDR. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung Reviewed-by: Nicolas Dufresne --- .../platform/chips-media/wave5/wave5-hw.c | 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 2d82791f575e..6ef5bd5fb325 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) @@ -33,7 +42,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) @@ -1601,12 +1610,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 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 Mon Jun 17 05:59:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13699952 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 BE4B117F397; Mon, 17 Jun 2024 06:00:08 +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=1718604011; cv=fail; b=OGby8jThfCNFMC4vhwy0ygZU1mo1pHWuZMdX8FAadGktwAqgpNseOlzOdRRuFJXg+0bRsYTZQP8YaGOnPJRL8G8ePpzNpyugdjQia6iQkEdCx7Bny9X9Q3gchP2bMPXfuo3t7XvXrFjRU1moy4pdC5BKESRNwXC7wvHRbNFwAg0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718604011; c=relaxed/simple; bh=3qILsRgTVn2kyQW/Ny3d9ROv4NxhZc6gY7nfpP+Ah/g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=p0IhvgGZqt0/jiI3gdGo39AU/wxyO525FshIcS4Y2UdwZLw9s89JxjrvpHjO/M/jueKTeevqpS5KHKTzHhBhtPEoxS2jn+nBEodpuzrsQLXXXXLrCTw4hrb2xzAVcpVdtrKxq0vuUJF/jSJkfaZTR0ZBaWdQ02NdA9pfBQsqbaU= 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=GVAnSZ1l; 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="GVAnSZ1l" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m+jJmq0g79tZZLA4HrI6aDdTGFfPY7nLeZIWy4SREMOJsTitzC3uFpIeFRqGafmPpdOj1pKFWYDNPUnagOVXOwTUvevjGsDwZbW38V/Za9e2V08TyRngQIv9mtTR/nbQwyKkb+tKnitI8fF46xCvGDwGj6p17LNQb5UNawp0c/sDIANEFcIrlYxPojApmGhelghcyMUOzVWq6+T819j9op7xrBib6n9gKF7La2LrxYBd01iUkNo0GAqQw9PFTZBUQHQYoZOAHutSphjRlyhW/abqTUHHT7BFbxKAtxSGXRKrDWppZjFiTOhQUhC1DEl7VO43cAAwiOCgx9JT/jxNPQ== 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=PGdEGCEqHtYBaCTzewF2uQr90v0EknKD79yzMufk/lc=; b=L1S8qYojTYUf3Wsm6NhQAEJk3cF51NvmL0MwEZqvQ8Le4g+XP9WjGk7ex6OMiSOCNe40n7/1XA8ErtVK7bNwV/csKg+Cr0oRxu6e+60ixXqYQTnGBKMcN4bWyGRaYkx5fVlyEnGw0lP/CJ9zAVPplMoR7pz/3jAh4vtmZ4/PzZAnUnKrHA1mgrEt3SdwfeKhraswEHqOjndtHYTHtfRB/x/VFObbGl7nfvFkwsKCqx//0wXwPqaC0+LU3nrbEFAbvLAhxsyCph4v0sQIlKz6WfgUMwZ7cX505CrKm2EYwhbFeQ+KaEcrzynOch7T7scC0IVJ6S0drnDQib9whf3J+Q== 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=PGdEGCEqHtYBaCTzewF2uQr90v0EknKD79yzMufk/lc=; b=GVAnSZ1lr21skn4qXTd1PvZOLywoVoq/5QO2jPRSciIGfz441/D84BQO1h69xxAfa1IVRC/EIY1XE8w3Jxi4flESNg68R4fZ1x/NzmyQA7SoQ1kEeJ39zf2Jmbr2QON0FqLCnYT48eTOm2nw7sJSixvJhb2QrmUN+YKxEBakcOU= 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 SE2P216MB2915.KORP216.PROD.OUTLOOK.COM (2603:1096:101:28a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Mon, 17 Jun 2024 06:00:05 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%4]) with mapi id 15.20.7677.030; Mon, 17 Jun 2024 06:00:05 +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 v6 2/4] media: chips-media: wave5: Support runtime suspend/resume Date: Mon, 17 Jun 2024 14:59:55 +0900 Message-Id: <20240617055957.135-3-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617055957.135-1-jackson.lee@chipsnmedia.com> References: <20240617055957.135-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0153.KORP216.PROD.OUTLOOK.COM (2603:1096:101:35::8) 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_|SE2P216MB2915:EE_ X-MS-Office365-Filtering-Correlation-Id: 5991487f-6956-43a3-71cd-08dc8e92bc3a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|366013|376011|52116011|1800799021|38350700011; X-Microsoft-Antispam-Message-Info: N6fehGyRT5uSm3Do5XCgQaYUPao+8SB1G1gv7jepkDNKzlG7Punp7b9YrB2tEKvLmnTCglvuiV3lE2OJRDep7aMt3J1lC4xeVgBYdO6NTGkmyqb5owbIihLRvvQk783wY4t66kx//zvptYvt5PK7WMwbtInR+pNSfqnxl1U0YnkzibQUGKeaAWfMEgLBnra6lvID1baOTpkJWFDCmeYdtYFTF2Cr4qKh/jVW8xVX9VaeX3nmYpns4HqpXxCdoqslOf7OeUQFC1Q1MFv+9VdNO03wMg8tbNusu8Z8IdZjij9d41YYUeMKl9zhIq0UIMVd4gfOVbaUCAB22h5Y2nkVdP95zQRRVn07wz7ZwoWGrLSoflY9d5J7TpvDPjsb877xQ7/XKL00b2fvasFXpjEX+Tej6qCLRnmZIjy55fzp0gtQtIVN+GD10EJORLWIq6ZmX97dV47qB+p0vDkKcnkf7CFl+Y74KtRy56iZ1WHX7xK8BYBOp6rOJujq/h6e//qks09YZO1YHWHUtVMft+iIJYEn0fwWDPmhC7Qg93tn3wh2IyDfy+DWieaJuzSjbGhEBhyu0H5ppXN0x061GtFuEC84Tsn++mC4K3hAT/QpFL94euZnRHUSky3Aw5hKaQOFuwrTtsFyU1cIzyUTC+B0fhE4wZsIs2sFlJZaduu9WlV25jAIlbd7MYjHwB2Yzth6fQm7He1uB3jby94U0upY4inBRfblAATWhThvVaCyYuaa2DGI2dyXeGKCw7aNUORzbEBnmwNEZpmlFFVRMfmiUP+gdWpwcbr5BQC/BDznH/qtof3FVal9PVu3BHRkItxZmVMaI2LcHTWzzTYvC3c/sG4Djs5XJx+byTjPdqb9eJNqWIUts6ylidL2pvhsKmy5FJVcqVOuPBehPm2ofJjcE98SjC5AQjrwmxgOb4ZuYtIkXpSx0uV/Mk9KOnEw0jH2Sp+xs2/k4U4rnmZ4tbr1xFHp4CuilNFjqJ87fhS62LMKc73oueYx3cL4LRzGRYjd3i+kCa5gl2Wb8EtgKe/1jjlqEt/f0/3tPVFZ8xFHvnN5XbkGDk5prSg0Ogg3woS0Sk4MPww39umpQ1AUJPSW0RBn5zEe793kN6GZrbf6nHjdGLDHPPWj4fOeLzIipTClX6YBEbNM1jYbPAT1Z1qok+9su5DF7K8nlEE8Q0HWa6GENxLmJ1bDTSJXAzdYVVPN/Y/KZU5Ulnx32h3ZEAuCaLNfmXaAMF4swWcgTFy+m2W4UQU5UOQimEQYSGQp+QCrihP/6Oij7kWe4nIA7oTTl6RILEAITvDv997F7Mb5DeHlf9zS8qO25sdb53qUJeR3uKgfSeyBDZteZ5KM6joA6SId2gkc6dBvqnrA7sZaHQk= 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:(13230037)(366013)(376011)(52116011)(1800799021)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VjvroeG6379pw8SEcbc1viWgBURNpsFe+TicXcjVybU5aeMzvLpNzEwzl6woPCmuVJOh63tlKsM73NX9Sr6PFl1b69YCrlg9IFM+jZHbfjqMtq3r33p4b2cetMFmLgSu4AGU7YFdMfFCXvf/V0bBRA3VPrwYvL7zwGiVbNHcvjCjg695kw063nyVQKzsUeLISCtq96g93x+2UMuLHrGAI/VQLqLj1zcI5/OkoQEVM9QRnzmwFk3ci/Wyl0JrMf8mDxICFzS/65Jt1EX90cc/zSxOocqcBgI3zf8fpUgswEVMYTiHoIFDNFCKNndacnvDKITgQPIogMWz5tEdpRuN2Gcf4vJW0Czer+hiUQDKds9nvl6G1PuKgDSV+2PmGcX9QBgmYfgngvILiLjrfJKwxxeXmwAxQ7LKXOZApv2c1KjDCe89sMhHGNVnIFHVnhJxDp3tdrYKcAB8gh2YdGA4huarCUfAjRCt4MYqVUpUlk9AHgih7NVNsOFxEpJeAKKbcT/cJezJtp9gN4yY2+UInyKu/YrFGn0fLwtIVsTe8A7hP06lt+O3FrwcjbMQy8pgAy680ggPXRaxQC3ghqZFV9qaFCb9jyOcI3gi7Ck/MtjLHj9SCH4OvLKwIsHThOmpBW2rXvNznxDwNW0SJl4OzMBocJY2pHmo0DsEC05YUZDIzldxxEorDqihPIBkbSVLSeXUNb2YCoAr3BwQQfY5fPJzIQtlhnYfx0OVpcas/YZS3lZsqSNYCEH+YC4rbRsFFX8FX2qzxfutDp7eyxMkdRfRRvLOHcQzriQq+3nk2esfl+50lEaiYQh1/J+ULbFOv/OwKm5/yo9HnktXUwkGQ3OQ7ExzU0tfe7PYpLtBqOsc1XtgBLqr6ZmP7NOD7bCPvwcVOWFpCahdu0VzMpcJ2WbrMZjlmShgJiFca/KwAXOPELhQM19Y/CQjcY3tyiCAANRAbHZiFAPl2i1pbQnIn2pJCZr7NqXG6OJ+VacgcGppRhDeZyM4tC+nONCfCAJZgMgPraieXeZiz03INC6MpQoKPdXEYF/LEy+Ez6T4fBbkWjYGglWuoAEmm/ksNn8CBD1VWKOuLP2BN/M3J5JnakGqGf8jNJ9POU3MWqfHyb0TY6Xu/YC4qflj6JTc29rznDng8lsWEWow1eXNQhDJBmpTAkfDZJ3jbpo9m303x2o3zHwysib25Y4JWNWBsFvzrdtgjQ8YesTPD0f68SCg1yI9O5DNWbrWrZ2sizBPGWZ0ahnXoiU7F5xYy6pm2hRT1pm4Fn/sDRg0z19C4x772XbPkYTYDPJeD5ERVpXCkQWbTlMTbahm86KLQBFRdIsm13sSx+hH5pEOiYhGhyo4MJ2I70GwFWOCFwsifV6etOFUwz4Th+nuvXkXQpe/RkroKCi9l2RDvYvsbP/l4++M9dyxVh1lEFsLXchBoBpLFDIw/OL7nQUEfcPZ+2Wa7HM0HQejCxmvEaqXRFmHsJwM4QI2dydJ0kcOeaojIEnKYFHjEhpXNle62yQ7T0xxyaU23o49DyR0GBlPmZpUHTuStI3OHOygiJvuC43MzaKEPPBzFTF4UX8PKgRWW7K44uR3X1dcV6QxXvATPoFjwgDsZA== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5991487f-6956-43a3-71cd-08dc8e92bc3a X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 06:00:05.5047 (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: uwY60Ndh5o0ajbJkaNok1mRP/ED/hcrxbKGRwF9cRIOTsF3iti+p/UJIqi5Wz+lRFN6TEuJn//5+QxyW1QN+zdMpNy6tB8OYwBirsvgV9oQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE2P216MB2915 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 Reviewed-by: Nicolas Dufresne --- .../platform/chips-media/wave5/wave5-hw.c | 4 +- .../chips-media/wave5/wave5-vpu-dec.c | 16 ++++++- .../chips-media/wave5/wave5-vpu-enc.c | 15 +++++++ .../platform/chips-media/wave5/wave5-vpu.c | 43 +++++++++++++++++++ .../platform/chips-media/wave5/wave5-vpuapi.c | 14 ++++-- .../media/platform/chips-media/wave5/wave5.h | 3 ++ 6 files changed, 88 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-hw.c b/drivers/media/platform/chips-media/wave5/wave5-hw.c index 6ef5bd5fb325..dcdb1eab0174 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..0e7c1c255563 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 __maybe_unused 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 __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; + } + + 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 Mon Jun 17 05:59:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13699955 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 95BE31862AB; Mon, 17 Jun 2024 06:00:13 +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=1718604016; cv=fail; b=rpHcuC7KJi+us34w49k+FZONGBiRUVpYpTKADrm/ffZYKIT25Nv+U4rGBCZa/E7UK/0QPeF2LHwVVKWQXLK8gjBEV7S0GxE3TyWUUQmQ6FFuqolTQEsyjVu7JbdndwV/UCbvwPutp9gEtC2qU2B1o3jxDuBMJjZdhQb0FM32cVk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718604016; c=relaxed/simple; bh=cj6k7FJ+TvoYwSUkcIV0CMR+aNYb4h5Mo+7wFSSnkQY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=RUioukYHIVfTu+9Bt+UL+mp+MN8Ut+9I92Pimh9VlotYKKI+UmKzAE8vsV5SBexg3lYEF0iE/TtHG5yI/afIbaTjmoU2uBJjKf5bkbW6oyhQYm37J2kSO8Irn13/ixlm1eDkPJzm8aw3dioen59+7bVxByYp3nSaTRM0B3a5Ca8= 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=FSL3aTWl; 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="FSL3aTWl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d9TSfhvyrkQlq0BJ+Z9NIhUiUQEviPSJMxgoaxCSokl6gRKjlPBHE9JSPm4r0Tdf12CIIYvCxTDCy9qZJ0UmG2dxcESzLo99c2irVDtOYVU/LHEYXj71I/45l6+OhQfTus8+M7MsEPVRO2ZX20awlRWdmXPiJTrwuIgtC4muGtIzqsyYsiDjvvLf3uglSNZMRh8UhICSQbwMWHCoF+7lB8XpbKlUItC/jxmYZQPcLZJ42BSiRLUPpna9fCFpAERRScGK92QOWKb1iAHxU/ROF9epQTBojr0Hbe7v0CE9R/hm1jGLP6M7J6QsR8I4IO0FX6ZpX3jVa6haDTiqnDP2cw== 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=P88Dc8EteJWw9uikve/h1QIxOpXc7QN+d7J7umr0PEQ=; b=cAYxZqBNkRf02wczOAhqA4mFG8e4EPLvFLRaXldH0CZ57t0IgiAyDN3OPFvJ6cVhQBln7LtWIeXJhNhi7YQ49iljlmzzqWVJ6zL5Tp3ziCpk1hhlxxsrJdFnEKcwH7xawWwqW6BNf2W/XFVZEOucSFkrOPyqftkP9YdARopYQCBK5+Hx3RGI4KZwgjeiGkVJNR+nNPyt3JBQLzYypDWUjxoOV/fASMQg2KtrIzru4LZCtyoecZxlOGyFf4ZTQZshWwr3U3nQjeBWirVyz8zVpzGXBU9v+Kihp4FB6W6abFrOlQ7gCO70rtFox0SDb1dSHX6FNGVL49eMoNpO3WtQPg== 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=P88Dc8EteJWw9uikve/h1QIxOpXc7QN+d7J7umr0PEQ=; b=FSL3aTWlt4iifPcVmxyMi3Lr3Q396BaHQT5IvjrpVPLTcMIoznKhfPCJ59eYRIoJSmz4QLazG63TpbwErWeQIBW/qdo0BUYCSEpQWd27jnCAgSuoXcmyKvRgl4vc5MSzaM5ZpkSYfx3e+lrd7R4bXQmaD2C2Y2JyAKClf9gSWBk= 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 SE2P216MB2915.KORP216.PROD.OUTLOOK.COM (2603:1096:101:28a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Mon, 17 Jun 2024 06:00:06 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%4]) with mapi id 15.20.7677.030; Mon, 17 Jun 2024 06:00:06 +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 v6 3/4] media: chips-media: wave5: Use helpers to calculate bytesperline and sizeimage. Date: Mon, 17 Jun 2024 14:59:56 +0900 Message-Id: <20240617055957.135-4-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617055957.135-1-jackson.lee@chipsnmedia.com> References: <20240617055957.135-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0153.KORP216.PROD.OUTLOOK.COM (2603:1096:101:35::8) 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_|SE2P216MB2915:EE_ X-MS-Office365-Filtering-Correlation-Id: 3cc44624-dfcb-4bcf-4ab1-08dc8e92bc61 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|366013|376011|52116011|1800799021|38350700011; X-Microsoft-Antispam-Message-Info: l7lZpR8gFCckO36/B/8cTzaI3CvrwbYafQniYuXZdhbgOAqO5Ty2gScbJzt1ZeANXoMdXjbE2dkkuANZFRPeZhIzYvzvWc/bFvEPaeZwKdeDziaqBYjyLaY/qjWIc/3B/7L9aQLmGrWTtns3U4aYUpqAw/Im22iewEUlraf7mZ73EUJaqGfV3rRgrB/6Op7pwhrDr3YfyoZ+WX02PRBO0uY9j8IXOk98i9mZ90qt+8bQd2GVRPv9F/TbCX2N9Pqs0klsWQBgQOtolR1Q9gq0OWhCtecqS7qcJLiewFXZpy78BeHjqeaPtAj6pwGBNtC+TpDpuoy5indqkAxud/nSEitw2UxuXOALQag2EVayXG1zqIrJ1mab8z1lTxIQpmgareBONBpjZ9pHMcKpCgyp5XWn1hd+SHfHWqNtv80RC8ab/VCB6gs5cg6/OKayLOBbBIFAQu9BsWMKaJo9gs8NvC2D11gc5j/ZUP4AD/x1YU8XXvBt00+vqEsgh264AViWSR+c0tBNslkATFIV5ylblrJIypOi7Zo4U4xJ0aKWdkJ4EWVdZq9iPOvevk+SfkOAymsGcavkMzTKmK7AO1foJvm94YCtKI3FedKZXQqnF7Fh++9k1TRb4j/3i40SS8gqU3FYheGuu2K7cdS6AybdVKAZubxdbzDXLs2so8uoByrwv1ODp4Ip71HEdtA4CDj82uyuk7Hw5Z/z5ZNpKxsdLuzVQ7n6BFOxr5Vpxmda1FkSmH+ym9n2jagOs6w4o4Db/CQw6rn/CshgADfk+qLEuBjn1UG1m8k3JUak7cVAr+jpC6K7w/7ve9K4IYK4TyGOwpM13XsEUpjPNthEgqW9ff2l1Nph28YQwVRi2M1qDDixhnt4LchSxU+8Zvk0/2Q6NxIMLd9aoCFXDVIlZYqxL/X+NItS87ffhke1WR5+yC3TSEJC3d0Qb+XXHbDDfj3AiPVYO8PBBd5HRnlMVKSxVxEBJ+Em1Vvrl8IXKlsT2h63SO0okxhlcVVPST0XoYjtXisoTbWcLDQ6aZzGFPcLmX196+eVvw2eKNNC5Cav9pLHm0EQBc8m3QkRRp0KmCwLIYsG/HqRMX+D9gKyMlzwrbHaWbLvDyqoM5HaTbQhUMt0qM5z86SP1BmmEfspvkoqWCPo3nIIePt2aJTIZ9GaVMwvt/vkzY1JSH5oE9wy4WezPu5ToxNRbzz9CKjPxULTIWgdWhUvkvqiVJUJFxscABXF8KxN1lxnz6PbBSfhhRBl5lSUtP83N+NJiUEROVl7JPLUPcV1/jgWpk2ATCXHMM5vYApeITpZJgeHxPmu2XsTn22k2hOrPezuq2fLpfwJYPneNRMT84xlHovmmXrGln27GAaSZ34Vkh4XSQpLHzA= 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:(13230037)(366013)(376011)(52116011)(1800799021)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gToTwKIlCB0tA+JiaMXY0kkPUuc/HNyWhz712U75eoAbJcuhFeMDznAzfwQNr+BWMblJGUAQC45b8UymcM4upXRXw8MUbdUzx77JLug6thkjKgFAimIpbxfoOEvCV+qteUbBq6rJv9ZVH/4Q4DdnkfyMScxgQFMdF6ENG+h7lh4Q8u/00E+HV/b1yaSt/+yj/CZhBMfzmZ7isot9GlolYl+OoQDxPj538l3+Yf3gi5oc+GPKQl5mwwdKmGNCkTISFs+HuAnM1ZVOwKzOKHMI9ONmXC4UE3T4fOWOMtDQ5ilciJNSA8PZY1KjkfJbpNQfbWI2d1xD2On2nz1ATijm1ZnFPUX8+wtsk7m5acHas5SyMCWfDybHuQIbGLIGN8gNJh2YG7bP5wFBQSdPPTNtwHmeNWeIyvddyOX/4V98PeQYdM0eWPfyB/sk/2nbc09GQYPt2Y5MxV7KqzVK3IfbC+PU8hw89CtgPORO2xs5PtjlyCf4Z378xlR5GbbeTF8AYuBLJNgpwy+VJ7b9vodijukNcIL9G1r4KUxqijChVNrYqbvZgviA598VZg0vrCIhULv09mS2QXqkPukUa23Q2i7orFU5aNYYuObxQt/dLMeobxqyvELy/o0hTe1K/e7s19zez7FnsIkKLiNuOC6FtBEvxwD9aJo/WW1GCIyJkWfO8+l9lms9iIApK1xGXiYb4pt4OPHx5gNEMkL0koME0LnjKtF6RhoGKAntNx5d4gSdDG3JvRuopEtpAPYFXT/ZBFkLeqfUk3MhjcQ6gNfRkpiVLkM8Yvn6vneti0seYCX78woJQ+O1Yr481kyzXDmhUDYWPDbZyRgiic1ZxzHYkI7+gXVso28Dv/Lkj9fNW6KwxlFj697Ws3Rdk72TeUawE4Q5hElsZshD8yQFiTRG+sGbFHVfzSLqFMKem0CQ64ZUYU8nnunbVh/DPAOhwKKz7H0H6GG6CQEKW7/ensRVEkgEXUZqv9zvk7UbTIrzNQvvs/GXCNPOOs/nB+fKdh7li4GLFLqKD13KxJCUsdLuaXEoJEc5asRUfBG+aLMs1IC8AI9gcgqA90eokHBJPlAS5qxG8Dl5E7IMGEl3sUF9lUiGvSmTeS4L6EYwh9I3PwWUp2M7ts8I6MagSQBFvybvz2hg4F17Sel08WLciR9myQ/JOOEm3r6RUV2CDKPdNiG6cMWvy3jpGLje+GtnQ+CGBVnQeSgkya0IzSpaAS7uySuO+H/ZIcElsR/hwUHDkL/ap/RbXNIpB6KN3OOncCeUG7v4jKyk/XPk3Sn/7bpn+5bm0bz6eRM/fm2gYgy/kR5sUA7K3KMk1o8xFFKYc3Phl7PrzL4TkctXW95M/zj7daGkGp6ysi005wwpyTVgzh+cnsigycmCtGCeOCr8ET6wosZvu75awWyMqv6oUfMVg2WS/s/kv1ZKi5gf6suiHiv4DKKnXKfk4ArlLkPeahhdpAjCkA5s8Sc1YMqru6zDc8472192mRjhLsPvJYi/ScLhCzUHqxkSXG3XYe7kyMwJy3hX+Qy3+N2JUWnNfMtpohZJO9qHX//0dtGMW+gSzNe8zB1T+RNAIPbgRgN7Jb3GvNATaJjYUGraur43Sz0b8g== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3cc44624-dfcb-4bcf-4ab1-08dc8e92bc61 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 06:00:05.8226 (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: M6lZr210KpIqywYQq223sn6CSbpz/oLPhRZ7Ui5xbvoDCclwnsGqrz+j6LO5egOa86ZbtOAwMq1Vy8c0ryj2FclIY4+9G0v64APZ1ZMf2Z0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE2P216MB2915 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 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 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..1aa5b6788266 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]); } } @@ -1564,20 +1482,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 703fd8d1c7da..a470f24cbabe 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 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 Mon Jun 17 05:59:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13699954 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 A8F96184134; Mon, 17 Jun 2024 06:00:11 +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=1718604013; cv=fail; b=qJvgOrNLIFLLsRbdDuwiCxKKNBsRmpO6wHgadrfq0ao/4pNHofapxhwdBI4kfavHSizBDE3unNwZ/hzUil+dZmK0nMGzw9OjRwjoJGnV5dXfG7zjEPkUZqQATD8gZQAqw8tMnZ6YjG4INLKkbES+HKGZIBiT0JJ8JYMLTHRnsP0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718604013; c=relaxed/simple; bh=VMtPjfoOC0XTH+riNVMx8QR0jvlY6HzL+4rikDpX08E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=M5Lmpt3rxMGQWCBV+54O1NM9xPyRqvX5BYpiJfzLwVytL/MtnoordiIQZ3iUdlrwEy5tHYg/iv42IiLecOtVCOrk8sIHlSt5P72SKW9tiF6/scuvlnSseeDRIOVMXTFQ6MgRvchhSyWkgySyYonFeRl6rO4eTuN40CPS2dvHXpo= 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=gg6dydMr; 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="gg6dydMr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GprCnY3VSZaKW1aN4zlUB5y/fgiqePpTZsK5HuV4jegSQdpcnU4matOFUsd6xbR+zDBKPkEb73WdncfSfJk8GO5jA27eZkC95u7OwXmtWgHXIeWuru4qAFkm3pfLzQEKrrWrEQiVwWdX44n5RT7VpatYMXhoqQ+N+tLNPJACmo7lc94IDdd1xFwFDTZi/1Y2CnPy7ca52McSVB4MtxACHmxFYBKWjR6DyRIkKvmAnE2VEIkgxtnaLhEdkqaZWtkWyDwHQ4qgOLjCXuh6G7dKMbxnu08tssSR7r/wFMOLoIVa4hfW3kgZE2GcXzlHqdSKXwOklIDfYc9ClTbqH3ralg== 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=r0rAwfhgGXe8i8mWUYHlL3qQfx2HZL4rsIULoSdXt5Y=; b=nxvwjEyqyhIY9pR3ennf2Q0V/CGth4JaqpDaAh64t/kKYjG8fEVx5UajmjHyum5yhCVCemFVM2/dDo6jDTU+fLogBVhQfcVWErkMlRSlDPk5DrANtok856kcQ5IzKi4jdKm+aOIdoA/JVmPx9+2eIkwgizs+hbrcCgixzY7khI7tMT3gmdQBuaBYTp7lXR342K9IszDPRjJgwx+SrByBS73pgtubTpUIfZfbxFSSRS+XH05bte5WDhoteW+9Z25Gwz/LRnA1BXwQ+a3PFrOkTJoJ5P9JJhyni2WTUNMQZP9AoEwsRlKJHfxXswJc3e8YYkxBx6/4lE3oiaWSQMKLhg== 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=r0rAwfhgGXe8i8mWUYHlL3qQfx2HZL4rsIULoSdXt5Y=; b=gg6dydMrVCDW92vjmOMRVpKeoxJpmAIZ08bt+BcEboJ+R2BfiguAfZ8aLPcrJXcsgL1LjyRTQODAuRulBTSalbJ2Z4TXiagm8lctHUMtkR4mhgpTN76g1osXP0JZZvSJEjUxAioqJ/jmGAoFGilYwpsYegPTGRvdziZHTp2FKkg= 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 SE2P216MB2915.KORP216.PROD.OUTLOOK.COM (2603:1096:101:28a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Mon, 17 Jun 2024 06:00:06 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%4]) with mapi id 15.20.7677.030; Mon, 17 Jun 2024 06:00:06 +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 v6 4/4] media: chips-media: wave5: Support YUV422 raw pixel-formats on the encoder. Date: Mon, 17 Jun 2024 14:59:57 +0900 Message-Id: <20240617055957.135-5-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617055957.135-1-jackson.lee@chipsnmedia.com> References: <20240617055957.135-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0153.KORP216.PROD.OUTLOOK.COM (2603:1096:101:35::8) 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_|SE2P216MB2915:EE_ X-MS-Office365-Filtering-Correlation-Id: 432afdf0-e15b-4a5b-1fc1-08dc8e92bc99 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|366013|376011|52116011|1800799021|38350700011; X-Microsoft-Antispam-Message-Info: A3lvt+LQ23/QlTe6GTuT00hLOICEJnoOxRGut2x7SUlcbrfRk+CLbyWjFJK4O4fzAKpBptVF7tFAwKeKez78lFyAhYTdTuEp77G2UTnXONyHgWqF08BXLmezjw9xUEz4w20UyMcJB1QUQjCVjvhITSnQZuq6NqMyV2z20SgV3tLLLGBtBExxyrRX8rB6uY8fvbkaPRbTibb+YRxtbgVitrZezMBvUWn/W5HN0hureJ84T7FPzxHji7vN2WKUpAt+B3ZUE54lyOybOfS/fM7Qj8GkZLGSkGOAU4U+GV6UW0DoKj6CIlc8Jlc1bddM6jVS9fpP0/FkpgsmdBngJyGsSF3sEk/r+RCEyKsV3u6gnZ9Iw281JzLrHU0Qj0TwSr6UUVUuqVyVrFVTgGyoIbHNxACwvNlrx25SEughU4r28oMk2VbipnGb5odkUi2qQQsLpLNNv2YreyD/su4C/g6nrEYVoJ6H90AYsd7doZJhgw3YWySmbT3bD/JejQLCXDczOU+ZH9BtQQ6uwkIQm4a+RGh2lz7k0byvBFa1DAD82YA0nEjAwctrrHyFF5w5fXtQOM1pyR18cfHn0GmRgbm/umbj8yjSJo7KYBsNiSywrFsIhxMVl91KwtQuvgl1XofY8tXpfxt7MvTwLAZwuJkSRrP0/WE+ZRxzHE1YiDrjy10NNgr+YWraDUrSkFOlfw4Frpwzf26k1G4grk4c69OYpNJ+Ur49NzVnSTEd55xjg3Abu/8tctJ2AjQqtdcZuszg3C0oTPzl4irQR34RstiFFXdc2XnuEvdJRSvkm+1i0j41REYW3OVPRYpK5HSM9zv6YF7TU5BRwqIGUKRMLI8f/vENEAi8VryvyYZPOlijAQzVg8r+GBvDGSrVGYKRveoPRC6WA+n8j2ZHaOYQSguMtZhEVN0GeXVYkz69DZPNyT3HqQ7nzFLoZ42Yx4FGZbpZzY+32AY8MeayeKMljToXzr6HRGKe4WNRjZEaLtjQM4A4OGM0LIxB3oHH6cVPi7r/A/GS8qD4SSbH3S01OC+OCMsVC+IUeCmVHQbJDnJr1UFGpu2tYi5Rw9e0mD9E0A/wnrtX9Ut4jJgFTSj0BnWJH9hzJlIp86APOP8s6Y+VfiLEDLbuoU1uldhJ+DukwnY2rmr8DRT2HRi1yFMmiGT7XIFJpzIn1L91NBgd5c6RZNn+V/NM/TAwXZToI+buvoVzTeNeW5HBEDvPuHIge/4LHpAAc8/7H3QHnFYiAGD5nS3Pzmo7N6vHszxXZu3YAbbKcAKAhoQdMstZ4x6wJHZJOvmn5gZGddGaJ5BBWathTehGxyt42Xk9IuKFZSo5L8BWEabXv8Rn4YWoOneGJqROXVZ7xc02Zerad8PLAXZOvJM= 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:(13230037)(366013)(376011)(52116011)(1800799021)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7qu9ro4a+6tUIKX2oJlPKAxtcK1UhorrAspa5szmGYbvpsnnPJCBUfi+gfC8qAY2sTiLuJUYEZKFuQGP2etzg94VRWO0fKkuAVrUcqyYRarlCzabgNmfksx/BWO2ihs7iqsoZoXPPSzNWMb8huHWHNQLapPf+brDflGh/4ig4uslNrGwvydv7uAfL7Liuulqcq5qqz7KJdmwEIKvAMhq2sDTYdBDr47ToK2ETlOycYoAepTPPVXj0z1YYndjgLCJ0rulmlMty880AXrrVbGAxFzTnNktMjty16I2kawt3ihNNcHJSMgRbVRniN9c1lq0B+cENw87YvArf0+AUHvww5z/1YR9dMO59/hflZGBGZ83TbGNJsp0f8r8hhzxpYF8Eh+MfXZ0bj6ZGIBds9B8xfNskde+kgGppJKRu6Bvi7Z1gNpDnFGkoyIPXyPaWL8Pr95qKteH7DlMNG3Jgrip+uotiOByz+KJ4wPVVdcj7DFDEAOcUi8gauSQulyaLWQvvj8Lw312dUUNIpN10XTyOA6MfPHEIKDl1TZ9CZROqMVy3qX5Bn0No4gfI3f+C2tJfgvLpzgwFM7/LwzJ/71xdKC0EkfVeyOpPPwPC9VzNofKQHEsVikxA4zirolMlCS9SQeArYMGyrAypIMr2KrWc7oWgniS/vhVA4AflT9WPd+sw201lUltFOA66EovJowPflOxEsMLX4PR8m56F9SJHm5+tNp64sho4Q5xE9mi6seO6rPFZ5enYh1xrIja9U1aEw0j1Ai52ehq1JTLxG0P6kV4G1H7EO6FutFZxCtIi8vlwDlN+JWCm6vWChEs43q1n7e9LYXNRa9SFJocgWdtCnsFfB8awUBIVDbPZnhVV2qcwY7VtoHEnL34ssorhwTCRLE9ttLK3BpPMBsH6TxyY5UF4GTYegyzAn52k6yPa9wSC6PUoy0/TmuWrZ1pRFjR4I6Qnqj3nkk+tKnNPKQ2W94ceZXwF/VSyNuB0tHmHKrUZcOmQgrCei5Lrs7LDnkwZAIqJvLeejiTbr+09S/iC+81z3tYabE1568/DjbDAP0q6foWr3/ZKav+ijWId8Uw9rc5/Zgu0xhXH2kRGe5ebJ7urbw7mb10VyWZcsg16oOKo0cPnRILk4+8g/74QaA6s/MoJG5zjs/JMBxTlWQh71KQEpRVhPo4dWhWB/4NOucMhDsdQxgw+Hsi5BRIV9yoptpY4aMhcy9oKsdhM7fu+UZJCcjp3UjGlG1Ejboj2sQpXmX6RblRHXnLO/xdi9aoUlc5oSA3Vno5B6dt5gVR/MKSbTuMnkRtVaNdGWPPITO5u5YcuRMiGY3xayNwfRy0JW6B0/vqdh7bRPTo76pZFBlQxjpfRAyZaVuk//vdT4Yu2Hyq2q2+z0i045fLDn/zdCxBuAkF3elCDcb5ASkTwP+Y2OaiLBi/ZHJ+7LnyvA55KAPu/p7Xe4k3iSKzHKy7Fq1b9dThwTNY/zFI5TLElv2qOOtnk8QTSuHPYS1reesJWbSCHLYMNk/64Z6UFev4zhF7BHc5HikLSZ28/1dThHkR5o3g/n0LKXnaRcAq3G2C2vakmVMSbRR2Nk1BXJaluVDUEaSz8ymJAauE8lwOng== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 432afdf0-e15b-4a5b-1fc1-08dc8e92bc99 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 06:00:06.1101 (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: 90iSjDrR7SJNUba01aSq7Nf/dhe26ftwOvhHFlZK+gozvTYQ4Wif6wu/QpCLK3tqFhzOkNNO5Jjdalghp7l56TkBovVqojoPSgLsFq7wcjM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE2P216MB2915 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 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 a470f24cbabe..fee24b427fd1 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) {