From patchwork Fri May 10 11:22:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 796318 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11020002.outbound.protection.outlook.com [52.101.154.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E37016F829; Fri, 10 May 2024 11:23:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340202; cv=fail; b=rPgOQZ5Qj2qO1LYKlG69N/qk6FzIX56PoyA+NiLs6VpNPF2M/9GofGQ8OHK8el1JgsQ2oK1v+7Ljm8cD4y2/uRV6WGqX96RKwdvpJIDFrsDzi6PzbAiYlELxLNjRcGy1ikKWUcxQ0oYwWF7jp3AGA5JdQ3u8pCZH5dlnqF3vWNc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340202; c=relaxed/simple; bh=UdDbnQ+4fqdcittKVESmOw+oCu2MKZmKC4WoVjV6smg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=OQXM3uOtt7bTFd5PqbyjHjOk8qfx+W5hgP8GU5ICnuVPpk9IZ3e0xkiTLIlSPxCTlC/97WeWtto9VnLABullT3Q0HWiI6MuuChGigK6uwd0RAaJZZyXGZwTpgAvPTImKFrkg7XYOVTDzAnSjy0nN1JIte8wINqDjHjKGcDMnI1c= 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=F5VtrorA; arc=fail smtp.client-ip=52.101.154.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="F5VtrorA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kn5Zb6QHID8D/ImoTYbzbQXVpfuQ+mpoPwGfBAx3OnEoAqpUM2yHQXKRQO5q7yXFLNZY5jiwDdxKKY0YIeFGkIrL0i8SxYH0DJCHL8a6WbvPux7d0jO55eGqYjQMXxtAKlTrm1fCnRBDJ2sgVDAEgaHVvQzKZSuEt61QyVBeqYnOqvbvCa176sL02upZYwQ0wEUH71AU0a8zoeSDLNNX8tL7N/zNN5vhCc/BBdH7rOIWRNBQUiwbzVuF45R3Pv9I1o4d4JBssQyAySUVbQTrKxI0MPsothcv6N6iA0o7tzf3fByh/JYx/c7E3LtxveCpQu2WIMJKR69dGTTZyQuN3w== 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=t7u64hUVPthveZ+N2cB+0mYi+WsgE2TPOg4MbPzmR2o=; b=D3FSquSYnn9/cb6I4Z6yCEs8THtJwcyyF62DgNJRm1zJZa99rpCQP4Mwuj5tv/1H6/CoQ5DC1qYfiGCDPLoknCAu4eIkjpeWolSqCRQo/+P72NKoidQJ4ot3tAN8O24vhsRaLdW07tXSng+FpAWSgXKu/GzbHuiSgCC/Bk/TrdswGPqCljCa8HL3eZg1sM8M4hj+vhpoH6ZPlNlYypcVo1J4mat908T5pnbUkYYeLPo46X9Nuz1GHp7P1QAysa9f/9wiHSDtjm4O6IV0Jf3P1/frmSNieGHPHiBaI1GSw//iD8s/LFQ2K6zcjnQz2r1gsTR8Wq2Nu2/rDOyg76sAKw== 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=t7u64hUVPthveZ+N2cB+0mYi+WsgE2TPOg4MbPzmR2o=; b=F5VtrorAuvjZXLO1j2FNd8533YgNpY1hCaJTPlj/pPn9CvfGOAGpTTriW0CVE4GNA7+incw7pPLgTtQH3v1dM4ibKbZ+cXECaTkBx7ekRGDIZUlCG+aVaay7ktOHkJJ68ul3pDp+/+3gd7Z3z3N0nInQXBv00S4o+4gtvrSDhnM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=chipsnmedia.com; Received: from PS2P216MB1297.KORP216.PROD.OUTLOOK.COM (2603:1096:301:73::13) by SL2P216MB2862.KORP216.PROD.OUTLOOK.COM (2603:1096:101:286::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.51; Fri, 10 May 2024 11:23:02 +0000 Received: from PS2P216MB1297.KORP216.PROD.OUTLOOK.COM ([fe80::ce88:bd2e:8caf:8004]) by PS2P216MB1297.KORP216.PROD.OUTLOOK.COM ([fe80::ce88:bd2e:8caf:8004%6]) with mapi id 15.20.7544.048; Fri, 10 May 2024 11:23:02 +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: [RESEND PATCH v4 1/4] media: chips-media: wave5: Support SPS/PPS generation for each IDR Date: Fri, 10 May 2024 20:22:49 +0900 Message-Id: <20240510112252.800-2-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240510112252.800-1-jackson.lee@chipsnmedia.com> References: <20240510112252.800-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0168.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1b::7) To PS2P216MB1297.KORP216.PROD.OUTLOOK.COM (2603:1096:301:73::13) 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: PS2P216MB1297:EE_|SL2P216MB2862:EE_ X-MS-Office365-Filtering-Correlation-Id: 95e52167-b554-40ef-24b2-08dc70e38e01 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|366007|376005|1800799015|52116005|38350700005; X-Microsoft-Antispam-Message-Info: gEvX+yCvJxwvedC//zL4ZA/yXYNcWL+/ukXThYpI1wlzU6y3XBp8HMMY+YlIUN1Gi/iN0I0zR0+L9yJNfzMESykc+owwJOdlMNTgbRdOmDwf66i/Uyr1rWaqDB+zs9AuSzPiSpm1E3Ikwmj1RxuZh1iFOggtAp0ZApc25WwtdAlW0uSvqJKlRDCfzuFp7u6XJrMeMKsAqI5NxwVOK2Fz723jLBm3aez9TsIYYOqwl+GDetnqSKCEGf+qpacuEnV5oP2SwOms9Wy6Kjl4o8cg0EEKChAubIUcZeRURqAIRkr+xtlf/KmgW+NXSYOWUfZARCeEly7sdcLlMx9IqOA3s0CURPXJ6IS8mlGPTQD6Zy+qcKnB8x52yk15dChYqdf2uzl+4m1epnAXnOMKimdW1IbyadTPeLou4qCoN+sQCf4WRRNmXsyvvT3verHa5T9S8rTz7moIRnBIpD7G5pelM9tvIWtdth+p8bYLKNvaq0kYJzSge4U6LRg/ps5JwqcPzbBS5FNkd8JAXiNjzmrFGlB26D/gk7z0H6L1KcLXHYoXkpBq3ThWH1cZvXDX6KkP97ZLwAjtjYf+udakZsbvhQ7WQX+CeEGT61kNg3LmpTBuyYGnjD/VwlyGfiMveRhjhX79AkF+bxNnjnjGyGHC2sSnjKILZJxp7SFchhgSLLdXwFjItH44cB8h/TBWSgJXag4O618qdFiBbIMSFOeBu7jzrnQttDutFCS9TDbIZHvAerUTwlGXIQvciToUcoBvzVUen8kaQUpvYHdCVevNSzLzgaXd8sqLBUmjLE0Oj4PRcEbZ8VBhqYcJzKO2RMVXsc29CKzTjHyvL0mpnzTmWr2fzm/BMpNBa7syUfjPKE8AAMwvrLUbFa90wrhfOEIfbE1odMNWvTdcCqTAkLw75MvpGZAWT1i6MzRFhpUiNdBs4feSANVABgPMov9WSKjBSqP7VhakH+L95NQR/4T6YvwZJ2uQF0Iockx86kAL41o57F0OGK3QPxSIfzB8eyAc54PMaFptBZPiNqXQ4F4YuBFoGV9O94UdJ6RXGlZbxRB1wQZTz7ihkqOzjLn2qS3XrT/3pVcmp+TrlXWvhpkMkQiCV6XrCRJ32pawlEoVxJQPNDcekFlTnJXsvUMO5BtvHgZdbkYKEhbM0VmnapZlw/7rakx/QFZeLOzfLcEfJKincu9Oqi+ZLG97Et4AYksBQlAmj9+Fzi9KUC5xmwTU92v2PasM15CFnDa9nS+5i5CjiK56mBa1R5ASZ+/IOjksJZrnEiyhAgIQFrttfQF8GYMmdji26VujuoFSFUNVidkewp+0slqt9nmRXEAZ7qB777d3p2l+UFRof2RIKay0Lw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PS2P216MB1297.KORP216.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230031)(366007)(376005)(1800799015)(52116005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CatXNpV2ael11J627nMqRqTO98CwUGyQAV4C1lIXBxhNe4VTMF+uPsrvV7PcwSYTQz8IqpFx0zA59XVo0wazSuKbaewlNjKjik/X01q3K8pnc/9arNHufzPqNDSUypjo8MYnZEUYwGEGTcwnnA5USpL3M3Ry8yr+z83fWu7+4VockCL5Q5Nq2MzX+mf96ucMN5HfI+5Q7kU654lni1u21MKPtUfTYwV+k/94aa/qcB8j+uxuDO3Ha4JbvsTdFxULNAvVEOVoupBr8VnYKn8iapazU4Ts9X3145CYMp7P/SYxnXP6O2CqMOcLF7+ocFE932NkiQWytNiIYcuuyS/mVqtVToMhW2FolWVavt99o3LxTNRcck5XSRJyO2UYxlNz62I6lOku9SM5YImWNEoDOvcp87QKbNu4onB4OF82yhqNRESPLCmeaDNHcMIAL1j6ZVq+T2IlYX/JrphTe83uMJOzTYN66yJFNcOBzqlb3jgGZ2GTEaVQtG5VNAKkpI5gq0jCuOSkbLrFCode0xsjsj6psiTzwiuMaUUW9edNRQaKlkLh5oNHdHEt8oKxsJDSuAl2AedOGqvmlQnw6NfqBxroI3+JCM9ehhnpNYhY1DDyT80+mq3Aaa6FDawyMgQgFnv3tkBDEpLhj3H3VDsE3uWyk5UiBmRt9S7uRIRMKXHVpQCoROGQjmWp6uU/nADDMN6EaIdwKKAQmt6OBymXOFptvo7Zc46HJinOilsdkCBRYq5cEAoXFEy2qUU6SqARS29yv01GAzOXQDbzkXvgTvGOlD7gFxdPV7SB9UIAZCXcBdAHKj31L8qKhzg7Jp3wL2c8Ft7MaFsG9eDFaSlGRBMIgL+Pr34z90dfK6Ab125c5WqYw0b/cbK5Rb9+1ko1LKvD7vi+W1dDSCiri/dHyvde+s6Vx3kSljn5nPNRNQ4ABT9TouNeZIa9SCzsiuLtR6S9AJ4nilBowKex/nhc3zOgQh11eWLYh/hhlFRlzzAJVhK7IDvP2kIw8JY6igZjDm0mD6M+5+ZH0IQH2CuzEW6bhyE59yJkU/4kn+8MESwRfrlCV8l/1efdT0kU/ZB9W04+LQybcrSwU0O7jVNF1zBDPoi60xX/7333Q3cXYqeRbB3zXYgxJuKMsiaeN8HL4aNcztVe939upebbRhuCoKOh9p1uz4Sx0heQTXDNao8lmmru/5UKsFtGEL3WzRcVWgfeOJCStOKEOSZu/+eAXQhIwDDvWGWYBS7lQ25T6WRFp30DkNdHBEFUg6LSUd4ryu2xWwybK3i36Z+K8XHfoIWy7ngMh1sPji+LtcRX849ofae1XR/d4SXGQlkgXk2PjdCfvzUmrBcgzsNbQJ+lH8WUWLsIZH3z2lg88qPfGfIVByartpxQRRXIqeNA9Gxr6wANHzEU0nd09DV9bM65t33nk86/elgyC4e6wba0gtOC2Yo31gVGRK5RwKHUSlqPFATDPFnBsKFK9Lt0N3xg6DHYwLKMYxr1QEZfKA9nHTAC4HwfnDx2laRTNkQqY8xOosd5UPu6mCFo+c3Qed2dbKtI6bynkKdltAZ4mNlyGStjMoX4rUENBy62/NmpcPYXC5K3FcWFW8yyTEdc8h0Z9A== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95e52167-b554-40ef-24b2-08dc70e38e01 X-MS-Exchange-CrossTenant-AuthSource: PS2P216MB1297.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 11:23:02.2916 (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: IPuz5cIi3TSv9AemPOwO4DctBxoD2eG7NBAku/ONfoa3zKNwwoBkDXyg1StDe1jI9nTZMs6M6pzxRWQjlBJfP7pqUnFzwGKl8kQKcaVU1t4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB2862 From: "Jackson.lee" Provide a control to toggle (0 = off / 1 = on), whether the SPS and PPS are generated for every IDR. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung Reviewed-by: Nicolas Dufresne --- .../platform/chips-media/wave5/wave5-hw.c | 19 +++++++++++++++---- .../chips-media/wave5/wave5-vpu-enc.c | 7 +++++++ .../platform/chips-media/wave5/wave5-vpuapi.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-hw.c b/drivers/media/platform/chips-media/wave5/wave5-hw.c index 2d82791f575e..fff6e66b66e4 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-hw.c +++ b/drivers/media/platform/chips-media/wave5/wave5-hw.c @@ -23,6 +23,15 @@ #define FEATURE_AVC_ENCODER BIT(1) #define FEATURE_HEVC_ENCODER BIT(0) +#define ENC_AVC_INTRA_IDR_PARAM_MASK 0x7ff +#define ENC_AVC_INTRA_PERIOD_SHIFT 6 +#define ENC_AVC_IDR_PERIOD_SHIFT 17 +#define ENC_AVC_FORCED_IDR_HEADER_SHIFT 28 + +#define ENC_HEVC_INTRA_QP_SHIFT 3 +#define ENC_HEVC_FORCED_IDR_HEADER_SHIFT 9 +#define ENC_HEVC_INTRA_PERIOD_SHIFT 16 + /* Decoder support fields */ #define FEATURE_AVC_DECODER BIT(3) #define FEATURE_HEVC_DECODER BIT(2) @@ -1601,12 +1610,14 @@ int wave5_vpu_enc_init_seq(struct vpu_instance *inst) if (inst->std == W_AVC_ENC) vpu_write_reg(inst->dev, W5_CMD_ENC_SEQ_INTRA_PARAM, p_param->intra_qp | - ((p_param->intra_period & 0x7ff) << 6) | - ((p_param->avc_idr_period & 0x7ff) << 17)); + ((p_param->intra_period & ENC_AVC_INTRA_IDR_PARAM_MASK) << ENC_AVC_INTRA_PERIOD_SHIFT) | + ((p_param->avc_idr_period & ENC_AVC_INTRA_IDR_PARAM_MASK) << ENC_AVC_IDR_PERIOD_SHIFT) | + (p_param->forced_idr_header_enable << ENC_AVC_FORCED_IDR_HEADER_SHIFT)); else if (inst->std == W_HEVC_ENC) vpu_write_reg(inst->dev, W5_CMD_ENC_SEQ_INTRA_PARAM, - p_param->decoding_refresh_type | (p_param->intra_qp << 3) | - (p_param->intra_period << 16)); + p_param->decoding_refresh_type | (p_param->intra_qp << ENC_HEVC_INTRA_QP_SHIFT) | + (p_param->forced_idr_header_enable << ENC_HEVC_FORCED_IDR_HEADER_SHIFT) | + (p_param->intra_period << ENC_HEVC_INTRA_PERIOD_SHIFT)); reg_val = (p_param->rdo_skip << 2) | (p_param->lambda_scaling_enable << 3) | diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index a45a2f699000..a23908011a39 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -1061,6 +1061,9 @@ static int wave5_vpu_enc_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: inst->enc_param.entropy_coding_mode = ctrl->val; break; + case V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR: + inst->enc_param.forced_idr_header_enable = ctrl->val; + break; case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: break; default: @@ -1219,6 +1222,7 @@ static void wave5_set_enc_openparam(struct enc_open_param *open_param, else open_param->wave_param.intra_refresh_arg = num_ctu_row; } + open_param->wave_param.forced_idr_header_enable = input.forced_idr_header_enable; } static int initialize_sequence(struct vpu_instance *inst) @@ -1701,6 +1705,9 @@ static int wave5_vpu_open_enc(struct file *filp) 0, 1, 1, 0); v4l2_ctrl_new_std(v4l2_ctrl_hdl, &wave5_vpu_enc_ctrl_ops, V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, 1, 32, 1, 1); + v4l2_ctrl_new_std(v4l2_ctrl_hdl, &wave5_vpu_enc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR, + 0, 1, 1, 0); if (v4l2_ctrl_hdl->error) { ret = -ENODEV; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h index edc50450ddb8..554c40b2e002 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.h @@ -566,6 +566,7 @@ struct enc_wave_param { u32 lambda_scaling_enable: 1; /* enable lambda scaling using custom GOP */ u32 transform8x8_enable: 1; /* enable 8x8 intra prediction and 8x8 transform */ u32 mb_level_rc_enable: 1; /* enable MB-level rate control */ + u32 forced_idr_header_enable: 1; /* enable header encoding before IDR frame */ }; struct enc_open_param { From patchwork Fri May 10 11:22:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 796172 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11020002.outbound.protection.outlook.com [52.101.154.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C32D16FF5B; Fri, 10 May 2024 11:23:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340204; cv=fail; b=r0Lu0wL4RYehB76ZRksKMTnuI/AA5mVvuSxWY5pMVlEYp8y4/+4stBHfsTSrhVNR3K0eKw+V8DfRpQuRmWN18aRTgbcFxi1SuTFeCr2WdOWAZ6qGWCKKFKW7g3QFpzSN4uylXp0o7A/jOzbKtKFEOY5Bl2ZvnjlhCvI3Vt9UQ6o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340204; c=relaxed/simple; bh=sPD6+YGlDMWDRGEEUeou4zIHNyQcJ1mIkNhi6TA2tTM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=agoLmo5SSt1EWlnIAaSfLHfHj483+L7Whm/NL0IadsPqhv/YomLI6tf8eNIl+r7vYUfvdS+GUNsddLbJaptUSHu/PA8Zzaxrr9N4b3yUn+u1wbIHAQ4cNM6SyGau1Nis+BgrHocxEG/t8t3voFwdqmi/ZLBmDnv4lCzxTRDL27U= 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=KF9e0wMv; arc=fail smtp.client-ip=52.101.154.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="KF9e0wMv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kKWL16iLPxSXu2NPce0xUxSpiqfHROe2m/AuWeU1GmLX2LQDgaeS55v1nuhIZJXYjB8JgLc9qSBX57so1qYWPEnDdEHZiLfBoS+I4jHUr2j5PXsIiTnlPcFZAfR546eVzBZtAIR6uORmhXqHY5Bv4n1bpBpfOdKhtTcwKMH627qteT5poMuRptJlC2Cxi1X4XeMc7apFxh5zpVXSSOvZ6ravYrpqPPwHmIPi8UnJYAbR/BYgH18OqpX67t2Hu53H2nwJhZj3I7nJ0qHRS2ucW5tdcZX1AnNQNKWgrUAqq7hcSWmDD1s2a7KCUnmGHicZHq6sEWWo0tkwdBkUL7KTpg== 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=rIuLWFkQPpa3wN+Kc/MaH+1CyTD/wOpW2RSQCbprehw=; b=S111mev4M7frKRufQEjM/7NI+DMjnbL8pv5PsYND6BoZzPZSfbd5ubARkj2irQo+8qgGGB/++IzcYfLU6QCifgSovHh5CVxscoGJN36Wr+l+WkRaqn9G0q40WSvxEONidG9Ihobi6NvZ+gPxJZoA4jzLMSgs5hwW5X7883buZYQWGEao+D6fCnE5GXheDpoM445b4qhbCPuhH4QgSFtaeDb90RqV84cMgGLgpEQ1BF5jIo1sNddbv1P+LkI6Qgvp0+Eg130SG3DeuxvqGqlyANWU/qYSIAYmlenOk/ONAXPuiR+KM5lTz+ttZQf2rFpsuW5nVFlKT0XlWjIJotH5Jw== 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=rIuLWFkQPpa3wN+Kc/MaH+1CyTD/wOpW2RSQCbprehw=; b=KF9e0wMvO9An2m9zYOzPZBgCn2QWkalTNvm0JYZ76JD+tRz48QVgzMqseYaFDBm7W1E96yTtBweVQnm4tmuAhq6m5ZPVFkRaDFLCDjoAlJ1G5WgqPdapH9PzxHiAobYZazYZ5GWEsafq4W2gxICzzvI1tNSxn+oBPIKl1K+T+WI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=chipsnmedia.com; Received: from PS2P216MB1297.KORP216.PROD.OUTLOOK.COM (2603:1096:301:73::13) by SL2P216MB2862.KORP216.PROD.OUTLOOK.COM (2603:1096:101:286::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.51; Fri, 10 May 2024 11:23:02 +0000 Received: from PS2P216MB1297.KORP216.PROD.OUTLOOK.COM ([fe80::ce88:bd2e:8caf:8004]) by PS2P216MB1297.KORP216.PROD.OUTLOOK.COM ([fe80::ce88:bd2e:8caf:8004%6]) with mapi id 15.20.7544.048; Fri, 10 May 2024 11:23:02 +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: [RESEND PATCH v4 2/4] media: chips-media: wave5: Support runtime suspend/resume Date: Fri, 10 May 2024 20:22:50 +0900 Message-Id: <20240510112252.800-3-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240510112252.800-1-jackson.lee@chipsnmedia.com> References: <20240510112252.800-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0168.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1b::7) To PS2P216MB1297.KORP216.PROD.OUTLOOK.COM (2603:1096:301:73::13) 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: PS2P216MB1297:EE_|SL2P216MB2862:EE_ X-MS-Office365-Filtering-Correlation-Id: 96c4cad8-9e19-4006-bd45-08dc70e38e38 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|366007|376005|1800799015|52116005|38350700005; X-Microsoft-Antispam-Message-Info: E5hLe4/NOZvHR5eaZsVht4rIj43cnMcGL1aYbbCH2tRqkwZCK+lTJkFD39XcvNcyV/LuDt1LBYkiG88h/JQTbM9AMAuTcDbyGBS0ttLAxzT8eUoASlovOKPIEvJ6x4m2u07UR3Z5tcu+utP+yDLg6xknUG6khQjGMZTmGLrJ4L5/kKrKWpXSkgEczhDgaYb5tXpzIFAv44qKhQ6fZO50qfk06YdY6aOCMjnWXQtA+24hRNan17a5XYE9uI62B8PeUcFUuxpqpXpJUcoUNTTFRbPfeYvVA0ah7QLD/25pcGDLDi5yedv/3mWWnV/IFflrFYUQju61n+Ia6eWGPGo1RTsRT4e9w9f+26o5Q2qeYChmXXxqh1ZSLVvfYx41rKw09MBEKXtV9j2Bhs2R7huYKhOWFLa7M4IroETAdAwefDstTiS9e/6Ep7dqbBvMzWJmigNmsnIoFVjg1Pzt7x41a8h5HmSmLVsBf7/0uk5hZ3O3D6nRp6a6SFp2FariciaMiOtS1YQopCJIObkqmy1Zl9frcTpE607gZ11Pagk4B+V5PhefTc+tFDon+HHyX/H1gNFPBf3OnQTEn0GKRvC8MXWc9BPSBDB1LFoWV05Ec64SXqxu22qODdynK69TZ+3o2PVBc6J2urnlMEAz5z4LyrDe4heBd3THtb2d+P2yz+BBl+G3gjoy6QjMIlvv6+styG2W7xxF+aqlzCfL/jHNkprPxoxzmyzxcwUNzZ9fxhrDX6GDpB7mOhsACo5FCzMb2gJ1O3XVGxVXjRHMoLB1E+eQIsKy0v59xKrybh0TzQiqswJsTMaZrlmZ9nVdK7uUws6jg2l32TVoBTjqGU1FusGZFZLy2Zt/Ypoo17D4XjbB06FuMutbY5/JvDJPrIMfdB1AuAtyYYKHImxovaXfLzG/qbLFU7rv903fgx2CQKDcc3yfLvyWWlUUGioikOoplSUvZItG2IUKxILfzUE2vZJ0x9/lYwUR/GWF5+C3Dd+mb6tEpsFWADFIE3kjb/UD3rGPiLgQ094aimSgRu59kenMBe/Ph7bnS72gQ3dupR6OKGhYq1pDX4WTUszu3jVe9L2McYOq9wVis6R6HCmeBYV2xd380Ktp8mT7lBXoS4KWwm1BFFKhvzoEWN96xaEUDbenqfHClZPj3IUPVAGbsaHe8hzhzoT1qkoEKw99OOHPTO5fOXj9DyblTT1qV4oVK446bPRITHnfjANSh2eRZ8m+utVHElceIUdDkU33W8Tyh5CmxIN/85exAihkadAC4zsE9LDDmZurhK3lRbMDq3Kfn7wpPhmOH09rqfM5zrVqW2oLN/8iPTzdvyrlGLnX X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PS2P216MB1297.KORP216.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230031)(366007)(376005)(1800799015)(52116005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1Jbk9s0IlnIrNEGMHT6IiG844wq7UvM6SZ5sW1RY7jKb6SVhj2awp0uZv4n/UEgWaETMUwv4/lIE/j/cuQzmANlwX4v6d2EeFy+8aBmuYWPagYwUpq9LtwEHZfCKebojFG4VpRK+d26eUAkK0uSxqohe6hTzvBKy41CpR2ANuHWO1D7cp+zTn8664gKtRl87YLS4NsdRNZlHJ3nV7/wXSVZPjL8fmx4hVDmp3WVUN/mSdGbfo26Xqy2XkmAX1LoG65hCsMN8VHKG166CYhlpoHkjWOio+IyV5z4g05omcj4QZSjBIrMGNONKzXbnda/dVVuet1nS53xxjSARmnC4QDXXGACJeMeY6a8F3UvFREqdRxgIFWLGIyuJ59Bu3YXE8aEL3kI1K7X9mb6O28oTEeE/jY7YrSXfQf4FkVWOPzbVBfG2zoAGWsF7GpFNjvfyfMOdjBrZ05NwLNnbiN02WRO8lcT3AEGUR+rfFsm6QEY1+Pzc7IqHYDUeLqyuoH+noY0FIc7LRrp0ES+R8xIMq/+jwc6zbhKOjgoUd8skdI5BFxcKq7IlxeS7HXM/aZcqtCbRsH9MCr0rMjy6us8FIEGnEkSRA/Br2HwyuUL9NRV9rmEOWtr693NGci1FQnDWeI1i9X+z8fS5uZ3zSLMXdEnDaKxiqHqjKGxL1Ra2Ua+TaLVKL9nTKh4YTN3BdgE2gSf7lhhx+Kr8sARW/Lpa7Nmp4qYPWuMn/gO1KXRF/WJ5b3vokl3pWXcu3xcd+IrzujLsuqZaCrEHaGHDUE73FuLQUC6gGquCnL+JYAUGj5S8S8o2e5h4nkqXrJK6xQ9Eqf3mxVPbuTBcblv1toYgkOze9zM49jHNsV1Z95v+c9G13Ye/vlnqd2skBXXNSrjiN5Cfr8qTcc0kflebMNqnN5NyNy0W8KjZUKrsESN0LkQmZyffUum+9k/lrLwIcEyYvNAoh/WgRe4fqYGBSf9BkCW/y1n6LbDcQbBRhjkHQmranp9A14qzoLvlIR4k0y/Cv+w0MA/ww/dLqrCoYBhiQq6N10ErF2C8Iz8LXzzVfsiUn8weF0aWkYfdSpossinw+6BSMjqiXrFwQGNgS5OK91pQgd38X1kEWcjtdDwHf0jkx9R4AW39ci4V1OhUzoCe3+pbdDjHVT1Ds/8kt2VOSEipm4RKc+2n0RataZbRWVrF1uzaHYISoSrxJGVuK1P+cdPregRBOr0MUVib4snAjsUauWw35f9HjKWzrF8/cdzcBYtX8rY5gkEgx1pkq8F4q/2zjR1BthlVzByJV6VXg99VE3NPZvmJdBms5Y4JEXYUliQ1o4PK+4UGhObdmGrbgw19I6fHEGPFRWpkN39BHI34vTRj0WC9GpnnYFaS2Q+mYtdtwWisTriL9MY0ZdkMi3IkzPRIcb3bxaU/tVkAtm7ecA+YDoAdp/yG/cH5ZDEAgCD3JdB/GL7tCq892IUImkDUAzGz97rfwHk4oVspHQsgitkFfjybWdn34tKukS2Le0Wh7IgBTPPv3mjI9BgNgofizSgBA843bMyNi6inFVgGnGSk/Y0fFCCoHBAVlkR+YOfjFi6hD5R+PetDyNeF3pF3xMiXurb39+fIEdJByg== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96c4cad8-9e19-4006-bd45-08dc70e38e38 X-MS-Exchange-CrossTenant-AuthSource: PS2P216MB1297.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 11:23:02.6570 (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: oIessfaONly4lAA2tZB68nCRB+zZCA0HrUI+isdOw4XK+PwOVKid4y6jFPKsLEu4o6gogNaGrb9kxQ8o+TlpAfewKy2AGLK9g8U50NS2AaA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB2862 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 fff6e66b66e4..791b1f0e3199 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-hw.c +++ b/drivers/media/platform/chips-media/wave5/wave5-hw.c @@ -1084,8 +1084,8 @@ int wave5_vpu_re_init(struct device *dev, u8 *fw, size_t size) return setup_wave5_properties(dev); } -static int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uint16_t *code, - size_t size) +int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uint16_t *code, + size_t size) { u32 reg_val; struct vpu_buf *common_vb; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c index c8624c681fa6..861a0664047c 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c @@ -5,6 +5,7 @@ * Copyright (C) 2021-2023 CHIPS&MEDIA INC */ +#include #include "wave5-helper.h" #define VPU_DEC_DEV_NAME "C&M Wave5 VPU decoder" @@ -518,6 +519,8 @@ static void wave5_vpu_dec_finish_decode(struct vpu_instance *inst) if (q_status.report_queue_count == 0 && (q_status.instance_queue_count == 0 || dec_info.sequence_changed)) { dev_dbg(inst->dev->dev, "%s: finishing job.\n", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); } } @@ -1382,6 +1385,7 @@ static int wave5_vpu_dec_start_streaming(struct vb2_queue *q, unsigned int count int ret = 0; dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type); + pm_runtime_resume_and_get(inst->dev->dev); v4l2_m2m_update_start_streaming_state(m2m_ctx, q); @@ -1425,13 +1429,15 @@ static int wave5_vpu_dec_start_streaming(struct vb2_queue *q, unsigned int count } } } - + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return ret; free_bitstream_vbuf: wave5_vdi_free_dma_memory(inst->dev, &inst->bitstream_vbuf); return_buffers: wave5_return_bufs(q, VB2_BUF_STATE_QUEUED); + pm_runtime_put_autosuspend(inst->dev->dev); return ret; } @@ -1517,6 +1523,7 @@ static void wave5_vpu_dec_stop_streaming(struct vb2_queue *q) bool check_cmd = TRUE; dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type); + pm_runtime_resume_and_get(inst->dev->dev); while (check_cmd) { struct queue_status_info q_status; @@ -1540,6 +1547,9 @@ static void wave5_vpu_dec_stop_streaming(struct vb2_queue *q) streamoff_output(q); else streamoff_capture(q); + + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); } static const struct vb2_ops wave5_vpu_dec_vb2_ops = { @@ -1626,7 +1636,7 @@ static void wave5_vpu_dec_device_run(void *priv) int ret = 0; dev_dbg(inst->dev->dev, "%s: Fill the ring buffer with new bitstream data", __func__); - + pm_runtime_resume_and_get(inst->dev->dev); ret = fill_ringbuffer(inst); if (ret) { dev_warn(inst->dev->dev, "Filling ring buffer failed\n"); @@ -1709,6 +1719,8 @@ static void wave5_vpu_dec_device_run(void *priv) finish_job_and_return: dev_dbg(inst->dev->dev, "%s: leave and finish job", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); } diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index a23908011a39..703fd8d1c7da 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -5,6 +5,7 @@ * Copyright (C) 2021-2023 CHIPS&MEDIA INC */ +#include #include "wave5-helper.h" #define VPU_ENC_DEV_NAME "C&M Wave5 VPU encoder" @@ -1310,6 +1311,7 @@ static int wave5_vpu_enc_start_streaming(struct vb2_queue *q, unsigned int count struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; int ret = 0; + pm_runtime_resume_and_get(inst->dev->dev); v4l2_m2m_update_start_streaming_state(m2m_ctx, q); if (inst->state == VPU_INST_STATE_NONE && q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { @@ -1364,9 +1366,13 @@ static int wave5_vpu_enc_start_streaming(struct vb2_queue *q, unsigned int count if (ret) goto return_buffers; + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return 0; return_buffers: wave5_return_bufs(q, VB2_BUF_STATE_QUEUED); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return ret; } @@ -1408,6 +1414,7 @@ static void wave5_vpu_enc_stop_streaming(struct vb2_queue *q) */ dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type); + pm_runtime_resume_and_get(inst->dev->dev); if (wave5_vpu_both_queues_are_streaming(inst)) switch_state(inst, VPU_INST_STATE_STOP); @@ -1432,6 +1439,9 @@ static void wave5_vpu_enc_stop_streaming(struct vb2_queue *q) streamoff_output(inst, q); else streamoff_capture(inst, q); + + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); } static const struct vb2_ops wave5_vpu_enc_vb2_ops = { @@ -1478,6 +1488,7 @@ static void wave5_vpu_enc_device_run(void *priv) u32 fail_res = 0; int ret = 0; + pm_runtime_resume_and_get(inst->dev->dev); switch (inst->state) { case VPU_INST_STATE_PIC_RUN: ret = start_encode(inst, &fail_res); @@ -1491,6 +1502,8 @@ static void wave5_vpu_enc_device_run(void *priv) break; } dev_dbg(inst->dev->dev, "%s: leave with active job", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); return; default: WARN(1, "Execution of a job in state %s is invalid.\n", @@ -1498,6 +1511,8 @@ static void wave5_vpu_enc_device_run(void *priv) break; } dev_dbg(inst->dev->dev, "%s: leave and finish job", __func__); + pm_runtime_mark_last_busy(inst->dev->dev); + pm_runtime_put_autosuspend(inst->dev->dev); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); } diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.c b/drivers/media/platform/chips-media/wave5/wave5-vpu.c index 68a519ac412d..325e311cdedc 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "wave5-vpu.h" #include "wave5-regdefine.h" #include "wave5-vpuconfig.h" @@ -145,6 +146,38 @@ static int wave5_vpu_load_firmware(struct device *dev, const char *fw_name, return 0; } +static int wave5_pm_suspend(struct device *dev) +{ + struct vpu_device *vpu = dev_get_drvdata(dev); + + if (pm_runtime_suspended(dev)) + return 0; + + wave5_vpu_sleep_wake(dev, true, NULL, 0); + clk_bulk_disable_unprepare(vpu->num_clks, vpu->clks); + + return 0; +} + +static int wave5_pm_resume(struct device *dev) +{ + struct vpu_device *vpu = dev_get_drvdata(dev); + int ret = 0; + + wave5_vpu_sleep_wake(dev, false, NULL, 0); + ret = clk_bulk_prepare_enable(vpu->num_clks, vpu->clks); + if (ret) { + dev_err(dev, "Enabling clocks, fail: %d\n", ret); + return ret; + } + + return ret; +} + +static const struct dev_pm_ops wave5_pm_ops = { + SET_RUNTIME_PM_OPS(wave5_pm_suspend, wave5_pm_resume, NULL) +}; + static int wave5_vpu_probe(struct platform_device *pdev) { int ret; @@ -268,6 +301,12 @@ static int wave5_vpu_probe(struct platform_device *pdev) (match_data->flags & WAVE5_IS_DEC) ? "'DECODE'" : ""); dev_info(&pdev->dev, "Product Code: 0x%x\n", dev->product_code); dev_info(&pdev->dev, "Firmware Revision: %u\n", fw_revision); + + pm_runtime_set_autosuspend_delay(&pdev->dev, 5000); + pm_runtime_use_autosuspend(&pdev->dev); + pm_runtime_enable(&pdev->dev); + wave5_vpu_sleep_wake(&pdev->dev, true, NULL, 0); + return 0; err_enc_unreg: @@ -295,6 +334,9 @@ static void wave5_vpu_remove(struct platform_device *pdev) hrtimer_cancel(&dev->hrtimer); } + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + mutex_destroy(&dev->dev_lock); mutex_destroy(&dev->hw_lock); clk_bulk_disable_unprepare(dev->num_clks, dev->clks); @@ -320,6 +362,7 @@ static struct platform_driver wave5_vpu_driver = { .driver = { .name = VPU_PLATFORM_DEVICE_NAME, .of_match_table = of_match_ptr(wave5_dt_ids), + .pm = &wave5_pm_ops, }, .probe = wave5_vpu_probe, .remove_new = wave5_vpu_remove, diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c index 1a3efb638dde..b0911fef232f 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c @@ -6,6 +6,8 @@ */ #include +#include +#include #include "wave5-vpuapi.h" #include "wave5-regdefine.h" #include "wave5.h" @@ -200,9 +202,13 @@ int wave5_vpu_dec_close(struct vpu_instance *inst, u32 *fail_res) if (!inst->codec_info) return -EINVAL; + pm_runtime_resume_and_get(inst->dev->dev); + ret = mutex_lock_interruptible(&vpu_dev->hw_lock); - if (ret) + if (ret) { + pm_runtime_put_sync(inst->dev->dev); return ret; + } do { ret = wave5_vpu_dec_finish_seq(inst, fail_res); @@ -234,7 +240,7 @@ int wave5_vpu_dec_close(struct vpu_instance *inst, u32 *fail_res) unlock_and_return: mutex_unlock(&vpu_dev->hw_lock); - + pm_runtime_put_sync(inst->dev->dev); return ret; } @@ -702,6 +708,8 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res) if (!inst->codec_info) return -EINVAL; + pm_runtime_resume_and_get(inst->dev->dev); + ret = mutex_lock_interruptible(&vpu_dev->hw_lock); if (ret) return ret; @@ -733,9 +741,9 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res) } wave5_vdi_free_dma_memory(vpu_dev, &p_enc_info->vb_task); - mutex_unlock(&vpu_dev->hw_lock); + pm_runtime_put_sync(inst->dev->dev); return 0; } diff --git a/drivers/media/platform/chips-media/wave5/wave5.h b/drivers/media/platform/chips-media/wave5/wave5.h index 063028eccd3b..6125eff938a8 100644 --- a/drivers/media/platform/chips-media/wave5/wave5.h +++ b/drivers/media/platform/chips-media/wave5/wave5.h @@ -56,6 +56,9 @@ int wave5_vpu_get_version(struct vpu_device *vpu_dev, u32 *revision); int wave5_vpu_init(struct device *dev, u8 *fw, size_t size); +int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uint16_t *code, + size_t size); + int wave5_vpu_reset(struct device *dev, enum sw_reset_mode reset_mode); int wave5_vpu_build_up_dec_param(struct vpu_instance *inst, struct dec_open_param *param); From patchwork Fri May 10 11:22:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jackson.lee" X-Patchwork-Id: 796171 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11020002.outbound.protection.outlook.com [52.101.154.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7183E17089A; Fri, 10 May 2024 11:23:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340209; cv=fail; b=c/DLHkCIv0CAfJZBZDSHV4Roqnz1aWd7z4tdpw0Y9rhqn00UM9ld4zLrmQZlaMkVQVLdXot3FuRMwSqSK8/l9RG6j3CVfAO5DsNydxJTcghSB6XVFTX/hCcFTsIZD5aBxeDPcD2+ptgL4ptYaOU1jGcECxI0XkZ3vISqM/VvFeM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340209; c=relaxed/simple; bh=iLlXNG2PIIx+T+C2n+6SEH1YJri7KU76SWyIbHTJfGY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=GLFRvOobqI8uzNgB6CJv9HzgC7B5+yWhEeYdxUh0ASKZJqiUtrZmWWtKaeOV751OS2wEO3D2F09RbNal/WacOQ2g2He7ArBD87X7h2jXeQMp8WhDivu07pVPPfI27yX/QICRsl2NC+p0cKYGuNmJBK3JrJBj1UPkJdFJiYhYGs8= 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=HOhhTDwZ; arc=fail smtp.client-ip=52.101.154.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="HOhhTDwZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l8s9gDXVBfg+RUjELQb2AHFQn5GWIPTB3vYI6f/7A1yCjOynBkbNDY3xeVaVQ1J9YMtJ5xNfW/Txlxz67ynNEkAQdtOGI10S698tluB00ov7c2Wra6KKCvc2H+Jj65HWp4QBUrV9IEp2DV5HDbXozM9WVsBwUZs94h/niv9dk5uE2GTu1S5ev/wybxGdeWIkfn461B/xNGQpsawB8udUBOCH/5sXGejWxZsijlzIu/MO7gGajrDE5Qmt4vB+4vdAR6JJW1IZbRhEmaV85hm3Xx7qGBriQJZbkRIE2+74PBsq6v43no0fKEosIahO4SbzRQrLhTJLVJ04LMU4+wt25Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wN3e1j6LQP7KFaGLTrEhzYsm/r+C6mDQ+1o2ezW5wGQ=; b=EhoTqlYmAzg8K2YBl2CmJRAYVgnsUUPkvt8teJYl3/qIucjOVTt+dvpB9epyMv8JLCwJCjBnyQGi28C5ybidIXmHVUYkXSIPh0xksE03cq2UeoOF9SY2j95oLDJwkncvb06N1ELqw1qIi8MfMXrtavZ8dAmX7ajN2z/b779CQpESZIAsHxoJY5fZRUzru1j1ScldGAKq49e2dRUrVJuWVPxplc3OD8YKPs0YzM2ckx4/3OB1J/E49u3/vfmXE7oSRYaaJwJJS4Gk+kuhInwAZsUFDOfEleJuR8H1IlZiWmxu/k/VFuDG006VTHWWU3DVRFbwAXPIE9qqOIvGGkqPAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=chipsnmedia.com; dmarc=pass action=none header.from=chipsnmedia.com; dkim=pass header.d=chipsnmedia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chipsnmedia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wN3e1j6LQP7KFaGLTrEhzYsm/r+C6mDQ+1o2ezW5wGQ=; b=HOhhTDwZjNVFzZ/8mkD4ZF1H/Qf+jFxY45HJgNneYJaHPLonHE6PEiIYLOGOkqfW2/JOb0tTugWguKnzcBbF5666JajOc6HqZmvxxHxfitM7WZ++pgXrzOLKsUZzgVDxff/tFF9fmvTHTxGWdXMfzoUXpOcvDX6rZqdVbMJcpYE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=chipsnmedia.com; Received: from PS2P216MB1297.KORP216.PROD.OUTLOOK.COM (2603:1096:301:73::13) by SL2P216MB2862.KORP216.PROD.OUTLOOK.COM (2603:1096:101:286::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.51; Fri, 10 May 2024 11:23:03 +0000 Received: from PS2P216MB1297.KORP216.PROD.OUTLOOK.COM ([fe80::ce88:bd2e:8caf:8004]) by PS2P216MB1297.KORP216.PROD.OUTLOOK.COM ([fe80::ce88:bd2e:8caf:8004%6]) with mapi id 15.20.7544.048; Fri, 10 May 2024 11:23:03 +0000 From: Jackson Lee To: mchehab@kernel.org, nicolas@ndufresne.ca, sebastian.fricke@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, hverkuil@xs4all.nl, nas.chung@chipsnmedia.com, lafley.kim@chipsnmedia.com, b-brnich@ti.com, jackson.lee@chipsnmedia.com Subject: [RESEND PATCH v4 3/4] media: chips-media: wave5: Use helpers to calculate bytesperline and sizeimage. Date: Fri, 10 May 2024 20:22:51 +0900 Message-Id: <20240510112252.800-4-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240510112252.800-1-jackson.lee@chipsnmedia.com> References: <20240510112252.800-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0168.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1b::7) To PS2P216MB1297.KORP216.PROD.OUTLOOK.COM (2603:1096:301:73::13) 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: PS2P216MB1297:EE_|SL2P216MB2862:EE_ X-MS-Office365-Filtering-Correlation-Id: 7292211d-e6f8-44f7-51ef-08dc70e38e68 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|366007|376005|1800799015|52116005|38350700005; X-Microsoft-Antispam-Message-Info: a/Zr4eY3+3m9F1l8bnQXuNzCtRcn5RTj+SoNk6rr88ozr/ZkY0UHNkMq0p9RssGDHbvdsGFEwtZ9LY1PHX2d98KrQLN1FsTt/QCf7uEbiJ5perVkJGk3R9MNukJc+qltJji6I0Y+DosxiMM9eO0aECqtT8n+j6+1mcLGgHWipAI8z38zoOb8Y1Bmc/afXzAf/rmUTcsyZ8T/aaW8STZk10FTboSgGlQ15GhvY77ABzOV8nD/CeXx/Otu38Kh8aIS8Il6aj09fsPowCsBMaFJWlTMXJ4AWquz74ulVfhyq4X9ktCBQ6KMu6/QcmMze7Hgiutjkj6vuHHqZ/YQqOjNFek9NUyrGh675VLV2ryBZvldYmvzuapTpI6JlpHY0dLkhfz4tpNrmzVvQpp3l0b4CrNquAxM1Uzm1oyZaiuHSibno9YftGPB2iRZgpZUbuH5KfxU12gEhw2ax5pgfDaBnGeL1TCCxDCk57LNbdUGdMeTa1hFou4bZQbA5k5mK5hiXRGPqjrcBISECLJicEsxED9BlYfwfWz5HFmEKGJBauJWr+de0bDBOFPj5w14MItjapzi+z216lLPIOmLsgkhfzc/CiwjhKkML1MtOQGMPfJCsK0IQsV/T7Vy/gikKUrQz8gjL+QiNYDqgiBvrn/2L7QpsqmH87W6+mZf8A3pewKlVh359jaduxcg29Ldi4KMilsAaCtVr+Y5X9mNCuX3gp4qBENHTb8fhwU9Js0ImNeBfoNa3hkhvgIqr3/gI1141WWW0O28Wlg4PAZMiWFsgEY5d1pnFAdb62IL8wSA33ACSXXlFiII8N+fpsxMl9lwURJ4R/A69X11DiC0xciif84BYfDFGFoXxNneOkRAk9ZT7U17afZ15IR5bSLwuNRhgloGN56greUmcNKvGGvF/G0PslKBAhBEHXrmP4dGHEdFHRM9wOjNOJu3bpqvQrHORUBxznNvmXsn2Tk+6sSa/SdSEtUZLJCAO/B8L6bN1nBxSF7ffGXQQTJtUKbA1XRb+z/vd7hCYmKV4o34bVxeUvcA3JmHjsefBQcX1OavFfziwt3tmdy97Z7pM02kkFisvQRAXqGQvxIz39xYLzkNayzpuT1Gv4vERtQKo7vGdO3eEfwEN82m/dakYVqkE12wY5cIMroqXudl7f0bh14PT2hpGLSx5aIZQ3jH/e5gueMueVqfWhG0bmTHNjeFpJsLFk67fLaES9Pc4Dp4z9BTSO+VICIg6/YuQV2yW24aqSj5ssy1gg1OubFxpwRJWHDJgsT7XZSwKjUg9TNUgbcLDfn0OR1DJ1Lcr8mmps8w9Bqwh/TG3Rnih+B7hZjNqSSkT+6rkfgNIl/5R6KZp8E7PQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PS2P216MB1297.KORP216.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230031)(366007)(376005)(1800799015)(52116005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pGVDv/sLGMF3NbarrekgzXBzxd3xJQP6/CnbrV1A2R+d5F0+6CMEunnSdL4RV9UMFHYM1K3d3kWbW6tph9JuVU1nAYl8d9QmHmZsN+m/YPFavqM5udPbuNvRKluXx4qHOwzVh8q6tagpEaKyI9A8dN2ZD2zHRMjiGT98NQqgcpvXyvMlt9mr5nbmJ8X7CTnKb2wDjdt2AVZZT9M/bQnNpOs70maB6dWLs5sXp4lrvJ5f0J4poggQsB8cAKEX3iIx8TddjwltYD+K/Jc9eCoHbGagAi4pPyfB/UzylxKNsROMzTMtaLNBtFFLO0jQY4pdLq2QifQ5VYncahLIDbXuNqD/igaphkv9qAontx7988n1vWUawjF/ewZwOvCy9nSvWLjsJWydxfN68cuzrb+D1qQW4aOysL/PHJWpJF2p3e0LvMGgj8o1drrPfs73gm0K2dtOyXUxiYMszK0nUlqkDCk3aPEg8uYKqsmpsiu3NotSNfRFUpUHBDX9SM9k/bh9dHSx6SXEO8QeDUPNTUlBh1R7rUqyU5RFgF93pjxYWJGa0d4R0B0TOpm/+CcDultKIoIHFsVUlQe2eb42SBM+gHrnJovDD2xnRF62c8REhXghGpU9Dfkqmsajc19yOtrkIP0I1adenB1VLPe82Di31GQzpSWX2f+HwjpSoUBoPvdUSbN5mC00IjkXrWe1fwRk8Xqye6Bp1PWBOJ/cncwsgjTrHfXBbvboce+2TkAJHN/3uUiv5uvG5AFxCXXqVzEe/mYIpLPI3MyHeWFGg74E5EGS5BmY8mmSkNTPv6DvKmY4k3JgpRKYhDeXQiAYRpFA3ptxxu/E3jhhpDYhU7GUXE5Rnm5iOM6r4HO1APXkiKc3bmifdr6y4TWOzte88NhKuPky43KGaKiC+C87Yte6kcjZHt5Ux9/4Dj5IYE7bCpf5mRBw2MW27pvgt6w8wrk9gmR0qGTdS1B0BDOex9Zg2RBtwl38tdl8Eo34SABH3fpHmIRbz+BRVwZSYuZcf2yjkm8UQBipavSwv1svWsfAigoVqoWzeCKtpni73/k7E+syrJqM3k+HctfOjFtarIHQUwMmxrzVtBQoz8H4Da/51zHaQy6XiWrb7ude/urJta/viYeRQyv5yKYIb0ypzsuTBgufP1nIo7j9YjKGjGbZXgh75pbBwar3zUd+ICCI+tQ3AvNstQsKUgBl6LR2MByQrvw8dwnwBI+6UNXn77IYzZw8DoWtkkfmBFzxug1pXSo5HKKKjNug2VOzrSuub6t5LXyP8pT9LZg2ESdACz24y71Xz/GIhDz5eyCbLUFX/EOHgRhruGlf5QjHI6Bv7+9OHiLsuFhosPbWdRrzmY2PLTcENzkob7mWxspsnY1V/8mrPQ9Rqt5y3zc2hiHzy57fy/Wjp2QvnNMiSZtWR0AKWLQa9FAEaBZrVCZoyi2pdxApzi7rfBQUU3ZrE4zSi7AhkzBapHUomkEfESW65uMA0zFPXeBZ7jEMcHXDyL8j2XOFDGoUzdRUSza2mAmt00/qW26r+ccEr6+Gy3nNs24DVVM5rCAPWqUW5XKI94AmdgKaVw+8EwzpLQrmP6xcs4ZxLzo9v7scT6ra2rfr30KBtQ== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7292211d-e6f8-44f7-51ef-08dc70e38e68 X-MS-Exchange-CrossTenant-AuthSource: PS2P216MB1297.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 11:23:02.9922 (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: wo2R5elQz3oq8h2GxoqhywLk7l3qn5ywzHdS9fo/U6mciAI+nw31y4wGmOOn25/uCdvVJFi2zD8T0LUrDqO6gFAZ8emYcL8f77VfM8Y4AAk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB2862 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 | 296 ++++++------------ .../chips-media/wave5/wave5-vpu-enc.c | 197 +++++------- .../platform/chips-media/wave5/wave5-vpu.h | 5 +- .../chips-media/wave5/wave5-vpuconfig.h | 27 +- 6 files changed, 236 insertions(+), 318 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-helper.c b/drivers/media/platform/chips-media/wave5/wave5-helper.c index 7e0f34bfa5be..b20ab69cd341 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-helper.c +++ b/drivers/media/platform/chips-media/wave5/wave5-helper.c @@ -7,6 +7,8 @@ #include "wave5-helper.h" +#define DEFAULT_BS_SIZE(width, height) ((width) * (height) / 8 * 3) + const char *state_to_str(enum vpu_instance_state state) { switch (state) { @@ -224,3 +226,25 @@ void wave5_return_bufs(struct vb2_queue *q, u32 state) v4l2_m2m_buf_done(vbuf, state); } } + +void wave5_update_pix_fmt(struct v4l2_pix_format_mplane *pix_mp, + int pix_fmt_type, + unsigned int width, + unsigned int height, + const struct v4l2_frmsize_stepwise *frmsize) +{ + v4l2_apply_frmsize_constraints(&width, &height, frmsize); + + if (pix_fmt_type == VPU_FMT_TYPE_CODEC) { + pix_mp->width = width; + pix_mp->height = height; + pix_mp->num_planes = 1; + pix_mp->plane_fmt[0].bytesperline = 0; + pix_mp->plane_fmt[0].sizeimage = max(DEFAULT_BS_SIZE(width, height), + pix_mp->plane_fmt[0].sizeimage); + } else { + v4l2_fill_pixfmt_mp(pix_mp, pix_mp->pixelformat, width, height); + } + pix_mp->flags = 0; + pix_mp->field = V4L2_FIELD_NONE; +} diff --git a/drivers/media/platform/chips-media/wave5/wave5-helper.h b/drivers/media/platform/chips-media/wave5/wave5-helper.h index 6cee1c14d3ce..9937fce553fc 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-helper.h +++ b/drivers/media/platform/chips-media/wave5/wave5-helper.h @@ -28,4 +28,9 @@ const struct vpu_format *wave5_find_vpu_fmt_by_idx(unsigned int idx, const struct vpu_format fmt_list[MAX_FMTS]); enum wave_std wave5_to_vpu_std(unsigned int v4l2_pix_fmt, enum vpu_instance_type type); void wave5_return_bufs(struct vb2_queue *q, u32 state); +void wave5_update_pix_fmt(struct v4l2_pix_format_mplane *pix_mp, + int pix_fmt_type, + unsigned int width, + unsigned int height, + const struct v4l2_frmsize_stepwise *frmsize); #endif diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c index 861a0664047c..733c770fb049 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c @@ -11,111 +11,92 @@ #define VPU_DEC_DEV_NAME "C&M Wave5 VPU decoder" #define VPU_DEC_DRV_NAME "wave5-dec" -#define DEFAULT_SRC_SIZE(width, height) ({ \ - (width) * (height) / 8 * 3; \ -}) +static const struct v4l2_frmsize_stepwise dec_hevc_frmsize = { + .min_width = W5_MIN_DEC_PIC_8_WIDTH, + .max_width = W5_MAX_DEC_PIC_WIDTH, + .step_width = W5_DEC_CODEC_STEP_WIDTH, + .min_height = W5_MIN_DEC_PIC_8_HEIGHT, + .max_height = W5_MAX_DEC_PIC_HEIGHT, + .step_height = W5_DEC_CODEC_STEP_HEIGHT, +}; + +static const struct v4l2_frmsize_stepwise dec_h264_frmsize = { + .min_width = W5_MIN_DEC_PIC_32_WIDTH, + .max_width = W5_MAX_DEC_PIC_WIDTH, + .step_width = W5_DEC_CODEC_STEP_WIDTH, + .min_height = W5_MIN_DEC_PIC_32_HEIGHT, + .max_height = W5_MAX_DEC_PIC_HEIGHT, + .step_height = W5_DEC_CODEC_STEP_HEIGHT, +}; + +static const struct v4l2_frmsize_stepwise dec_raw_frmsize = { + .min_width = W5_MIN_DEC_PIC_8_WIDTH, + .max_width = W5_MAX_DEC_PIC_WIDTH, + .step_width = W5_DEC_RAW_STEP_WIDTH, + .min_height = W5_MIN_DEC_PIC_8_HEIGHT, + .max_height = W5_MAX_DEC_PIC_HEIGHT, + .step_height = W5_DEC_RAW_STEP_HEIGHT, +}; static const struct vpu_format dec_fmt_list[FMT_TYPES][MAX_FMTS] = { [VPU_FMT_TYPE_CODEC] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_HEVC, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_hevc_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_H264, - .max_width = 8192, - .min_width = 32, - .max_height = 4320, - .min_height = 32, + .v4l2_frmsize = &dec_h264_frmsize, }, }, [VPU_FMT_TYPE_RAW] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422P, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV16, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV61, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV16M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV61M, - .max_width = 8192, - .min_width = 8, - .max_height = 4320, - .min_height = 8, + .v4l2_frmsize = &dec_raw_frmsize, }, } }; @@ -234,74 +215,6 @@ static void wave5_handle_src_buffer(struct vpu_instance *inst, dma_addr_t rd_ptr inst->remaining_consumed_bytes = consumed_bytes; } -static void wave5_update_pix_fmt(struct v4l2_pix_format_mplane *pix_mp, unsigned int width, - unsigned int height) -{ - switch (pix_mp->pixelformat) { - case V4L2_PIX_FMT_YUV420: - case V4L2_PIX_FMT_NV12: - case V4L2_PIX_FMT_NV21: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height * 3 / 2; - break; - case V4L2_PIX_FMT_YUV422P: - case V4L2_PIX_FMT_NV16: - case V4L2_PIX_FMT_NV61: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height * 2; - break; - case V4L2_PIX_FMT_YUV420M: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[1].sizeimage = width * height / 4; - pix_mp->plane_fmt[2].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[2].sizeimage = width * height / 4; - break; - case V4L2_PIX_FMT_NV12M: - case V4L2_PIX_FMT_NV21M: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[1].sizeimage = width * height / 2; - break; - case V4L2_PIX_FMT_YUV422M: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[1].sizeimage = width * height / 2; - pix_mp->plane_fmt[2].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[2].sizeimage = width * height / 2; - break; - case V4L2_PIX_FMT_NV16M: - case V4L2_PIX_FMT_NV61M: - pix_mp->width = round_up(width, 32); - pix_mp->height = round_up(height, 16); - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = width * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[1].sizeimage = width * height; - break; - default: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = 0; - pix_mp->plane_fmt[0].sizeimage = max(DEFAULT_SRC_SIZE(width, height), - pix_mp->plane_fmt[0].sizeimage); - break; - } -} - static int start_decode(struct vpu_instance *inst, u32 *fail_res) { struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; @@ -389,6 +302,8 @@ static int handle_dynamic_resolution_change(struct vpu_instance *inst) } if (p_dec_info->initial_info_obtained) { + const struct vpu_format *vpu_fmt; + inst->conf_win.left = initial_info->pic_crop_rect.left; inst->conf_win.top = initial_info->pic_crop_rect.top; inst->conf_win.width = initial_info->pic_width - @@ -396,10 +311,27 @@ static int handle_dynamic_resolution_change(struct vpu_instance *inst) inst->conf_win.height = initial_info->pic_height - initial_info->pic_crop_rect.top - initial_info->pic_crop_rect.bottom; - wave5_update_pix_fmt(&inst->src_fmt, initial_info->pic_width, - initial_info->pic_height); - wave5_update_pix_fmt(&inst->dst_fmt, initial_info->pic_width, - initial_info->pic_height); + vpu_fmt = wave5_find_vpu_fmt(inst->src_fmt.pixelformat, + dec_fmt_list[VPU_FMT_TYPE_CODEC]); + if (!vpu_fmt) + return -EINVAL; + + wave5_update_pix_fmt(&inst->src_fmt, + VPU_FMT_TYPE_CODEC, + initial_info->pic_width, + initial_info->pic_height, + vpu_fmt->v4l2_frmsize); + + vpu_fmt = wave5_find_vpu_fmt(inst->dst_fmt.pixelformat, + dec_fmt_list[VPU_FMT_TYPE_RAW]); + if (!vpu_fmt) + return -EINVAL; + + wave5_update_pix_fmt(&inst->dst_fmt, + VPU_FMT_TYPE_RAW, + initial_info->pic_width, + initial_info->pic_height, + vpu_fmt->v4l2_frmsize); } v4l2_event_queue_fh(fh, &vpu_event_src_ch); @@ -548,12 +480,7 @@ static int wave5_vpu_dec_enum_framesizes(struct file *f, void *fh, struct v4l2_f } fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; - fsize->stepwise.min_width = vpu_fmt->min_width; - fsize->stepwise.max_width = vpu_fmt->max_width; - fsize->stepwise.step_width = 1; - fsize->stepwise.min_height = vpu_fmt->min_height; - fsize->stepwise.max_height = vpu_fmt->max_height; - fsize->stepwise.step_height = 1; + fsize->stepwise = *vpu_fmt->v4l2_frmsize; return 0; } @@ -589,14 +516,10 @@ static int wave5_vpu_dec_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo width = inst->dst_fmt.width; height = inst->dst_fmt.height; f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; } else { - const struct v4l2_format_info *info = v4l2_format_info(vpu_fmt->v4l2_pix_fmt); - - width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = info->mem_planes; } if (p_dec_info->initial_info_obtained) { @@ -604,9 +527,10 @@ static int wave5_vpu_dec_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo height = inst->dst_fmt.height; } - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_RAW, + width, + height, + vpu_fmt->v4l2_frmsize); f->fmt.pix_mp.colorspace = inst->colorspace; f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; f->fmt.pix_mp.quantization = inst->quantization; @@ -719,6 +643,7 @@ static int wave5_vpu_dec_try_fmt_out(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + int width, height; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u colorspace: %u field: %u\n", @@ -727,20 +652,19 @@ static int wave5_vpu_dec_try_fmt_out(struct file *file, void *fh, struct v4l2_fo vpu_fmt = wave5_find_vpu_fmt(f->fmt.pix_mp.pixelformat, dec_fmt_list[VPU_FMT_TYPE_CODEC]); if (!vpu_fmt) { + width = inst->src_fmt.width; + height = inst->src_fmt.height; f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, inst->src_fmt.width, inst->src_fmt.height); } else { - int width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - int height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); - + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = 1; - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_CODEC, + width, + height, + vpu_fmt->v4l2_frmsize); return 0; } @@ -748,6 +672,7 @@ static int wave5_vpu_dec_try_fmt_out(struct file *file, void *fh, struct v4l2_fo static int wave5_vpu_dec_s_fmt_out(struct file *file, void *fh, struct v4l2_format *f) { struct vpu_instance *inst = wave5_to_vpu_inst(fh); + const struct vpu_format *vpu_fmt; int i, ret; dev_dbg(inst->dev->dev, @@ -782,7 +707,14 @@ static int wave5_vpu_dec_s_fmt_out(struct file *file, void *fh, struct v4l2_form inst->quantization = f->fmt.pix_mp.quantization; inst->xfer_func = f->fmt.pix_mp.xfer_func; - wave5_update_pix_fmt(&inst->dst_fmt, f->fmt.pix_mp.width, f->fmt.pix_mp.height); + vpu_fmt = wave5_find_vpu_fmt(inst->dst_fmt.pixelformat, dec_fmt_list[VPU_FMT_TYPE_RAW]); + if (!vpu_fmt) + return -EINVAL; + + wave5_update_pix_fmt(&inst->dst_fmt, VPU_FMT_TYPE_RAW, + f->fmt.pix_mp.width, + f->fmt.pix_mp.height, + vpu_fmt->v4l2_frmsize); return 0; } @@ -1005,6 +937,7 @@ static int wave5_vpu_dec_queue_setup(struct vb2_queue *q, unsigned int *num_buff struct vpu_instance *inst = vb2_get_drv_priv(q); struct v4l2_pix_format_mplane inst_format = (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) ? inst->src_fmt : inst->dst_fmt; + unsigned int i; dev_dbg(inst->dev->dev, "%s: num_buffers: %u | num_planes: %u | type: %u\n", __func__, *num_buffers, *num_planes, q->type); @@ -1018,31 +951,9 @@ static int wave5_vpu_dec_queue_setup(struct vb2_queue *q, unsigned int *num_buff if (*num_buffers < inst->fbc_buf_count) *num_buffers = inst->fbc_buf_count; - if (*num_planes == 1) { - if (inst->output_format == FORMAT_422) - sizes[0] = inst_format.width * inst_format.height * 2; - else - sizes[0] = inst_format.width * inst_format.height * 3 / 2; - dev_dbg(inst->dev->dev, "%s: size[0]: %u\n", __func__, sizes[0]); - } else if (*num_planes == 2) { - sizes[0] = inst_format.width * inst_format.height; - if (inst->output_format == FORMAT_422) - sizes[1] = inst_format.width * inst_format.height; - else - sizes[1] = inst_format.width * inst_format.height / 2; - dev_dbg(inst->dev->dev, "%s: size[0]: %u | size[1]: %u\n", - __func__, sizes[0], sizes[1]); - } else if (*num_planes == 3) { - sizes[0] = inst_format.width * inst_format.height; - if (inst->output_format == FORMAT_422) { - sizes[1] = inst_format.width * inst_format.height / 2; - sizes[2] = inst_format.width * inst_format.height / 2; - } else { - sizes[1] = inst_format.width * inst_format.height / 4; - sizes[2] = inst_format.width * inst_format.height / 4; - } - dev_dbg(inst->dev->dev, "%s: size[0]: %u | size[1]: %u | size[2]: %u\n", - __func__, sizes[0], sizes[1], sizes[2]); + for (i = 0; i < *num_planes; i++) { + sizes[i] = inst_format.plane_fmt[i].sizeimage; + dev_dbg(inst->dev->dev, "%s: size[%u]: %u\n", __func__, i, sizes[i]); } } @@ -1564,20 +1475,17 @@ static const struct vb2_ops wave5_vpu_dec_vb2_ops = { static void wave5_set_default_format(struct v4l2_pix_format_mplane *src_fmt, struct v4l2_pix_format_mplane *dst_fmt) { - unsigned int dst_pix_fmt = dec_fmt_list[VPU_FMT_TYPE_RAW][0].v4l2_pix_fmt; - const struct v4l2_format_info *dst_fmt_info = v4l2_format_info(dst_pix_fmt); - src_fmt->pixelformat = dec_fmt_list[VPU_FMT_TYPE_CODEC][0].v4l2_pix_fmt; - src_fmt->field = V4L2_FIELD_NONE; - src_fmt->flags = 0; - src_fmt->num_planes = 1; - wave5_update_pix_fmt(src_fmt, 720, 480); - - dst_fmt->pixelformat = dst_pix_fmt; - dst_fmt->field = V4L2_FIELD_NONE; - dst_fmt->flags = 0; - dst_fmt->num_planes = dst_fmt_info->mem_planes; - wave5_update_pix_fmt(dst_fmt, 736, 480); + wave5_update_pix_fmt(src_fmt, VPU_FMT_TYPE_CODEC, + W5_DEF_DEC_PIC_WIDTH, + W5_DEF_DEC_PIC_HEIGHT, + &dec_hevc_frmsize); + + dst_fmt->pixelformat = dec_fmt_list[VPU_FMT_TYPE_RAW][0].v4l2_pix_fmt; + wave5_update_pix_fmt(dst_fmt, VPU_FMT_TYPE_RAW, + W5_DEF_DEC_PIC_WIDTH, + W5_DEF_DEC_PIC_HEIGHT, + &dec_raw_frmsize); } static int wave5_vpu_dec_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index 703fd8d1c7da..75d230df45f6 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -11,65 +11,60 @@ #define VPU_ENC_DEV_NAME "C&M Wave5 VPU encoder" #define VPU_ENC_DRV_NAME "wave5-enc" +static const struct v4l2_frmsize_stepwise enc_frmsize[FMT_TYPES] = { + [VPU_FMT_TYPE_CODEC] = { + .min_width = W5_MIN_ENC_PIC_WIDTH, + .max_width = W5_MAX_ENC_PIC_WIDTH, + .step_width = W5_ENC_CODEC_STEP_WIDTH, + .min_height = W5_MIN_ENC_PIC_HEIGHT, + .max_height = W5_MAX_ENC_PIC_HEIGHT, + .step_height = W5_ENC_CODEC_STEP_HEIGHT, + }, + [VPU_FMT_TYPE_RAW] = { + .min_width = W5_MIN_ENC_PIC_WIDTH, + .max_width = W5_MAX_ENC_PIC_WIDTH, + .step_width = W5_ENC_RAW_STEP_WIDTH, + .min_height = W5_MIN_ENC_PIC_HEIGHT, + .max_height = W5_MAX_ENC_PIC_HEIGHT, + .step_height = W5_ENC_RAW_STEP_HEIGHT, + }, +}; + static const struct vpu_format enc_fmt_list[FMT_TYPES][MAX_FMTS] = { [VPU_FMT_TYPE_CODEC] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_HEVC, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_CODEC], }, { .v4l2_pix_fmt = V4L2_PIX_FMT_H264, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_CODEC], }, }, [VPU_FMT_TYPE_RAW] = { { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .v4l2_pix_fmt = V4L2_PIX_FMT_YUV420M, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV12M, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, - .max_width = W5_MAX_ENC_PIC_WIDTH, - .min_width = W5_MIN_ENC_PIC_WIDTH, - .max_height = W5_MAX_ENC_PIC_HEIGHT, - .min_height = W5_MIN_ENC_PIC_HEIGHT, + .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, } }; @@ -106,46 +101,6 @@ static int switch_state(struct vpu_instance *inst, enum vpu_instance_state state return -EINVAL; } -static void wave5_update_pix_fmt(struct v4l2_pix_format_mplane *pix_mp, unsigned int width, - unsigned int height) -{ - switch (pix_mp->pixelformat) { - case V4L2_PIX_FMT_YUV420: - case V4L2_PIX_FMT_NV12: - case V4L2_PIX_FMT_NV21: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = round_up(width, 32) * height * 3 / 2; - break; - case V4L2_PIX_FMT_YUV420M: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = round_up(width, 32) * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[1].sizeimage = round_up(width, 32) * height / 4; - pix_mp->plane_fmt[2].bytesperline = round_up(width, 32) / 2; - pix_mp->plane_fmt[2].sizeimage = round_up(width, 32) * height / 4; - break; - case V4L2_PIX_FMT_NV12M: - case V4L2_PIX_FMT_NV21M: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[0].sizeimage = round_up(width, 32) * height; - pix_mp->plane_fmt[1].bytesperline = round_up(width, 32); - pix_mp->plane_fmt[1].sizeimage = round_up(width, 32) * height / 2; - break; - default: - pix_mp->width = width; - pix_mp->height = height; - pix_mp->plane_fmt[0].bytesperline = 0; - pix_mp->plane_fmt[0].sizeimage = width * height / 8 * 3; - break; - } -} - static int start_encode(struct vpu_instance *inst, u32 *fail_res) { struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; @@ -360,13 +315,8 @@ static int wave5_vpu_enc_enum_framesizes(struct file *f, void *fh, struct v4l2_f return -EINVAL; } - fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; - fsize->stepwise.min_width = vpu_fmt->min_width; - fsize->stepwise.max_width = vpu_fmt->max_width; - fsize->stepwise.step_width = 1; - fsize->stepwise.min_height = vpu_fmt->min_height; - fsize->stepwise.max_height = vpu_fmt->max_height; - fsize->stepwise.step_height = 1; + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; + fsize->stepwise = enc_frmsize[VPU_FMT_TYPE_CODEC]; return 0; } @@ -392,6 +342,7 @@ static int wave5_vpu_enc_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + int width, height; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, @@ -399,20 +350,19 @@ static int wave5_vpu_enc_try_fmt_cap(struct file *file, void *fh, struct v4l2_fo vpu_fmt = wave5_find_vpu_fmt(f->fmt.pix_mp.pixelformat, enc_fmt_list[VPU_FMT_TYPE_CODEC]); if (!vpu_fmt) { + width = inst->dst_fmt.width; + height = inst->dst_fmt.height; f->fmt.pix_mp.pixelformat = inst->dst_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->dst_fmt.num_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, inst->dst_fmt.width, inst->dst_fmt.height); } else { - int width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - int height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); - + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = 1; - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_CODEC, + width, + height, + vpu_fmt->v4l2_frmsize); f->fmt.pix_mp.colorspace = inst->colorspace; f->fmt.pix_mp.ycbcr_enc = inst->ycbcr_enc; f->fmt.pix_mp.quantization = inst->quantization; @@ -500,6 +450,7 @@ static int wave5_vpu_enc_try_fmt_out(struct file *file, void *fh, struct v4l2_fo { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + int width, height; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width, f->fmt.pix_mp.height, @@ -507,21 +458,19 @@ static int wave5_vpu_enc_try_fmt_out(struct file *file, void *fh, struct v4l2_fo vpu_fmt = wave5_find_vpu_fmt(f->fmt.pix_mp.pixelformat, enc_fmt_list[VPU_FMT_TYPE_RAW]); if (!vpu_fmt) { + width = inst->src_fmt.width; + height = inst->src_fmt.height; f->fmt.pix_mp.pixelformat = inst->src_fmt.pixelformat; - f->fmt.pix_mp.num_planes = inst->src_fmt.num_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, inst->src_fmt.width, inst->src_fmt.height); } else { - int width = clamp(f->fmt.pix_mp.width, vpu_fmt->min_width, vpu_fmt->max_width); - int height = clamp(f->fmt.pix_mp.height, vpu_fmt->min_height, vpu_fmt->max_height); - const struct v4l2_format_info *info = v4l2_format_info(vpu_fmt->v4l2_pix_fmt); - + width = f->fmt.pix_mp.width; + height = f->fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = vpu_fmt->v4l2_pix_fmt; - f->fmt.pix_mp.num_planes = info->mem_planes; - wave5_update_pix_fmt(&f->fmt.pix_mp, width, height); } - f->fmt.pix_mp.flags = 0; - f->fmt.pix_mp.field = V4L2_FIELD_NONE; + wave5_update_pix_fmt(&f->fmt.pix_mp, VPU_FMT_TYPE_RAW, + width, + height, + vpu_fmt->v4l2_frmsize); return 0; } @@ -529,6 +478,7 @@ static int wave5_vpu_enc_try_fmt_out(struct file *file, void *fh, struct v4l2_fo static int wave5_vpu_enc_s_fmt_out(struct file *file, void *fh, struct v4l2_format *f) { struct vpu_instance *inst = wave5_to_vpu_inst(fh); + const struct vpu_format *vpu_fmt; int i, ret; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", @@ -568,7 +518,16 @@ static int wave5_vpu_enc_s_fmt_out(struct file *file, void *fh, struct v4l2_form inst->quantization = f->fmt.pix_mp.quantization; inst->xfer_func = f->fmt.pix_mp.xfer_func; - wave5_update_pix_fmt(&inst->dst_fmt, f->fmt.pix_mp.width, f->fmt.pix_mp.height); + vpu_fmt = wave5_find_vpu_fmt(inst->dst_fmt.pixelformat, enc_fmt_list[VPU_FMT_TYPE_CODEC]); + if (!vpu_fmt) + return -EINVAL; + + wave5_update_pix_fmt(&inst->dst_fmt, VPU_FMT_TYPE_CODEC, + f->fmt.pix_mp.width, + f->fmt.pix_mp.height, + vpu_fmt->v4l2_frmsize); + inst->conf_win.width = inst->dst_fmt.width; + inst->conf_win.height = inst->dst_fmt.height; return 0; } @@ -584,12 +543,17 @@ static int wave5_vpu_enc_g_selection(struct file *file, void *fh, struct v4l2_se switch (s->target) { case V4L2_SEL_TGT_CROP_DEFAULT: case V4L2_SEL_TGT_CROP_BOUNDS: - case V4L2_SEL_TGT_CROP: s->r.left = 0; s->r.top = 0; s->r.width = inst->dst_fmt.width; s->r.height = inst->dst_fmt.height; break; + case V4L2_SEL_TGT_CROP: + s->r.left = 0; + s->r.top = 0; + s->r.width = inst->conf_win.width; + s->r.height = inst->conf_win.height; + break; default: return -EINVAL; } @@ -612,8 +576,10 @@ static int wave5_vpu_enc_s_selection(struct file *file, void *fh, struct v4l2_se s->r.left = 0; s->r.top = 0; - s->r.width = inst->src_fmt.width; - s->r.height = inst->src_fmt.height; + s->r.width = min(s->r.width, inst->dst_fmt.width); + s->r.height = min(s->r.height, inst->dst_fmt.height); + + inst->conf_win = s->r; return 0; } @@ -1151,8 +1117,8 @@ static void wave5_set_enc_openparam(struct enc_open_param *open_param, open_param->wave_param.lambda_scaling_enable = 1; open_param->line_buf_int_en = true; - open_param->pic_width = inst->dst_fmt.width; - open_param->pic_height = inst->dst_fmt.height; + open_param->pic_width = inst->conf_win.width; + open_param->pic_height = inst->conf_win.height; open_param->frame_rate_info = inst->frame_rate; open_param->rc_enable = inst->rc_enable; if (inst->rc_enable) { @@ -1456,20 +1422,17 @@ static const struct vb2_ops wave5_vpu_enc_vb2_ops = { static void wave5_set_default_format(struct v4l2_pix_format_mplane *src_fmt, struct v4l2_pix_format_mplane *dst_fmt) { - unsigned int src_pix_fmt = enc_fmt_list[VPU_FMT_TYPE_RAW][0].v4l2_pix_fmt; - const struct v4l2_format_info *src_fmt_info = v4l2_format_info(src_pix_fmt); - - src_fmt->pixelformat = src_pix_fmt; - src_fmt->field = V4L2_FIELD_NONE; - src_fmt->flags = 0; - src_fmt->num_planes = src_fmt_info->mem_planes; - wave5_update_pix_fmt(src_fmt, 416, 240); + src_fmt->pixelformat = enc_fmt_list[VPU_FMT_TYPE_RAW][0].v4l2_pix_fmt; + wave5_update_pix_fmt(src_fmt, VPU_FMT_TYPE_RAW, + W5_DEF_ENC_PIC_WIDTH, + W5_DEF_ENC_PIC_HEIGHT, + &enc_frmsize[VPU_FMT_TYPE_RAW]); dst_fmt->pixelformat = enc_fmt_list[VPU_FMT_TYPE_CODEC][0].v4l2_pix_fmt; - dst_fmt->field = V4L2_FIELD_NONE; - dst_fmt->flags = 0; - dst_fmt->num_planes = 1; - wave5_update_pix_fmt(dst_fmt, 416, 240); + wave5_update_pix_fmt(dst_fmt, VPU_FMT_TYPE_CODEC, + W5_DEF_ENC_PIC_WIDTH, + W5_DEF_ENC_PIC_HEIGHT, + &enc_frmsize[VPU_FMT_TYPE_CODEC]); } static int wave5_vpu_enc_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) @@ -1733,6 +1696,8 @@ static int wave5_vpu_open_enc(struct file *filp) v4l2_ctrl_handler_setup(v4l2_ctrl_hdl); wave5_set_default_format(&inst->src_fmt, &inst->dst_fmt); + inst->conf_win.width = inst->dst_fmt.width; + inst->conf_win.height = inst->dst_fmt.height; inst->colorspace = V4L2_COLORSPACE_REC709; inst->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; inst->quantization = V4L2_QUANTIZATION_DEFAULT; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.h b/drivers/media/platform/chips-media/wave5/wave5-vpu.h index 32b7fd3730b5..3847332551fc 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.h @@ -38,10 +38,7 @@ enum vpu_fmt_type { struct vpu_format { unsigned int v4l2_pix_fmt; - unsigned int max_width; - unsigned int min_width; - unsigned int max_height; - unsigned int min_height; + const struct v4l2_frmsize_stepwise *v4l2_frmsize; }; static inline struct vpu_instance *wave5_to_vpu_inst(struct v4l2_fh *vfh) diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h b/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h index d9751eedb0f9..8e11d93ca38f 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h @@ -30,10 +30,29 @@ #define MAX_NUM_INSTANCE 32 -#define W5_MIN_ENC_PIC_WIDTH 256 -#define W5_MIN_ENC_PIC_HEIGHT 128 -#define W5_MAX_ENC_PIC_WIDTH 8192 -#define W5_MAX_ENC_PIC_HEIGHT 8192 +#define W5_DEF_DEC_PIC_WIDTH 720U +#define W5_DEF_DEC_PIC_HEIGHT 480U +#define W5_MIN_DEC_PIC_8_WIDTH 8U +#define W5_MIN_DEC_PIC_8_HEIGHT 8U +#define W5_MIN_DEC_PIC_32_WIDTH 32U +#define W5_MIN_DEC_PIC_32_HEIGHT 32U +#define W5_MAX_DEC_PIC_WIDTH 8192U +#define W5_MAX_DEC_PIC_HEIGHT 4320U +#define W5_DEC_CODEC_STEP_WIDTH 1U +#define W5_DEC_CODEC_STEP_HEIGHT 1U +#define W5_DEC_RAW_STEP_WIDTH 32U +#define W5_DEC_RAW_STEP_HEIGHT 16U + +#define W5_DEF_ENC_PIC_WIDTH 416U +#define W5_DEF_ENC_PIC_HEIGHT 240U +#define W5_MIN_ENC_PIC_WIDTH 256U +#define W5_MIN_ENC_PIC_HEIGHT 128U +#define W5_MAX_ENC_PIC_WIDTH 8192U +#define W5_MAX_ENC_PIC_HEIGHT 8192U +#define W5_ENC_CODEC_STEP_WIDTH 8U +#define W5_ENC_CODEC_STEP_HEIGHT 8U +#define W5_ENC_RAW_STEP_WIDTH 32U +#define W5_ENC_RAW_STEP_HEIGHT 16U // application specific configuration #define VPU_ENC_TIMEOUT 60000 From patchwork Fri May 10 11:22: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: 796317 Received: from SE2P216CU007.outbound.protection.outlook.com (mail-koreacentralazon11020002.outbound.protection.outlook.com [52.101.154.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96627170859; Fri, 10 May 2024 11:23:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.154.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340206; cv=fail; b=DRSiqEU1pHL0euz+/koctNR9cfxLBH0s/jBB+AvaO5zM6R/GP500Inr67eYh7coPWaaOyzAR0xkPKGI/UBvxpgOwj2SiyWWY+JjNpyZFt6xgqy4VIytDmbzZ1fp05aQ7GFNzWfXU2VwDK/c7LeNLrA/NZaecSnZKfi3wXuF3G40= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340206; c=relaxed/simple; bh=g7GnN3v5b7brU1xSRBE+yINneysTTH6RhFrDZCOc82Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=auJhLoM903CXZH4GZCt/X+2Zi2ReDPZbaC+mB2yxQDYW2rddjAADRNqOfA2SzRgmLd6fhh4scwm1qRMHwE+aq+dyB7EBUmDDHwRZLRLSY0mJOSD35GwZ3PwexsMENmBte1+rwfY6uMzZtoivIUh3BgZdfzAblCchDD16gBaGZ00= 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=F/Spdvx5; arc=fail smtp.client-ip=52.101.154.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="F/Spdvx5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oevy7l3h4Nn61mwyPYvfdnbQwr8ccOGPfRpNuj7Kghesv8nsSvVtb41/tTZH7iI2EnyVLNcKLY6KydMAGXh/PYConEKm+sor1B8YEVmiYvUV3Gr7p07P066429pn8/bR4cImqOYJy65ocxDz9GEFUBxkUU+Yx5mFjqcnjecp++1pskMTdbrJISBKHyasesU6eRXOskW0oBAFjK51mqBQ8wwJtOqj0q/xNFi/84IsL60Nrad3XINJiHBDJpg61Y+yn3rc5//esM6znxjwRd8AI2y5SXWpL3NPVldm2ridYY2igES5mdLoTuwSv3+iv8X6rFUbrbSvt1i4ovXmDl7qcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SSBCqniFhGfdDtbG2A0I0Ml3S3aWDzVpm/x23WOZIfU=; b=dsqj91I5L+x4I5SnsLR0pmjD1A2rP+cUjCPozxB0MOEteDFsVD8AVey5F95fjqEjobJDERU1r0GS+cBeT34FN3cQBQDxojBV9nQuysuPedSX8D3KIKV6hxeV6a2AsWU37I/7fuKjV5CMz/X8FE/wTT0Fk91JHShBBkTX/0NJlqt1Q+CTfZuzDb9isOE0bwmcWgBNTCj2+HjMkCCyGmkk1oD1RllXu3kB6Z0C5o/HE8M20lbi0uXRxlaHUJ8kzeRxC1BuIyxD7Ogx4FvlD7bVsqbvWYymt/TB7AQL3+mSM57pa/VTvUe/sl5iIIfE1J52QUut56ePyy1vSuDkWL8GYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=chipsnmedia.com; dmarc=pass action=none header.from=chipsnmedia.com; dkim=pass header.d=chipsnmedia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chipsnmedia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SSBCqniFhGfdDtbG2A0I0Ml3S3aWDzVpm/x23WOZIfU=; b=F/Spdvx5cqUzVmnT5EbkIiOtZ7ylgYKGFgZ7L5/QkSVqocN8T5s3SyrcCir3EIzQD6xLVjPNyc2sJSn4S11fMujQtH+Sr1RygZOxihN9StcEoQz3+cyLM3qdCRmuCs0m0T6pfIhJ+RLzsybjQcMoAoYQVwHWfKCShdhIT/2rtdc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=chipsnmedia.com; Received: from PS2P216MB1297.KORP216.PROD.OUTLOOK.COM (2603:1096:301:73::13) by SL2P216MB2862.KORP216.PROD.OUTLOOK.COM (2603:1096:101:286::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.51; Fri, 10 May 2024 11:23:03 +0000 Received: from PS2P216MB1297.KORP216.PROD.OUTLOOK.COM ([fe80::ce88:bd2e:8caf:8004]) by PS2P216MB1297.KORP216.PROD.OUTLOOK.COM ([fe80::ce88:bd2e:8caf:8004%6]) with mapi id 15.20.7544.048; Fri, 10 May 2024 11:23:03 +0000 From: Jackson Lee To: mchehab@kernel.org, nicolas@ndufresne.ca, sebastian.fricke@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, hverkuil@xs4all.nl, nas.chung@chipsnmedia.com, lafley.kim@chipsnmedia.com, b-brnich@ti.com, jackson.lee@chipsnmedia.com Subject: [RESEND PATCH v4 4/4] media: chips-media: wave5: Support YUV422 raw pixel-formats on the encoder. Date: Fri, 10 May 2024 20:22:52 +0900 Message-Id: <20240510112252.800-5-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240510112252.800-1-jackson.lee@chipsnmedia.com> References: <20240510112252.800-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0168.KORP216.PROD.OUTLOOK.COM (2603:1096:101:1b::7) To PS2P216MB1297.KORP216.PROD.OUTLOOK.COM (2603:1096:301:73::13) 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: PS2P216MB1297:EE_|SL2P216MB2862:EE_ X-MS-Office365-Filtering-Correlation-Id: 48696a90-7201-4b58-a26c-08dc70e38e9a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|366007|376005|1800799015|52116005|38350700005; X-Microsoft-Antispam-Message-Info: CvN2uEwtRjkPXeRsM/kUb2aaKv+H7eO5/kLX6i3q/HA4F2Lm8zxufjWAw+pSyoEucgUIbg9W6H0u5FafcM4M632o5XfCJMtH30DXzSxHCDXH7WNUjJ9pM4N0z6Q7Y/wt/aUVCt7H3XQ43GoJMq2B3aGkemIpkZvRYBv1GhTM0Xjx7LQp34ClDcE3QggQgxmye8VvjCBwXI1abTDDboonPEJ6VeVIVQgsDQX/zIckYYHGXAAjE6HG6MN6Z6NREBd0xuuzFSTPxGl4KodJYvZ5VhI+Qdlwl+V8l24J5+031cln6wlTaZHQ0SuRZqymNCdEx9W/YFPU7AoNgX06pIr+mVQ7edmEjRFdTAH9v9Z6Y4aP408XE5PPgEQNDu8dvVas1LlWviqIButEcHCdNjgXfXWC2noE2KVKri4XAqcc2K/UXDwqT2qrI247vIhXXXQS9Pf2Q+kvHbLtVuz1cJBHIuOGqPfmH1rAzZ6I1hk3a4V1RjJPfbM6Wf+SAzxC/Pk6AP1Zlp2o7ElqaHKwWZMpTiw4aPz4GdaCGdGaeYLbSbXIohiZkoWvGHcJPB7fF0gCnJOw3WF934j6qOFWncXFPa4KTeDyPLYKEyqiqSfes1uwlfO7/H381lHsapiWGdZKhIqSCpF9AWcTfkB0LR/zT9f93noNuttx9yocVB3h0MpkUvg06qb93n0OeJDt22B7/Q5lz+E5x6eMeuQVp2yIL/0fz1elPummVxi78o2XdakL9Nw7AoWbXe34MllCure/gpy0ZxsqJwusO2I05Q93SVoVhZ+msDA0l50fHgo+1zjCcxbIv5eDRZCTO/l8T409Ac9ZWKaqABVROsVACAVUJ51VyilZlhRMmCuRctH+Zei0kMA75qWKCfvWBwZRLUaHkVzVy/ZDnMBfnP5r56MDExv/wbObyLQVjU8lmhEmafS5CusoduzD51fkXbL5MMYEy6V3Ls5c3iyYLw3JUCe3D2lE3qgGpJgwJzl6KGsX+T9FFvh2NKd4V1tujmHhPyvATB2YNHZWfh/QUlyeu620j5p14pYgjZE9HtYobxmSHNKMpZ+Wo3Sk00OnahB9f8KbVCJs5GMxP0DgduXVVRiHydLPq0r1DpwNGLWWNf673qXFvOygvBTrxZtgxI+0vUxrEKlnXgIJnl2jE3N77ighEY5ljvnHjd2e6DCAe6AWh7XLVN2/ySpAcwQVEbAtKgaNFjCj+OjSvV8i5WFPG4jmO1JyRn6PARkSoAFGiIhwPSasc/zIHwJmc2iRyJm7x5Wbq8aeQ53/71wjGWFPk0A83XU7N5ZkLsbgCVNwWLDtf3FC8mZ885lkMqAlsXAW+lXtrN1x23Z67Mmrp2hfTEt7Xw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PS2P216MB1297.KORP216.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230031)(366007)(376005)(1800799015)(52116005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PPOg4MIGb2Er6LRISLTQYJzyimYMYZIi50Uk/lfZBnv5UX4SS4fEcpT2tuWkjrWg9PeU54x8xSVoDOUzyJ3QzxdqjLlRFo8pGXZRchhZ5hXuM3EETy57SiQWmImQYqhH3HBjVdzsxUb1uR/d/YTXJ0RfBD+P6JDCx+zdjjeb8Xy3kAmMsrsChWkmRW1Tnjb60gLDUmWYOQQywnvUvWc7de99HNoSpbNheKG8ldlU/Ex2vAgoPz9AQ2f5ANk4rqoTgN0X5XgeD64m3bwiR/eRJk22kqrdp/Dn+kkcl+OcS7emx0BFj2XgqSBHDeVJXF5msJR/msOGzwvXm9RDWA98B5D09aTdJSjR2HvMsvCFJNUfqUu/SD1vbPUCYJyOybGy0+bxBPtoKnZpR6df4H9BJzyIYbF+KicRXA3d9tjr2skj9aOm5GDCWWHAsooFHXb8tWd1iLGhr3xdhy9+lqcucAgfq8teGLGMV+miMv86JlJdSlgk1vh6M8aC/+hNgbNZ3GTaUNZYX430k3h2GpKAa3DYqiXSDv5y0YKLLxaA6anM+4eu9duN/4U5aFSIj0mwmZXf/ETK92Cy0Tf4Git2dN/Z9HbnM2lJq3s34i40Okagez7GAVQ15x+y/LG9JaSF9emsihg3DfQcSwXFAnMm/kXXP1JVlDUtJh6VIr8XrulQ+uJ/5csEziOtxPZB1uppDiYev54rYmZoi/O52hoZJ8nBmhMnkhN2lEntHAJOF1HZmBi5tL4gCxyHXvlboocJGr7Y6gF8clgswoAs/XGniGmsdjhaS7SpkhPU0l/Ixjwchn3TiU0w6SsVzFGH23OSXitPZbZmyWw/uPRxnxcrBwLYXA0Jwbv6W4gLhIsmcA+PnmH/EdKFxZb61d6VabbuSEMeor5fiv+ym+9A8hNm3vIcxIuCUx8VQGYGprTg9HUicM9s0SsLg3R6xSpsO24PGPAxpqkmEXZ1tDGRteWONcHZlQ8HzidzRwi8UTTc88Q6LQNzIKER+Ua3n8dl/nzFIB4MIZazcY7kiuOzV2Edy9x3XLE2fzBVvnxZsPaVad0mmlx8JAZSi/RoMb/RdRjQ3Q1VirgrJQsA1BXnoRG1TX1uSi/CVKlZiJvtH4gL0Ngo7SS6YKmSJ3PwAOoeEVy/usRPr2x/NvKQC1PgeqBd/4fIS0n30GDB3VJPqL6XgpD351EVqJeV67YPIGuCek8xegrgOgo4gh5MmD8n7JN6Q7YR3lKW1vhIFzY1bMRXL/1Yb8ETzyv55lUo66t8ljb0MgyK2mtB8udCobXCVNfYPvuoTOEeKPNzBc1QDxJFXGTwJBmzOC7xp+bf5WGX9SY8OLSDa4ElikXc1lbXThm2ji4NOO+7oK5qP84qxfVCNXoDRweTNkp78l9ck8uvQjCDs96szSgC3wFS2rqniDK4AwMXQQflDe5sgTmZathldmwH+sxdCgJdZWJXKnJg+DvowUvfzvyKBXAg930ah3gmxumEVQ8YSYxGv9GlzO2lWnsPT4UMUjXXHzZLrW2uf607isdFA10EdIGeVZTuKn9U8wyeUkmeu6uaosaZIRQdDvlhxhFjG7LZ5nTCdHC43fAvTu8c23B+U+r8qj3KX6SLGg== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48696a90-7201-4b58-a26c-08dc70e38e9a X-MS-Exchange-CrossTenant-AuthSource: PS2P216MB1297.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 11:23:03.3123 (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: Eqdmn11kiciNOGdIsLsBL8i1nfsWzE9WAZ0vnE21rW3h5ISXyjd7jZqe5uJwiW+K8LOqGbu5ywQW1Z7zpA31LxLjvtp79xXj8W2FE5ZLE/4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2P216MB2862 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 | 81 +++++++++++++++---- 1 file changed, 67 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index 75d230df45f6..3f148e1b0513 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -66,6 +66,24 @@ static const struct vpu_format enc_fmt_list[FMT_TYPES][MAX_FMTS] = { .v4l2_pix_fmt = V4L2_PIX_FMT_NV21M, .v4l2_frmsize = &enc_frmsize[VPU_FMT_TYPE_RAW], }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422P, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV16, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV61, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_YUV422M, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV16M, + }, + { + .v4l2_pix_fmt = V4L2_PIX_FMT_NV61M, + }, } }; @@ -109,13 +127,26 @@ static int start_encode(struct vpu_instance *inst, u32 *fail_res) struct vb2_v4l2_buffer *dst_buf; struct frame_buffer frame_buf; struct enc_param pic_param; - u32 stride = ALIGN(inst->dst_fmt.width, 32); - u32 luma_size = (stride * inst->dst_fmt.height); - u32 chroma_size = ((stride / 2) * (inst->dst_fmt.height / 2)); + const struct v4l2_format_info *info; + u32 stride = inst->src_fmt.plane_fmt[0].bytesperline; + u32 luma_size = 0; + u32 chroma_size = 0; memset(&pic_param, 0, sizeof(struct enc_param)); memset(&frame_buf, 0, sizeof(struct frame_buffer)); + info = v4l2_format_info(inst->src_fmt.pixelformat); + if (!info) + return -EINVAL; + + if (info->mem_planes == 1) { + luma_size = stride * inst->dst_fmt.height; + chroma_size = luma_size / (info->hdiv * info->vdiv); + } else { + luma_size = inst->src_fmt.plane_fmt[0].sizeimage; + chroma_size = inst->src_fmt.plane_fmt[1].sizeimage; + } + dst_buf = v4l2_m2m_next_dst_buf(m2m_ctx); if (!dst_buf) { dev_dbg(inst->dev->dev, "%s: No destination buffer found\n", __func__); @@ -479,6 +510,7 @@ static int wave5_vpu_enc_s_fmt_out(struct file *file, void *fh, struct v4l2_form { struct vpu_instance *inst = wave5_to_vpu_inst(fh); const struct vpu_format *vpu_fmt; + const struct v4l2_format_info *info; int i, ret; dev_dbg(inst->dev->dev, "%s: fourcc: %u width: %u height: %u num_planes: %u field: %u\n", @@ -500,16 +532,20 @@ static int wave5_vpu_enc_s_fmt_out(struct file *file, void *fh, struct v4l2_form inst->src_fmt.plane_fmt[i].sizeimage = f->fmt.pix_mp.plane_fmt[i].sizeimage; } - if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV12 || - inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV12M) { - inst->cbcr_interleave = true; - inst->nv21 = false; - } else if (inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV21 || - inst->src_fmt.pixelformat == V4L2_PIX_FMT_NV21M) { - inst->cbcr_interleave = true; + info = v4l2_format_info(inst->src_fmt.pixelformat); + if (!info) + return -EINVAL; + + inst->cbcr_interleave = (info->comp_planes == 2) ? true : false; + + switch (inst->src_fmt.pixelformat) { + case V4L2_PIX_FMT_NV21: + case V4L2_PIX_FMT_NV21M: + case V4L2_PIX_FMT_NV61: + case V4L2_PIX_FMT_NV61M: inst->nv21 = true; - } else { - inst->cbcr_interleave = false; + break; + default: inst->nv21 = false; } @@ -1095,13 +1131,23 @@ static void wave5_vpu_enc_buf_queue(struct vb2_buffer *vb) v4l2_m2m_buf_queue(m2m_ctx, vbuf); } -static void wave5_set_enc_openparam(struct enc_open_param *open_param, +static int wave5_set_enc_openparam(struct enc_open_param *open_param, struct vpu_instance *inst) { struct enc_wave_param input = inst->enc_param; + const struct v4l2_format_info *info; u32 num_ctu_row = ALIGN(inst->dst_fmt.height, 64) / 64; u32 num_mb_row = ALIGN(inst->dst_fmt.height, 16) / 16; + info = v4l2_format_info(inst->src_fmt.pixelformat); + if (!info) + return -EINVAL; + + if (info->hdiv == 2 && info->vdiv == 1) + open_param->src_format = FORMAT_422; + else + open_param->src_format = FORMAT_420; + open_param->wave_param.gop_preset_idx = PRESET_IDX_IPP_SINGLE; open_param->wave_param.hvs_qp_scale = 2; open_param->wave_param.hvs_max_delta_qp = 10; @@ -1190,6 +1236,8 @@ static void wave5_set_enc_openparam(struct enc_open_param *open_param, open_param->wave_param.intra_refresh_arg = num_ctu_row; } open_param->wave_param.forced_idr_header_enable = input.forced_idr_header_enable; + + return 0; } static int initialize_sequence(struct vpu_instance *inst) @@ -1285,7 +1333,12 @@ static int wave5_vpu_enc_start_streaming(struct vb2_queue *q, unsigned int count memset(&open_param, 0, sizeof(struct enc_open_param)); - wave5_set_enc_openparam(&open_param, inst); + ret = wave5_set_enc_openparam(&open_param, inst); + if (ret) { + dev_dbg(inst->dev->dev, "%s: wave5_set_enc_openparam, fail: %d\n", + __func__, ret); + goto return_buffers; + } ret = wave5_vpu_enc_open(inst, &open_param); if (ret) {