From patchwork Mon Jun 17 10:41:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13700485 Received: from SLXP216CU001.outbound.protection.outlook.com (mail-koreacentralazon11020003.outbound.protection.outlook.com [52.101.154.3]) (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 290AE194ACD; Mon, 17 Jun 2024 10:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.3 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718620932; cv=fail; b=uLPMw+PDpHEBoNCE2ewK/crr8xo5J+rLRHf56iOhkRO6+LTOyfZ0CPj8IeeGNd6OLcCo5QWWyadzYeONFsIbpRxN609X+SJLzshyAN/maDIbcHZKtgZVcn/99pJ3cC1NEmvHEU3BodfpgejTQqiD31t+NCNj9XA+PWlonzif9T8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718620932; c=relaxed/simple; bh=Jh7NMn5Ffi08bvNN1CoE3ShnyByaBguMtO82WgWG96c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=sRHddX6JgejWnQSzGQoqOHFGsR6Ba/c1h8C6dQhDfxKPzMMI0vw2tVxQc6tRtLfnyP8AJXRUdbCVj/q3axe8F6phrinzJE9odMEPIqpIzzhel/tSV9pyDcQdTozzu5w/ArnJ7eWC/po6OZIA/Q2/ZgocyIavBhrKfiLmlLj6NcY= 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=VCw1MaKb; arc=fail smtp.client-ip=52.101.154.3 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="VCw1MaKb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Av4moj8oUHR9FcEFkKYni2E6y1nN+rojHHz+8dmtGishUxZUEghnNjcwqkFMYyNG1RrOz4tQ2+IBshWRa4/5vFLAy7xFJ5i7RQDiEZnfZULFKWgfc7KWUIxhWzXxCo3GLG3ZCqIDNIyWJIKAzLOeRsK0wNob07AtdWdQmB/DJC7ulwSctyBbteAtTwCvffOR431JCFDrMWPtQa5F7w2zcD39TYoryJhhQAfgVi3RJSDvfTTilKa5DdBR2ywacRq7//Yrv0IK3C4gZHuc3tN87iX+cutLXw6ddq5EHDL5rdH9nk62J6MYIOgGqBlf/bQNLwG6ltomD6EjL+Nth8KOcg== 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=IAKIM+H7KVuC09/4ebJvqLRDJkCBGX9ccHbgfrRnqR7IOBAVNfY7NJDlSK4JlN19cxr4kLam9+KXBro0VWFIkuEmcdi4owM0+nyuLn0lZh3hS3STG3wLUwR04V20MY6k7+PcksyQg0IMVtg4tOE8ZEMaOWQP6RkynaV/fN0JV+vtACnayZZwUgVQpa735noUlKGbci/qhT2b9v2i63f2gn39Sou3P7TARyKDD3troIjPy89rej9VRF4fV8rhhC4/H2Un9aGEpaLNJ6m8/X6WBSs/sg/XS5zwcbvF4yCZIn/E8iIrRJ/uluZkRH68TJZgcRstiKukTqiXGK36jefU3Q== 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=VCw1MaKbgjCKkQErF3EVQDpYDjy7Xzs7fND2DIpydQgJ3RKGmc9+qaOAkn+7Dcjbr5rLi0FrE2esYJOhuln6Hmf8pWkdzb+9xj+r3rIq5xbYWJlfwKwX8ZCwJoWxA7cPsLGjeU/et2NZW5FaqT3GBzETURxFjm5PZcvzS0GlaCg= 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 SL2P216MB3099.KORP216.PROD.OUTLOOK.COM (2603:1096:101:282::9) 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 10:42:04 +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 10:42:04 +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 19:41:52 +0900 Message-Id: <20240617104155.153-2-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617104155.153-1-jackson.lee@chipsnmedia.com> References: <20240617104155.153-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0185.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1a::9) 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_|SL2P216MB3099:EE_ X-MS-Office365-Filtering-Correlation-Id: da95ecfe-e864-4c9a-c3dc-08dc8eba2058 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|52116011|376011|1800799021|366013|38350700011; X-Microsoft-Antispam-Message-Info: vEDBDjYg/qpkk7Hvx2uRUC26eyh8BozgX6gH67e3rTQkTNzSJOhAroqZLG8zBCTJD/qyOyMsydEPbTdFOVDxfSv62X4aGEN5OKKWnQ2LxTiZnLb8bgy7nDvBSwLHaJcWW0hedcrLwG9VNYL7FCpP7v3kFMkh+6HNKwmap80hZ1MDEY4xiZizgQxoaDghZFL0VSVb8BItGOU3BpM++DBEhiT0uTi9CP9VX/rOyascSZMr6jYwZgibUrPCtflWUDJfZM42T5zXHisA8gx+ABXu+VSbcT5QAfkWDyS/MyhrKUm8HHPAHpPtpBDpqc6QfXM6uC4VeQIdFmuldCyWfKEjFjZixqfiCtjukSZ7EfOl5NaGWXjSFjq0fXPpEIVVjZ1z4FrRKff3bwpviOXciIiE85Rc7WxgQC8oY0s6FNcgqLXJbXpMvzhmGHs8Vqbgn1G/hDOVty65FQ33ZjxGzCoCe3wlUVbCGvQ+hcTJYVEDs4+x7d6tgAIE1cOFGAKSQ2JpuQTSHW+TjcQK1Rxsf/ds8d/mIVfjbraTHQePAFVlbJ0Cq+iHqohZcopKVm3wU2Tw22lnd9/nPDNJtEp8Ju1PSHn0yrsg6HVg9zvTg3oGNxc9rN/Z88hFk3LoM0o9jK16epLdAfVVbThsbgDKJjiWXM1cEMCJ1pG6O4d7mgiapA7QQ5DDIpAnO3zOxoVyhp7toN3pXzyd11JVGeyy7i/8jOe09zJYrXMCRuWN1HPYIyiL67SgeqOfLHtIu9JpyY+bNiJHDH6ju8CL6i2TnLi6QgbrgHrZcv8OyCdU3YBgdXPV1Mx68jaY8goZZqvqyBlNqSw99UO0HWaK4a4pXlwY1IZgO4KjWfRodgZfGUAOyGKVg5O66hAur5/t2wEyC9eHbRemjB42AMVYwDc/iikrD9wY8rKAUs2M9EApTPnMoLzWKb4vHD6NYAtwaIIOXhKwIfF6c+oAf7EpUWbLBa1ZkgCIAViamVxYSIgBTz/C941MUPmZ2sksuwuHVNPOMFOx3IXyjCs1AAihKF9+aPyXXUAf/Dj5M/NW5s1APZl7RfVURmcElSnCYgGYEgeF90LZZVt9U496W2o5ce5uB14cmwNGGiXGnxENMK3S5zd1MNxoiylPdHS4ZjepFrec3OeAeo4BvRdhIokAvzUFvFZzZKzyPhUNJRlM9d9bs18xxYcM6MgzP4a2UTiw9dgdM17Mv6s9tDgL5NYjzcWmwT8/K/kaEJEkMDPz7D+jXwiq1hawnSlUd+ZwofifbwIXEt+k7wwP0+ZXi8ZvI5ukiUCR8gXVWc3jpM6MooBS4a2fwN6e5lhDsjy7E84NwWhYMr9tYTT+ELx4bmGyspceyzRP2H3MAFpt1xqmeuQ4pWfBUYI= 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)(52116011)(376011)(1800799021)(366013)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7XqCAJ2hwDzXU+3f7hGqGJDjUyBWXPpXfZfGxCsPjw5UxMMhzuYUC+GaMDfjm/d+Y9uEd3gZVHjWdt7jrXqd6qwgxF+D1b/aZfcA66eW9rcJpFrKhn9rgcpT7weLTact3MhtFjnRYrtmiLNY4q5Zaf3N3KTL2F6K+NxeUGEuaLqXutTulp6OXOSL0Ei08fZzITx8/nVh7l8nlljP4TbkPxjQNRDJJWduLHPyFHLmeM0jJD0WEJrzJusbWbvLOjRKh7VQIwmJiirKrNCa6wDhoGlHyf/MlWzuS5B8Gc0vPvRC5TIM3+OvzETSzUQnWiuqqJIHYB5b+ceJRpTbz708droqWB5cyeG8sfVhsN/fgmEGLqCtbm96euf6YC2xFApm0y0CYzMZf3YDN8VnZ7b4LIO4zYhgr7H5BkDinaQIBehZ6FmnjLvtWq1fCXiHm+YnPjzDy/z9a1bwiMLvlA7EvpP5BbhM9XyqlP927vH2PHebhoxhcgKBmhPWUKYMMwSSBdeuzG6pp/ajyEeiER0z/f22AIEtGW+q+pxXAivIjkDMYwJ+ABbWUT4l2IVjsW73W04EnOH8S0W4OYUMXFiarpFJh1/Fmh1xbJ/El2pUJUgBPU+EqLWKxIwl1CrMvW1EepZYdPCa8BEeTBnpyEs0061tfyZkqq4JuBctXLzMVgE0kMEvAMhrdJGwtxjJJqnAedGSJtDvKsWfRQ9Y2M36SsjAH9XcaqxUj5g1A57vw6Svi87z7oxaYtVdBrRNy0gccQYUaq2+1vJUE8h3ryzoredixKAaktkg6Z2eHOl9WeZ3a8glgT0YZjjAREXl4GNjsRIUwc5kiUzRFAxt5eE9osUwL73AMe5VsyTpn1DhU4IT01W0Yvc5mtnbHrmCevIpLH5ddR2xN6uab8CFluKU40FSmrEDbWW52Uu/FWl0tw4RHq0vGHuy8WxXpDoplQfeUKgNVOvodaurkGdhAPFiIQgtgH17fONYAaqHxBWeo1h4JpSAX7klzp9kIyAFnuI/s/nAZc6Gl8FTFzUbZ7rCP8kRNtRMMFgvaADu4wl13ieOSF8MjoG0VPK8seGOgh0qYw1fHgoRX6HV9Jh8WDosRCEAphXanjc3xD+52oUeMX9OrK+ga8Z4liAOYQq2HeiSBk6iQVK6BGXdLrjmUgaQLgMvzBoVWuqIcs4Ah/yIY/xEzcGNfMSx64WXbo1OcQvnNwBjrewUecVwLZ4o+mRlEGA2vciO+TkOLPDet+ir6T3k3342zCXsJC7PNWPwoebraKUgrec4BNMVPbDc1+2X4vniLZjk/RNTkVIUED/yrGS2BxitWw7B93HeykPmLu44QHr4SAvQcyuE5zPLJ4VPu+oaG+zj1NV4xmy/PbBDgVKlI6BIU1tHC0qjYMy+7kPIA0KNcD3eMXUCKvFEIWUYYPEl+IsvElI81KNHHMdpgYLp/dpXm7S+FOYK7TCGrjdQ71uwnGjEzYoPM7qUi+RWr4rIW0YTDk7479RONfS7rFBJEc8yh21mr7+ZuZfbtqfM84nYM5gaqE1WyXDd3abfJHGyxZMn4Z6SJIbc9dxI+j0/cgCG8yy1S/45McmMoJKkPeM72QtK84xBqmrmd7JGgA== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: da95ecfe-e864-4c9a-c3dc-08dc8eba2058 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 10:42:03.8790 (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: sNNRR1fBg+2LHEBRP7uCtMhUWCodUVEUw+MlymsyW2f3BdpRgKlCLgoUVi1YeWwHRycydtjK/RY9Sh49x3grUM4tjXwsrCCdWDsNDrjzgUI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB3099 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 10:41:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 13700486 Received: from SLXP216CU001.outbound.protection.outlook.com (mail-koreacentralazon11020003.outbound.protection.outlook.com [52.101.154.3]) (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 A3931194C67; Mon, 17 Jun 2024 10:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.3 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718620934; cv=fail; b=EuslFhI/KTEDFlK+PtMXQH0Ch4hRTcYpFpXRbTAgMji65I2IkzIHhVgKvWI/Luw/zbZy3lZ4oPweVXuoYn0W3nasfuYp4WYonZkPyMI2vkD3dNo+jS5PGp+jW+0BnXud1QVVpHov3e4ZW/jk7a9yQ8h+TFSS+o5HjkgV98MnsGM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718620934; 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=Ys9hIHheM8j0VVnupBQpDqFDyRRH7UYZE+d7fW1hb0cLT6QulYL/M77sqRTDPKYMpY3NLWFksH4kv+xF4HJpvwGuiQNGlZpWXclF70zP8tcTQ9yz6Xn8AaH4zLJebNTxEcjv527gow2AZrRFB/A1ttB6SNzn4SbLVVA1IKHoxcY= 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=VtwX9kbf; arc=fail smtp.client-ip=52.101.154.3 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="VtwX9kbf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VCTQ9LrI1kRo4hP6h/Cyq8nc7qyUsKt98Qn1CYfUkuUx4LbNZdCM3lY1zAc8ruwxJ8OhgTb1SkPhB7tAtYgo6rr/PsvfFnEKWW4tvaFleoagtO5VmUj24TjqUxSxfYHKyFKTAFC3vK6+n4bLDHMD3/roTZYyx39gJY431e/PO1SnfArFESOPyltWK5HNjDy2Mbitj8eKwHPJ3UXTvyNyDUCK9jJCitAPdH6oGDeE1MayTndwBykfZbWlpi3Lx/wha7snwI0Xz2TmdaC+vSrFYBdvNFvXXJSzKywuzedkUHekHBTgys8yn1Z55q4BO+/c047FKe16iMEYznON4A0cWQ== 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=PJe85d1I0v480cjEDigFPxbi80KQiwMUdMljTn07UHcrUXhsye79kWHNe3LUfOZqkxzOE8otTLBmz/wRVIjHFTy+8GcDxD0/umLl2CemBUc+5xa7BTkHVI+FMRu6dbqN0EEWh57QCtinXHR0Kkj82wakR6zcG7eQKoJ/fHV/IzsezI/saoOiHUcYOK7UTRBpWjL3wa2VpqoE2vhpWG6oTJbxzJhWnouoA9uX9aKglSy75xRa8H/zj+5PDTRF7mGjoehmnGzlQGnaxvdIucfAjLJu+TzV7fWK1tr/ZOyD0GUeEJamrNABBMQsn0VvqWy+El7dE1l6w/HNj3yUtos60g== 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=VtwX9kbfCPjl2+vdI8REWqU4uWUtYjQY0jYpTcVMr/6hbvv3LY2lDRCYGprfnup+HoTq9itSN+GKJTm4P/CUOajR8M4TMU/nKKtGye8yWRScj8P3JGXyRxtK7oihM8Nmtwzyc6v6NN7UsIeyasE77Do+mFanjrLzeB0kJkjJCy0= 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 SL2P216MB3099.KORP216.PROD.OUTLOOK.COM (2603:1096:101:282::9) 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 10:42:04 +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 10:42:04 +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 19:41:53 +0900 Message-Id: <20240617104155.153-3-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617104155.153-1-jackson.lee@chipsnmedia.com> References: <20240617104155.153-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0185.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1a::9) 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_|SL2P216MB3099:EE_ X-MS-Office365-Filtering-Correlation-Id: ac6e8ac5-9581-47ba-6c70-08dc8eba2094 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|52116011|376011|1800799021|366013|38350700011; X-Microsoft-Antispam-Message-Info: hLbAHoNPzp2s7+Fn7qVTh9QE6qhFgkpbCNFtCgp5ZDOpMi4HdFiz8rZDntpiu4LUcjiYJvjNRp3cSNzqtFPVzbWxwF1nhfDVK119ZsW9vdzCuUzPv0JAnNlxD6sUxC+MSdZSUzxeGUE3Z4mpG7Ey/BaOXNQg7ARYXwk/FlPOdfEzhEjqd5rCiReOg/pX+59r/URun742lNW/puVSY0i1Z9yarpPEGbFwn1pl+tcE/QJDaFSVFe9HakQSJn5hIU1PbLjnq4iLoTsD/tuP1pfE1zjIujKACCT/8qdoaMzVfB1h04aEfx8YFlU3YfNyzSVlNi0GXUoNuJrauzNr47BH25vgXwR9v0yXbM9IpGhuv8XZXoTuMPexK8PTZFXzpMl5+u/ZmUqI5Lua7L21LOYx+zHGszwHJcVG4yb4jAR7Jc3vj3gFIRaXHX8wPX/xfV9RGmzaW0Wr1oyXRu+Imc4pjDzNu4WUTRZdltUTz7N0fVK8u5R+I2O8+61mybve5kOs6UnPnOJ8VzMrg9UTE8GsGGOddCIBbEYXMlF/KCVqm4bC7qZaUXWtRJRpmQheN0d6vAsswFwhtxbo4SVSQBGqK3TNRPjtHqFwiWitWvRpMck2FBs9QUoQWEJw95MkiuiKy45qzoqt34a60x2e/OwUaTZmD+ojJ7QJzddHRkSb1+Q7GWVwNQHJmSuRL6pOq75D/OOTuTvBOTN/ogLFZ8Irrci/0k9M/YyV/FdCQgBkl5fFEuOXkQPG5OjjFLWfyUJugWiPA0rTlbHIWB9U2wWHxVTUpggu0cIVKXZQqgUhRncaHXhzHv5ovVs9joTpQpgGG6qcCLQvJxAl1rDUJH3mVRiVAWzoME0ddSjXLrzHQMAU58pJm7WL42coy5zmPThYG/o/CSymjZPoKZD2g/Ij0zWS8kqXq2jdPNvUnOQfAo3NUuKQYFqqQVwtN6UynGK2fajmeXuxpdFIXhsqInaLiE09NVsHTxXixFsA62PBI4mOWBSZmGwdJbJBS7I2E9ZVmvriSAKEt7hM8xH88lphJ2psIFl5FG6pNyRegKDG8iVrPdkZhAhm9f4HRVjXWVrB6zslo7BNRvimGWEQM9TxAy2kFWGNrWZUhG/Ct0wRCx5DhwrtAPFmJTvyLAb28LgWi8BqcQNlmazWRPa9vUnrez2Q4XnN9reTj+licse5cPBa9+dA4H82EI8TgsnPRocEaETIhViegUodt/gGTd516rTIse4RwNHjNgoevP/7m7D73BGbhbTdYQ7xgu0Vu/XpCgdnYviXBV8TkTFua2+fZtl1N94QGkCAPvNdG0PX7xj3MsHD45dhbDNS2X3oTFtXP8lytBEf0EDFyzYo+qMwqhLI3MUpZVLdofKIuG0yfJ8= 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)(52116011)(376011)(1800799021)(366013)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AayNjS9Dn4BHHQJB2sRflFYnqaO97jPvznYqKZuf5auFJv2qfRaQbQvcbWnds7BTjfL/kplYk4HCR7CFGKwpH+swVIIXJEkZKryluLAaDbFLtZPv376b70UzR4ZCR68kz26W4dS9HZ0iWVvtKl8AIMGkHtCzs8fj1jZjSuldaABqq3a3cfH5OLIrcnE8muC8Jb5Ey9iNPAC6DFRj+5ND+fjs5RoG/QHABJro9x0keSbN1sJtLW3paL4tKZ70AvjQG3eyuIm5OmbcnEeS2yWjJYozHVUvC41CVff0MUyvZmmeZKmPorosx1zI3bZys0hvUkvbazImS0bmM0/1Xphk3wktzB69nODV+NATEc52r7i9mieeoK57MZULKMlc2pSmfbfS8kBddagXYT9vug11ttuIwwvPv1xz2EOcLv6VfZPTLIWxGjyqtE5weJq4DgjnbXdn/QqOFV3hMHdORZ3XRI0vOpG7imHOdoO/Nv6di5Ufj0NXa0+yPkEoTC8dRvWJENsqARKoK7wkytrPkyzsqHzz+Z8iGTMcVCdGqxG9IplhFdwhC3rBkI2qsloNYVx1rQhWpXyPPwMvFb7wphOGbOKe+1uvcFW0wp67p73R8vktsMi04P7TzTkrA1djVsBB90HX4BzPEJumSOc10UTIOXT4PBx7CQl+e29hqt2V2WNPohNrAiVUT8HN1j/nV8zGcsiwCVgcmT871U5/cV4mp2kY/nvRpJh/136IXTcuuLITt25/Sh7pgESS+a5NaIWvNcokPlFipM0HyU6mX7ZKZSlB0aobnh0MvIuaCre1nWtEOvWwnZ5oMsx9FAssHM5AkIRRUTGIKXj54gjO+jYtO8hefLvyCxeI4qS9frzVt7YHty3dp7FW2cCwJuTgHDfXyqxtfxzAq2vvZHq0WVBMDdwPUyruV+xs3lm1WaMa5rX6thXtJXqsiLvKO+UUG9fi1SEs4+KoLY/FNjl9KOX/L4R3th7Lt9aBIeE51LB2IsVcT9c52nuj/eIYAFFMnti18sRfK9PXN+t5CTFLK1U8VGtT+AubQ9UJI648w5HbRQwYu8GW0iEYvx7UJ+YOKFUbhCVYfAaXSd6bb9p0m1mi8GG2Kuj9wVCYG4OBpTHVeQz029qAmWFkzHISQ2f5z276yLzFAo51lJK3dypEpwioT67K1zmC934jMwE70l/zb6r1lwFFu20rpxpAX6Lvav+hPxhk8bRuHsFuZkKNEsRN3ok7vr77YK2JRQpd/ZPuSBs67yzahPZmMhwS8rVdX3N9R6Om+dCiI8p/dbXP/mbBIHLr/06JtxEg94nGmBcxwmbBLR0PhsjvjM5joHtFCxSi6zE0MrjVcTeraARlWqAyXG2qDJF8xBNSc86tlPtuSbKrqCrPJmooo8SC9KNstjDu5gCPBuEP1wxXD3MNVbFWVdjuQ97pkxpPyyOE7ZTu9S34rE1gmEqrf+QqjCM/17mQkMAvOuR0vDiLcnkLtvfXcsZXZh/GS4RNLjIuWK7EIgu7y9yK7JHR8H+MAkIsC8RA1td2hYazhes6eH0DB4PReDase9Azq8hUmpJQ2Nac5MtMAs9GyCPEe7DR5fhzl8qhwUYb/E5tBVB/aBjE4qCuYQ== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac6e8ac5-9581-47ba-6c70-08dc8eba2094 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 10:42:04.2575 (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: Dv97GE4ixF7HHojuGAbiyTLyKt/vvfjOZQj0uv7rKgZ1y+JO1vz4l7YNZ1TIyD/rmoPY6LEgZNY8qGSRp4NSSdur7z3hlS+qOs+rsDNclkg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB3099 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 10:41: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: 13700488 Received: from SLXP216CU001.outbound.protection.outlook.com (mail-koreacentralazon11020003.outbound.protection.outlook.com [52.101.154.3]) (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 3657D1946D1; Mon, 17 Jun 2024 10:42:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.3 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718620939; cv=fail; b=G9PqdsAW0wN8gkW9lwcGsiDOOUpR+NN9YxcibF5B/wjvbXv+k4eFm5yNzuievleCBxpobR11Lenn1gIli8hvU55G5Pfmub4ptW4T21aq0M8y4YDfzg7KvaZk4wXYjFDf0oKyN+oKFqKvtirOK7hi7lc6m5j8fkNXZRlEcOav0xQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718620939; 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=FxkGx4/5muo91cZ7tWh28yr4nhisjYBF04np9gUw9W6k6bzWFchSZ16MX5gXaqEd/+pnZR64AnKa+pd69h/ybOb2xl3ccnrJrvKK7bVWbxGAUXvZdezLQxAtO1H9i4PuzlcrRnREaOhlwB2GtZ2UDo3y76ZUhA7uaA+lGoNg5wM= 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=SMmyjnMl; arc=fail smtp.client-ip=52.101.154.3 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="SMmyjnMl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eJVJ+H3rB/DcA2cW+iTaNE0jmpNExL+ZXP6S+nyg8TIjr+d8lm3luv+eta3ncRzPAr26PWNExOndYUV1Y+B4gAKvLkYvpxxMYPG8ML0kDu6YvKVmM7X9569XiuMYl0dOo04oGqzeQxmAYW2rWfSkVrqw8k8Cbvye+ZK+xWLZj4X1ORXCs0C6Ghi2baG1EP1Xt7dwjFw0gk2qnXLrFcN9Ax06hthSHfHp98rJnVfLmb/uE82xRI7zmLTNEi0isTd3McvkI0EiHwfcUkJQ9FQ8e30Bejiobl+ugVqhvVeN3jLiWPSV6iSiekivGwhE7Vjm8GC8U2pYOn44OYGMgYi80A== 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=lVfuU4eeXAqciHBhBr0qoilf0GeBToPEZErGedaW8MbR0ajVlt6CAPNP2al91xq5x/551CUsgU1+yPRrTPykLAMbIeGWSsXssrotzOipCJofjBV9mzzObXzlAcPZWkucSsgPQvhqOX9eHNHJM7UBzLgN56GAjDi6+dR5lhwQMcgOxA23iGxTkeZ0UuT9rmOWQE64044w7oZfdV2fjPf7odHN0+t8p2qksgXBu1kEfa/KrWhL9Knu3JsqJnJVgyNdYfvHIkSigL/nAGANRPbAm/ubK/OPL1QS8mPFLlKRQ5oU5SmLi/iwGpGUnGw/cVRdb+J4SLkEzWMNmXeafU8bGQ== 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=SMmyjnMlkrWJzoEqvf97vqUb/QebnqsDKA55l9MOibghOJckjvDU+Sa1xY6pLBOQvXOhtAG4WsNVhL3EYSx4k5mPSQTr6VHSO13CgiEtdgng4s4tSXrrZyta/fRGScFW1+UGJaqdCQef58X+Kd4mJ1f/KobjorRs6oRjsMbY2II= 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 SL2P216MB3099.KORP216.PROD.OUTLOOK.COM (2603:1096:101:282::9) 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 10:42:04 +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 10:42:04 +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 19:41:54 +0900 Message-Id: <20240617104155.153-4-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617104155.153-1-jackson.lee@chipsnmedia.com> References: <20240617104155.153-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0185.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1a::9) 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_|SL2P216MB3099:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b4a0bbc-6fd7-474c-5fc8-08dc8eba20bf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|52116011|376011|1800799021|366013|38350700011; X-Microsoft-Antispam-Message-Info: yaJtV+fKjP6H1+2w0nde2L+CV9IoJveO2SDH5MuOdey+OW/NcznQo46JtUE9BnRs5fKp+8n+PdZFVXMRChR82d3IhUvu2DzwLa3IifSlL1meclx30/oh7fHNIKD53IHdNXuzIGOD0+vgN6udhobyRsqoo8TthcDKzOVPx83mvml7T/fIkULQ/7X7cLEHU2Net4q0ellfP3u0hMNxQSwLEHr6MXNrt7owF5kXKXNsvG0JT3WgMOBdrN9QBfOmd6Zi0f/YAcV16Q8asY0EAaU9ZtH44pFhi7XlF+P+42Abbw3MbUmgqZfVhPRm7AtSCxXWDy/k5cUxSEsbYukGnN8XA7199S3oIuQd6to+Ca+SBV/BxqTkthHUdDWC3KTez8189wNfRtcg0R/UbGskOodyL5Vqv3II0w/l425dmuAVUKwuFKnOIVfD1rmgku2qy82bNyqOymm3ZluHXLraJ5/fqjdFodvbc16Fjnwgv9GJaWEUQD8AbhE9SX8/8gvt6XzPE+I0qCZVHqA8+n2XnubHKpP8F2oP8fiKI/mN5TmteQk4YtYWM564bhTQQYLNFOsU8iDzZnU6XDkwsqOZNT7ofcQaN0/laQqO6b620myGEUDHVwVnq1IMCY+Amgf87k2VHqJyc1m/aQ7bLHHk3ZmzRTPmTUuO0o7hIToFBtxFE4W7GvurDc4LcPKTXKLnO5Lu6KnK+wL05GeJ7JRU3OnIql/Po3DxzOXJdWIxDvxJcgDCCMii0yLjaOEm60xRyC05CcXKoMmRsubX1Ax3eOHWhKVdnrkhoBM2lrT1t0eqowEnpnAmdHyPrDNcm/zNhxcO7Nc0kPtrixZXuJdIWBHwNcTRyF/hTEBgUAgfrk5DqXdc6geCqT+SrV9qM2YvfHN0fNW02fWQVr8a5rfxnHhK4E+vGYs0KinwS2esjviSeKN1E+3ioTB2Lr3UICGcdqxAoYcgmuLWxoYmFdpyXkZ50wmugdrjgJm2s8PXOisNEOOF2jMKg7SbD9S7xkk72yRsH6SjqU2I2w5oYEy5Lba2SlIe6nhCpUoVLSUMIf+mdBrjIbKbcutNcB/orb23pZCNvY0JKahZFL9gMqREgEJpk0omQkI6H+7zJoi3ay+Ixp6USr8OTwfvEg2Q2IoNBqxm+qd4NZV1YUF4O2mrlbQePpRmlNzNcgeVhuLWZJVv4NndTQ39tHGUY4131ez7EwRm+E+GVgJQ3iHSeFqccmQc7ui0I4opp/lFc55g81hlubxiIeX1OeIdAK8OaTiKQh0+WI9emP3FgXdPqT+fzx2QA5+lHFu26onA9Vb92ZG5xmN0F0qNtXfnm0kkhVzQhik+u9A3wJM1umw8opP1mD8DcXx8tC8UabKLzeCfhtu0La4= 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)(52116011)(376011)(1800799021)(366013)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v5hcDizc0EpqhYC9GRmqtNpSmHY4imwJ3Hof4TN3f7wrpN22rsEFnLm63UW6v8IJp2zWC+9v9RRWo8i0owpjz0cxYfYxIIdMiorbC8ZCmo7cY4rOgX9M1Hn2IAkINvtfPHnB+uBuRQgFl9HarRjptHImgVcaRJcE4dqfZafZ6rzRM72si5ycehuEFUSo3Sx9cq2WjLzJKKVj3y3/y4OVZ+LSGS1q9R6Lcl6ITNZa9cCIPWYEdSrVYpH6Uo3hRxkSt6eJfADLIw2XVLNNp+EspAW2q6iYaflMq8FSL/yvyx6Z4/sVwWn5a9iImb6r3g5hLv958w15XyX19YG9s99OGp6vsBxz5v5vggTizHeSOLbmf689baMI+bJ1h/bNyJHBRWyG95xIw7MoHPgY7MkFXLchEsZdfKgXr+mVuqDs7P7+VHMIgqDMGzyP44nA91o+0D+PNE650WZdmMArDKT4c2PJ5CZf5U6jlLfcwBovvJu9augUx6sp82scpzhagu6LshecTtPXs73p1T8TzQNDEJ4GOlVfeZ5ZyX+0rKDNETefatSZT5KiFOYjfsTL2qCmfTkwBDGAjfaQ9gmXs8JhiGLotFhbLFKkoHfuoQSMpEM8OMe0TvY2F1JRl69tjg3VFMW4xK2Lr1NqWHQRpivIfSSmPA1a+tFf0++7jDYAOf88hQU5s0Qq3CUqKvuRrBGo53pNgFgO94Xx70KT4Q0/nSXnr+zg5w1uOcVIT2nxJWonZhuSKWEsBbQmvg7cSaCh6twMst2i7Rzr8i198dWMzPau57tadCunfuoO3LOr5owVHI5N1erJ6VNrVWd0e2/T/wKS/SeiSH5b0VfWLA5G5LvbGAAuRe2su20IydAFb83//s+TGkOWirnl5hvET3JQeiOimCRZwXd9BFRkd5YSIGU0e8IlMjKd7Z8CwKgeKhkvfn3NNxJzWDE60LHoBwPdsIoc6yt/Uk3HvpX++IcVP9LU2YtrTGS5hGLvdQJACZ3XONBZl3F0JkiP1DjAZWiZCRNE+htF6SAv9eR71Mc/yO/Cy1O2iPg3WFqVKCabpHrIsFBlpA1yqoNK4+/K8jqRXKDTEgeloaXOmIVFfX9JvSQ7VU41YvV2cEaHNXpRsn5iGCfZDmpJHBAVZCuw91/9eEKpnXQDZTcO1CjHff+syjpWBS3wh9ewX8a3BqQ31fsXi9BDlzt7tnnRp0bOJQ4Y9s40mTcxOTnBGGGjtH+15k/sFYEnCJXNRVH3e8u0Cl3Y8qsXxXIJxAg1Aoi0dLwNu7okK56OSmbZwyLvFTo/pM2f8LGKwzYrdljgxB2JiFYmZ/8TWRh5/JJMZcMItjpMRmwov1hE7Z7qfdnos476tB7QX4W8pFknRsnZaBQUHspYXanWUvveH0bsKHf+dfH8D/gkmaMCzGqWGTj9zqR+8a8vEbuGBQ9ikz5AStbV5ALWlzn8cFHCH5B+sq2R1vXODLbY8D7VbFtUIr7/9wrZhCekM1U1nkp6XfGFbrmxJO78O9vLj+UKphjIfdnHIJzUvD975BFc1jJfN9Q43jwsfYD1R8sdajfNfZ4oPBZlhYacVqKmmg5XTAP+uy+DPjHzYK8veXOYlL59YYlg/8jUWA== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b4a0bbc-6fd7-474c-5fc8-08dc8eba20bf X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 10:42:04.5654 (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: s1Y5f9oZkCVpMWJWB8pFWY4qXaS9hWmv4CKCt5uwjibLNodb0c9rrepOdJlVuqcQQkk2Yho3INxKIdtGeT8KM4b6LETymoEYQk2bMhG6vxQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB3099 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 10:41: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: 13700487 Received: from SLXP216CU001.outbound.protection.outlook.com (mail-koreacentralazon11020003.outbound.protection.outlook.com [52.101.154.3]) (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 E6F95194C95; Mon, 17 Jun 2024 10:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.3 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718620937; cv=fail; b=VbnIQ9MKwcF7I+oGdCs4GEUQxh7oyzwXy06wh/Bf5XHqXFSgWL8Z8ZVuUX6jxqh+slyDx/TIkiy/rHzSK8Epj8kcbVyfC5kmBfHGmOkFdk2tE6bMAQZUGZb84C0Ok0K7pOfiKsqelIiL3Su23VtCgzmMDZ+6UtMfXV1X83bybRY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718620937; c=relaxed/simple; bh=VMtPjfoOC0XTH+riNVMx8QR0jvlY6HzL+4rikDpX08E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Ra024k2qaFPYsVN982gUvPNkgecQ3GRw8vgnKt2k55FbL7uB6E0M0Pa9kxnis9bNSiookf4Hq0uyHuZZH8kyeFkD5oV18fqQnj6QFGEQK964HdqDBetHZbfG1CSnHEpiobOuiYxVlPirCVPfspkCf8V+iNXiv/moP12Cc1sTjcs= 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=Tj03ky4x; arc=fail smtp.client-ip=52.101.154.3 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="Tj03ky4x" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F+Wx5oo9geXLYdfo5cmemMWARPk3dHE5lm4wgQs0mAOpPCT0ZFXfWBxIsgat9jpxCJAzYdN1gtT3ekbQm3Ep/Yeqin/TZCKH77xzThcnCkGbs6WHPjd/9niam9IBDiJWb/+obsmN4Q07khhZbsez5omPGmNCAXJPYdNV9EJEqbO6kwtcKsy2fJ5NSkx5j+k0eeczBd9xNYmKpauTeh4bHRuk4dCffuveE+T7uW67S/IAm43cdC1Jr4fEeyUcinoQ0I9ZEHJ+/8NvSPBPUKhztyjJOD0vFKsyjH3HmxKf7mMjsIaM7uZ3VVNUV7Z9wwwX2fxtN5VCHTlejDmgLMqsjQ== 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=hmZyle6/DlgMDtj7DTURU2Cpo9Flp8JPvboLvfZnvVMSchlXFCjki7FmbLUTENpvwWB+15dMB5hF8VQAX2TefoIDFQSB2U0EKIuBoSmC1TyZh8QHhLJ/41OmB+zGXRJ7I5YtKCSskMd1wxERmEYN+bLV+jzgOErfdVZIsFJ2fSXu3TptUZ0peSELfkzgXKzDW6P9vQNHm1ISznPG2zLx+PccIb9yX3xe4RPSahmH8AzXRTWRNamkt2o2L1VrTQFV51DG/vO859HsS/J0UdvQ+ALDWE51qanDFwvZAvQt0VNQE22krJ5E4S8IelyywQNf+fSJCh9fdJf2k4v4+JOzaw== 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=Tj03ky4xoVyPv6+7O+SgV+Q6WS28O/yDsMZTqa8flm9RPy71BVzp5W7urhFwhOjTjWexrHXksOYLxKya56IUkEW9CymLrL+dy9G1EJDzgAhp/r363AC+gBcOlX9l98XEJ/ZcDXQITBKx5kUFXX2jRQG1co0qm/D+YUr7yU+80QI= 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 SL2P216MB3099.KORP216.PROD.OUTLOOK.COM (2603:1096:101:282::9) 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 10:42:04 +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 10:42:04 +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 19:41:55 +0900 Message-Id: <20240617104155.153-5-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617104155.153-1-jackson.lee@chipsnmedia.com> References: <20240617104155.153-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0185.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1a::9) 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_|SL2P216MB3099:EE_ X-MS-Office365-Filtering-Correlation-Id: 85e7ccff-13c7-4fcb-465e-08dc8eba20f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|52116011|376011|1800799021|366013|38350700011; X-Microsoft-Antispam-Message-Info: dHMkfMTZPB1tHkAkBM/VHv9+CYTrmoJ66u/IeS4gLBO+OFQzMS9UZZJyNoIjXH67YfVNVliBb3gd1ey9ipAgrAOmZAIGrfhfmAjmf97AnftFyWSXvm4khndmREjazUmqeLxeReAn3WqaCbnCsjjm/QrvrfnS4C2CQIO+coWNBfN6UE+27Ozn9gE67LfHCBxcrgiwPUJuliIHMUskgOI4f6tLA/T7coDqFyVIM4SiIdxhbY5i0TCQERGqwvlDR1/DO0/G8VPYZvrd2iVWAbXFSp1XkKZ9HokQlKs/ntcvvIlGDLiwGMwGXrs+Leb5nH3zbLccOOOhmQrrZAJdQtotMzbMSwK79zRvNNulcux8XgAYQfoPjpd3Hhb0ZKq9DarBIkKRTqYl+Uu4fDzfL/1OyN5i13+GzqPleD+HjDvftDrnmiOjBug0aQAcXhblMBtIYIZlgpjykDfGjajxdSCGqvhM9Grs41YaNPvmRpJcdTgLPhrupCIZLTUIJsdkm2oD0lBXqEmSDBCwblzonOK4QJJwps39p+nBPFyovzqGLgI7KWHPPk8nEOGlbmu8jMNbTqJLr1AqYaRVdynHOrYLs3OtOwLwUB3ogX5NustPcT2V9kviTzXPTZLl/cRsi7GVMFdY3tCok8Vrm2CLsWJeKl5Bm48IMeg0yYQVqnTN8rIijnENdSAQTLaw5opAFDx5KlkGUduHgKV0STUnI13WLnGbApN8Fez23ExwS2ffQgoiBriK5WaJMJ3+sIh0E1w/zWK1K7VM0lp99yfo2WLUUQ/P04dkKeJkSaoQfSIMiK0ipKLG0cAQ8xbFXcGARlqSmbC+IC2XBXJ+JLV7/fY53SC+xrM+os6WivRuI6vlj4MgMx75STrIvbE2J47NAsDZUhQkNp40YFlz58AttDO1o/Sza24PHFWn2YL9jNt+3jq8+mckOWVy+jyzN/UD7bjypTvgWisGfNHmOAoPyZTkfQ/SXmoDwm7XBPHxsdbaC374lQQOtKMy6dOgQpMjKxNkGy/5AoynzaTFH8O38Y/IeJQ7LUMojrLYBoyWSN86jKQtMTW0E09X1BWC34mBYGAu/8MMY/QVIVSyZgH8TXqcTpMSs+aXyuPzM7xDBkSue582cOm6j0v6w2l42ujPj0pSVVlUFLa1zHqbLTrZmMAFom7JshQcxtDzhv4Ojy2Nl/oX35r/h5t9yFehbzBAGX65MkQetu1X6r180hS3t+gm/sr1R+W8i3Oad/pnslg3Xk8WPuuL1PLpDDo+cnQIoTu6XWX987asqY4vvHCuaM8YgHFggWTPLroYoStFvGkQlO25qDDuBHTPp6xDcO4DjyGl/C+euwHdD/jJU6ZRVpOAZ/VTdfQasUHzMdAbtSG4R5k= 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)(52116011)(376011)(1800799021)(366013)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hOx74GEzbKd5r2QNSOJBB4vtZdNd0pGO7EV+F3tJHhJ2qyl13gV4RnnpHJpOmJkEO9Ja69Itz/j8yk0Svuj6lvawigucT+2fWxozJpE8TYdiuMq0T1Eqgoo2dhGW1Liqm1PbzmE67x0ouu/4RlhvpSSmaqpC5t0soFvhsKMrB6+KgMGfIEG2PZ7651S1I9tQ3vg3Hb0CXv0SbbYVGI08Fc1w2OvMB1mY4klDIdo55BeAv5Kb1ko5yxFVEfuMigyRQAxpdfWiFCJSiV9LvVthJaBW7C8pHMZyFvHCp71YDFM1CS2s518nNrPp5giM9wJzAx3MK0N1UwdfrxVRjQuAOIvL1xBFf7mEks6ZGZNnvCbx8LrpsOLqKzBXMidmMG9ezpupmjvN8sU981Fh3oOKwnANbUR10TOic7ZqUKfigI8sWhfWk7NEum0oVOtzEpFGRbxGx49MJ2a2cdJhfkLEeEqYmaKvJyvcVLdfZXK4UwEuiYsOteIJpRk0/6jnkodIo4qP/THDfxu0NLfWL4mAtlmdsxJzuQ1TKtzLzty8qLP+obmxeyZS4FAVOHsBLIz1m1xF+ExkYJwfuTfP8WKuMwPYnUlSZHxQ1K5z5dPtUIDWRbCkwBo5BWbAfu5Avm3pFf67dQEGJSnCqPgDdxBXkvl1I0CXUB70200S4/ww0SSAaLyGBCtCuqPX9mhhGB8sL0Dog7zK9fpCxAQ+GuOnadyIdqrT2IptSepkjMPcsXVY+BRFDi0sYs18vshBgnuqRH2f2xcCzqaSMXYMgQoetVcf+Bwz/3oTvoBKr8YGfSMv5skxjFvBN2iXt8nN4SbOInGeHt0JeVrdOrnuyqf8RBfuFgSybYfwMHrBN4tCOwZJIDEo0xkm8yRTaG+zv5atFDWa99HchaSW8lgiLrAw+6/GhoOhlag8pCnZiqEDGaA3ApG0NL1G/+ZT2NmpLReXLqoRPOel7Ig9o2Q5UyqKY1V5cBP5cvNk1U2tQ1191H5Xu4JDHmfMGNPFbBpuRYB5AkcNNLXnzii0WjKjlnpDCZigrzYKjmpjVadmiPoE01deXlS9pyAh/Tz5pBro114KK0FynNL+Z0sMD+mV4a83qoF8CgfixDb2rURzUlhVcNgKwuR5kMc+PSaGaF4sAlJTlagQA5HLAVKBpE1v7a5HEC8MFpTe8qBROHxTkvnj3NWbC9qV/cNTGzFJouHW9H/eVMF3U9tz3Xl1MpF7Ni64MxMdaVjLqw2jMOQtX1IEU7J6Ihu5PGQTrUKBNjVH9B0zROa/ubemlXR5WeN6Orq69TF6EC4AjipJXTamuRF0tBvB6Wx4IoKbJHFetro4VGWKe+QcIILHQazKlhI7f/XE6Brq3z5KVwW5UNF/j9VyPWngFGDmEmQ1kFfho+DZE8/cstWrnu66zZcF5938mi3nflbqMT6i+As0BO69KqT4N8w2TsO91rCfLSc6LFcdgowT1RhLSVsw9MLe8IJaE4jd+NeKvQLssDtiZc8Uk8uNK/MdvK23YGFOvJyRmuiEEIrRleOTVfZpC2WrMVX8fueHcto5Drn9fpcojBf2wuV10K8NLOoZSINXoXe0Ys6bXpdW+fnZlqXsyg//EkMWu0/suA== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 85e7ccff-13c7-4fcb-465e-08dc8eba20f0 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 10:42:04.8461 (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: leuwoIaEoegNJZi6iD44A3BQdNCZ+BI6rEuiZLQrQDtwgiS+n+qROp2QjeB7iVrFKgxlrd6Nt6f5ObengUenN80w/EXKJ2ybXGG2oTWaIfQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB3099 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) {