Skip to contentSkip to conversation

media: mtk-vcodec: venc: support for MT8183

PATCH In review Alexandre Courbot 5 participants 29 messages Aug 21, 2020 – Aug 28, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover media: mtk-vcodec: venc: support for MT8183

Here is new respin of the MT8183 encoder support and v4l2-compliance fixes series, addressing issues raised during the v3 review (thanks in particular to Ezequiel for the feedback!). With this version I hope to complete the collection of Acked-by from respective maintainers. A few driver patches still need approval for the mtk-vcodec maintainer, and so does the patch adding the device tree node (9/17) that is new to this series.

This series has been tested and confirmed to work on both Hana (MT8173) and Krane (MT8183) Chromebooks. v4l2-compliance also passed successfully on both devices.

Changes since v3:
* Link mtk_vcodec_fw.o to the mtk_vcodec_common module
* Add some documentation to structures used for firmware communication
* Remove some on-the-spot variables renamings that were distracting
* Add device tree nodes for MT8183 boards
* Carry new Acked-bys

Changes since v2:
* Carried new Acked-bys from mtk-vcodec maintainer
* Removed 2 patches that were triggered by a bug in v4l2-compliance
* Moved DT bindings patches before the code implementing them

Changes since v1:
* Checked that no regressions against v4l2-compliance were introduced,
* Fixed 9 failing v4l2-compliance tests,
* Removed 1 cleanup patch of contested utility,
* Carried Acked-bys and Reviewed-bys from mtk-vcodec maintainer.

Alexandre Courbot (13):
dt-bindings: media: mtk-vcodec: document SCP node
media: mtk-vcodec: venc: handle firmware version field
media: mtk-vcodec: venc: specify bitrate range per-chip
media: mtk-vcodec: venc: specify supported formats per-chip
dt-bindings: media: document mediatek,mt8183-vcodec-enc
arm64: dts: mt8183: add encoder node
Revert "media: mtk-vcodec: Remove extra area allocation in an input
buffer on encoding"
media: mtk-vcodec: venc support MIN_OUTPUT_BUFFERS control
media: mtk-vcodec: venc: set OUTPUT buffers field to V4L2_FIELD_NONE
media: mtk-vcodec: venc: use platform data for ENUM_FRAMESIZES
media: mtk-vcodec: venc: support ENUM_FRAMESIZES on OUTPUT formats
media: mtk-vcodec: venc: set default time per frame
media: mtk-vcodec: venc: fix invalid time per frame in S_PARM

Yunfei Dong (4):
media: mtk-vcodec: abstract firmware interface
media: mtk-vcodec: add SCP firmware ops
media: mtk-vcodec: venc: support SCP firmware
media: mtk-vcodec: add support for MT8183 encoder

 .../bindings/media/mediatek-vcodec.txt        |   9 +-
 arch/arm64/boot/dts/mediatek/mt8183-evb.dts   |  10 +
 .../arm64/boot/dts/mediatek/mt8183-kukui.dtsi |  12 +
 arch/arm64/boot/dts/mediatek/mt8183.dtsi      |  36 +++
 drivers/media/platform/Kconfig                |   1 +
 drivers/media/platform/mtk-vcodec/Makefile    |   6 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  |  53 ++--
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.c   |   1 -
 .../platform/mtk-vcodec/mtk_vcodec_drv.h      |  40 ++-
 .../platform/mtk-vcodec/mtk_vcodec_enc.c      | 211 ++++++++--------
 .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c  | 173 +++++++++----
 .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c   |   2 -
 .../media/platform/mtk-vcodec/mtk_vcodec_fw.c | 228 ++++++++++++++++++
 .../media/platform/mtk-vcodec/mtk_vcodec_fw.h |  38 +++
 .../platform/mtk-vcodec/mtk_vcodec_util.c     |   1 -
 .../platform/mtk-vcodec/vdec/vdec_h264_if.c   |   1 -
 .../platform/mtk-vcodec/vdec/vdec_vp8_if.c    |   1 -
 .../platform/mtk-vcodec/vdec/vdec_vp9_if.c    |   1 -
 .../media/platform/mtk-vcodec/vdec_drv_base.h |   2 -
 .../media/platform/mtk-vcodec/vdec_drv_if.c   |   1 -
 .../media/platform/mtk-vcodec/vdec_vpu_if.c   |  12 +-
 .../media/platform/mtk-vcodec/vdec_vpu_if.h   |  11 +-
 .../platform/mtk-vcodec/venc/venc_h264_if.c   |  68 +++++-
 .../platform/mtk-vcodec/venc/venc_vp8_if.c    |  11 +-
 .../media/platform/mtk-vcodec/venc_drv_if.c   |   1 -
 .../media/platform/mtk-vcodec/venc_drv_if.h   |  13 +
 .../media/platform/mtk-vcodec/venc_ipi_msg.h  |  27 ++-
 .../media/platform/mtk-vcodec/venc_vpu_if.c   | 141 ++++++++---
 .../media/platform/mtk-vcodec/venc_vpu_if.h   |   8 +-
 29 files changed, 836 insertions(+), 283 deletions(-)
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h

--
2.28.0.297.g1956fa8f8d-goog

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#1 lore raw

PATCH v4 1/17 media: mtk-vcodec: abstract firmware interface

From: Yunfei Dong <[email protected]>

MT8183's codec firmware is run by a different remote processor from MT8173. While the firmware interface is basically the same, the way to invoke it differs. Abstract all firmware calls under a layer that will allow us to handle both firmware types transparently.

[acourbot: refactor, cleanup and split]
[pihsun: fix error path and add mtk_vcodec_fw_release]
---
 drivers/media/platform/mtk-vcodec/Makefile    |   6 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  |  50 ++---
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.c   |   1 -
 .../platform/mtk-vcodec/mtk_vcodec_drv.h      |   5 +-
 .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c  |  47 ++---
 .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c   |   2 -
 .../media/platform/mtk-vcodec/mtk_vcodec_fw.c | 172 ++++++++++++++++++
 .../media/platform/mtk-vcodec/mtk_vcodec_fw.h |  36 ++++
 .../platform/mtk-vcodec/mtk_vcodec_util.c     |   1 -
 .../platform/mtk-vcodec/vdec/vdec_h264_if.c   |   1 -
 .../platform/mtk-vcodec/vdec/vdec_vp8_if.c    |   1 -
 .../platform/mtk-vcodec/vdec/vdec_vp9_if.c    |   1 -
 .../media/platform/mtk-vcodec/vdec_drv_base.h |   2 -
 .../media/platform/mtk-vcodec/vdec_drv_if.c   |   1 -
 .../media/platform/mtk-vcodec/vdec_vpu_if.c   |  12 +-
 .../media/platform/mtk-vcodec/vdec_vpu_if.h   |  11 +-
 .../platform/mtk-vcodec/venc/venc_h264_if.c   |  15 +-
 .../platform/mtk-vcodec/venc/venc_vp8_if.c    |   8 +-
 .../media/platform/mtk-vcodec/venc_drv_if.c   |   1 -
 .../media/platform/mtk-vcodec/venc_vpu_if.c   |  17 +-
 .../media/platform/mtk-vcodec/venc_vpu_if.h   |   5 +-
 21 files changed, 291 insertions(+), 104 deletions(-)
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h
drivers/media/platform/mtk-vcodec/Makefile +2 -4
index 37b94b555fa1..f679c6e1a3e9 100644
@@ -13,7 +13,6 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \
 		mtk_vcodec_dec.o \
 		mtk_vcodec_dec_pm.o \
 
-
 mtk-vcodec-enc-y := venc/venc_vp8_if.o \
 		venc/venc_h264_if.o \
 		mtk_vcodec_enc.o \
@@ -24,6 +23,5 @@ mtk-vcodec-enc-y := venc/venc_vp8_if.o \
 
 
 mtk-vcodec-common-y := mtk_vcodec_intr.o \
-		mtk_vcodec_util.o\
-
-ccflags-y += -I$(srctree)/drivers/media/platform/mtk-vpu
+		mtk_vcodec_util.o \
+		mtk_vcodec_fw.o
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +20 -30

107 lines not on this page · raw message

drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c +0 -1
index 5a6ec8fb52da..36dfe3fc056a 100644
@@ -12,7 +12,6 @@
 
 #include "mtk_vcodec_dec_pm.h"
 #include "mtk_vcodec_util.h"
-#include "mtk_vpu.h"
 
 int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
 {
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +3 -2
index 9fd56dee7fd1..e132c4ec463a 100644
@@ -309,13 +309,13 @@ struct mtk_vcodec_ctx {
  * @m2m_dev_dec: m2m device for decoder
  * @m2m_dev_enc: m2m device for encoder.
  * @plat_dev: platform device
- * @vpu_plat_dev: mtk vpu platform device
  * @ctx_list: list of struct mtk_vcodec_ctx
  * @irqlock: protect data access by irq handler and work thread
  * @curr_ctx: The context that is waiting for codec hardware
  *
  * @reg_base: Mapped address of MTK Vcodec registers.
  *
+ * @fw_handler: used to communicate with the firmware.
  * @id_counter: used to identify current opened instance
  *
  * @encode_workqueue: encode work queue
@@ -344,12 +344,13 @@ struct mtk_vcodec_dev {
 	struct v4l2_m2m_dev *m2m_dev_dec;
 	struct v4l2_m2m_dev *m2m_dev_enc;
 	struct platform_device *plat_dev;
-	struct platform_device *vpu_plat_dev;
 	struct list_head ctx_list;
 	spinlock_t irqlock;
 	struct mtk_vcodec_ctx *curr_ctx;
 	void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
 
+	struct mtk_vcodec_fw *fw_handler;
+
 	unsigned long id_counter;
 
 	struct workqueue_struct *decode_workqueue;
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +19 -28

102 lines not on this page · raw message

drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +0 -2
index 3e2bfded79a6..ee22902aaa71 100644
@@ -12,8 +12,6 @@
 
 #include "mtk_vcodec_enc_pm.h"
 #include "mtk_vcodec_util.h"
-#include "mtk_vpu.h"
-
 
 int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
 {
drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c new file +172 -0

172 lines not on this page · raw message

drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h new file +36 -0
new file mode 100644
index 000000000000..ff25b0c19f74
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _MTK_VCODEC_FW_H_
+#define _MTK_VCODEC_FW_H_
+
+#include <linux/remoteproc.h>
+
+#include "../mtk-vpu/mtk_vpu.h"
+
+struct mtk_vcodec_dev;
+
+enum mtk_vcodec_fw_type {
+	VPU,
+};
+
+struct mtk_vcodec_fw;
+
+typedef void (*mtk_vcodec_ipi_handler) (void *data,
+	unsigned int len, void *priv);
+
+struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev,
+					   enum mtk_vcodec_fw_type type,
+					   enum rst_id rst_id);
+void mtk_vcodec_fw_release(struct mtk_vcodec_fw *fw);
+
+int mtk_vcodec_fw_load_firmware(struct mtk_vcodec_fw *fw);
+unsigned int mtk_vcodec_fw_get_vdec_capa(struct mtk_vcodec_fw *fw);
+unsigned int mtk_vcodec_fw_get_venc_capa(struct mtk_vcodec_fw *fw);
+void *mtk_vcodec_fw_map_dm_addr(struct mtk_vcodec_fw *fw, u32 mem_addr);
+int mtk_vcodec_fw_ipi_register(struct mtk_vcodec_fw *fw, int id,
+	mtk_vcodec_ipi_handler handler, const char *name, void *priv);
+int mtk_vcodec_fw_ipi_send(struct mtk_vcodec_fw *fw,
+	int id, void *buf, unsigned int len, unsigned int wait);
+
+#endif /* _MTK_VCODEC_FW_H_ */
+
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +0 -1
index d48f542db1a9..ac5973b6735f 100644
@@ -9,7 +9,6 @@
 
 #include "mtk_vcodec_drv.h"
 #include "mtk_vcodec_util.h"
-#include "mtk_vpu.h"
 
 /* For encoder, this will enable logs in venc/*/
 bool mtk_vcodec_dbg;
drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c +0 -1
index 50048c170b99..40d6e6c5ac7a 100644
@@ -281,7 +281,6 @@ static int vdec_h264_init(struct mtk_vcodec_ctx *ctx)
 	inst->ctx = ctx;
 
 	inst->vpu.id = IPI_VDEC_H264;
-	inst->vpu.dev = ctx->dev->vpu_plat_dev;
 	inst->vpu.ctx = ctx;
 
 	err = vpu_dec_init(&inst->vpu);
drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c +0 -1
index 6011fdd60a22..e5393f841080 100644
@@ -400,7 +400,6 @@ static int vdec_vp8_init(struct mtk_vcodec_ctx *ctx)
 	inst->ctx = ctx;
 
 	inst->vpu.id = IPI_VDEC_VP8;
-	inst->vpu.dev = ctx->dev->vpu_plat_dev;
 	inst->vpu.ctx = ctx;
 
 	err = vpu_dec_init(&inst->vpu);
drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c +0 -1
index 257a5b5ad212..8e099b859f21 100644
@@ -795,7 +795,6 @@ static int vdec_vp9_init(struct mtk_vcodec_ctx *ctx)
 	inst->ctx = ctx;
 
 	inst->vpu.id = IPI_VDEC_VP9;
-	inst->vpu.dev = ctx->dev->vpu_plat_dev;
 	inst->vpu.ctx = ctx;
 
 	if (vpu_dec_init(&inst->vpu)) {
drivers/media/platform/mtk-vcodec/vdec_drv_base.h +0 -2
index ceb4db4cb3be..e913f963b7db 100644
@@ -7,8 +7,6 @@
 #ifndef _VDEC_DRV_BASE_
 #define _VDEC_DRV_BASE_
 
-#include "mtk_vcodec_drv.h"
-
 #include "vdec_drv_if.h"
 
 struct vdec_common_if {
drivers/media/platform/mtk-vcodec/vdec_drv_if.c +0 -1
index 2e43dd4486e0..b18743b906ea 100644
@@ -13,7 +13,6 @@
 #include "mtk_vcodec_dec.h"
 #include "vdec_drv_base.h"
 #include "mtk_vcodec_dec_pm.h"
-#include "mtk_vpu.h"
 
 int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
 {
drivers/media/platform/mtk-vcodec/vdec_vpu_if.c +8 -4
index 948a12fd9d46..58b0e6fa8fd2 100644
@@ -8,6 +8,7 @@
 #include "mtk_vcodec_util.h"
 #include "vdec_ipi_msg.h"
 #include "vdec_vpu_if.h"
+#include "mtk_vcodec_fw.h"
 
 static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg)
 {
@@ -18,7 +19,8 @@ static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg)
 
 	/* mapping VPU address to kernel virtual address */
 	/* the content in vsi is initialized to 0 in VPU */
-	vpu->vsi = vpu_mapping_dm_addr(vpu->dev, msg->vpu_inst_addr);
+	vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler,
+					     msg->vpu_inst_addr);
 	vpu->inst_addr = msg->vpu_inst_addr;
 
 	mtk_vcodec_debug(vpu, "- vpu_inst_addr = 0x%x", vpu->inst_addr);
@@ -34,7 +36,7 @@ static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg)
  * This function runs in interrupt context and it means there's an IPI MSG
  * from VPU.
  */
-static void vpu_dec_ipi_handler(const void *data, unsigned int len, void *priv)
+static void vpu_dec_ipi_handler(void *data, unsigned int len, void *priv)
 {
 	const struct vdec_vpu_ipi_ack *msg = data;
 	struct vdec_vpu_inst *vpu = (struct vdec_vpu_inst *)
@@ -74,7 +76,8 @@ static int vcodec_vpu_send_msg(struct vdec_vpu_inst *vpu, void *msg, int len)
 	vpu->failure = 0;
 	vpu->signaled = 0;
 
-	err = vpu_ipi_send(vpu->dev, vpu->id, msg, len);
+	err = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, vpu->id, msg,
+				     len, 2000);
 	if (err) {
 		mtk_vcodec_err(vpu, "send fail vpu_id=%d msg_id=%X status=%d",
 			       vpu->id, *(uint32_t *)msg, err);
@@ -110,7 +113,8 @@ int vpu_dec_init(struct vdec_vpu_inst *vpu)
 	init_waitqueue_head(&vpu->wq);
 	vpu->handler = vpu_dec_ipi_handler;
 
-	err = vpu_ipi_register(vpu->dev, vpu->id, vpu->handler, "vdec", NULL);
+	err = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler, vpu->id,
+					 vpu->handler, "vdec", NULL);
 	if (err != 0) {
 		mtk_vcodec_err(vpu, "vpu_ipi_register fail status=%d", err);
 		return err;
drivers/media/platform/mtk-vcodec/vdec_vpu_if.h +6 -5
index f779b0676fbd..85224eb7e34b 100644
@@ -7,11 +7,13 @@
 #ifndef _VDEC_VPU_IF_H_
 #define _VDEC_VPU_IF_H_
 
-#include "mtk_vpu.h"
+#include "mtk_vcodec_fw.h"
+
+struct mtk_vcodec_ctx;
 
 /**
  * struct vdec_vpu_inst - VPU instance for video codec
- * @ipi_id      : ipi id for each decoder
+ * @id          : ipi msg id for each decoder
  * @vsi         : driver structure allocated by VPU side and shared to AP side
  *                for control and info share
  * @failure     : VPU execution result status, 0: success, others: fail
@@ -23,15 +25,14 @@
  * @handler     : ipi handler for each decoder
  */
 struct vdec_vpu_inst {
-	enum ipi_id id;
+	int id;
 	void *vsi;
 	int32_t failure;
 	uint32_t inst_addr;
 	unsigned int signaled;
 	struct mtk_vcodec_ctx *ctx;
-	struct platform_device *dev;
 	wait_queue_head_t wq;
-	ipi_handler_t handler;
+	mtk_vcodec_ipi_handler handler;
 };
 
 /**
drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c +9 -6
index b9624f8df0e9..7a00f050ec36 100644
@@ -18,7 +18,6 @@
 #include "../venc_drv_base.h"
 #include "../venc_ipi_msg.h"
 #include "../venc_vpu_if.h"
-#include "mtk_vpu.h"
 
 static const char h264_filler_marker[] = {0x0, 0x0, 0x0, 0x1, 0xc};
 
@@ -257,8 +256,11 @@ static int h264_enc_alloc_work_buf(struct venc_h264_inst *inst)
 		 */
 		inst->work_bufs[i].size = wb[i].size;
 		if (i == VENC_H264_VPU_WORK_BUF_SKIP_FRAME) {
-			inst->work_bufs[i].va = vpu_mapping_dm_addr(
-				inst->vpu_inst.dev, wb[i].vpua);
+			struct mtk_vcodec_fw *handler;
+
+			handler = inst->vpu_inst.ctx->dev->fw_handler;
+			inst->work_bufs[i].va =
+				mtk_vcodec_fw_map_dm_addr(handler, wb[i].vpua);
 			inst->work_bufs[i].dma_addr = 0;
 		} else {
 			ret = mtk_vcodec_mem_alloc(inst->ctx,
@@ -275,10 +277,12 @@ static int h264_enc_alloc_work_buf(struct venc_h264_inst *inst)
 			 * setting in VPU side.
 			 */
 			if (i == VENC_H264_VPU_WORK_BUF_RC_CODE) {
+				struct mtk_vcodec_fw *handler;
 				void *tmp_va;
 
-				tmp_va = vpu_mapping_dm_addr(inst->vpu_inst.dev,
-							     wb[i].vpua);
+				handler = inst->vpu_inst.ctx->dev->fw_handler;
+				tmp_va = mtk_vcodec_fw_map_dm_addr(handler,
+								   wb[i].vpua);
 				memcpy(inst->work_bufs[i].va, tmp_va,
 				       wb[i].size);
 			}
@@ -469,7 +473,6 @@ static int h264_enc_init(struct mtk_vcodec_ctx *ctx)
 
 	inst->ctx = ctx;
 	inst->vpu_inst.ctx = ctx;
-	inst->vpu_inst.dev = ctx->dev->vpu_plat_dev;
 	inst->vpu_inst.id = IPI_VENC_H264;
 	inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx, VENC_SYS);
 
drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c +4 -4
index 8d36f0362efe..6426af514526 100644
@@ -17,7 +17,6 @@
 #include "../venc_drv_base.h"
 #include "../venc_ipi_msg.h"
 #include "../venc_vpu_if.h"
-#include "mtk_vpu.h"
 
 #define VENC_BITSTREAM_FRAME_SIZE 0x0098
 #define VENC_BITSTREAM_HEADER_LEN 0x00e8
@@ -190,10 +189,12 @@ static int vp8_enc_alloc_work_buf(struct venc_vp8_inst *inst)
 		if (i == VENC_VP8_VPU_WORK_BUF_RC_CODE ||
 		    i == VENC_VP8_VPU_WORK_BUF_RC_CODE2 ||
 		    i == VENC_VP8_VPU_WORK_BUF_RC_CODE3) {
+			struct mtk_vcodec_fw *handler;
 			void *tmp_va;
 
-			tmp_va = vpu_mapping_dm_addr(inst->vpu_inst.dev,
-						     wb[i].vpua);
+			handler = inst->vpu_inst.ctx->dev->fw_handler;
+			tmp_va = mtk_vcodec_fw_map_dm_addr(handler,
+							   wb[i].vpua);
 			memcpy(inst->work_bufs[i].va, tmp_va, wb[i].size);
 		}
 		wb[i].iova = inst->work_bufs[i].dma_addr;
@@ -334,7 +335,6 @@ static int vp8_enc_init(struct mtk_vcodec_ctx *ctx)
 
 	inst->ctx = ctx;
 	inst->vpu_inst.ctx = ctx;
-	inst->vpu_inst.dev = ctx->dev->vpu_plat_dev;
 	inst->vpu_inst.id = IPI_VENC_VP8;
 	inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx, VENC_LT_SYS);
 
drivers/media/platform/mtk-vcodec/venc_drv_if.c +0 -1
index c6bb82ac2dcd..ce0bce811615 100644
@@ -15,7 +15,6 @@
 
 #include "mtk_vcodec_enc.h"
 #include "mtk_vcodec_enc_pm.h"
-#include "mtk_vpu.h"
 
 int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
 {
drivers/media/platform/mtk-vcodec/venc_vpu_if.c +10 -7
index 9540709c1905..53854127814b 100644
@@ -4,7 +4,7 @@
  * Author: PoChun Lin <[email protected]>
  */
 
-#include "mtk_vpu.h"
+#include "mtk_vcodec_fw.h"
 #include "venc_ipi_msg.h"
 #include "venc_vpu_if.h"
 
@@ -13,7 +13,8 @@ static void handle_enc_init_msg(struct venc_vpu_inst *vpu, const void *data)
 	const struct venc_vpu_ipi_msg_init *msg = data;
 
 	vpu->inst_addr = msg->vpu_inst_addr;
-	vpu->vsi = vpu_mapping_dm_addr(vpu->dev, msg->vpu_inst_addr);
+	vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler,
+					     msg->vpu_inst_addr);
 }
 
 static void handle_enc_encode_msg(struct venc_vpu_inst *vpu, const void *data)
@@ -25,7 +26,7 @@ static void handle_enc_encode_msg(struct venc_vpu_inst *vpu, const void *data)
 	vpu->is_key_frm = msg->is_key_frm;
 }
 
-static void vpu_enc_ipi_handler(const void *data, unsigned int len, void *priv)
+static void vpu_enc_ipi_handler(void *data, unsigned int len, void *priv)
 {
 	const struct venc_vpu_ipi_msg_common *msg = data;
 	struct venc_vpu_inst *vpu =
@@ -63,12 +64,13 @@ static int vpu_enc_send_msg(struct venc_vpu_inst *vpu, void *msg,
 
 	mtk_vcodec_debug_enter(vpu);
 
-	if (!vpu->dev) {
+	if (!vpu->ctx->dev->fw_handler) {
 		mtk_vcodec_err(vpu, "inst dev is NULL");
 		return -EINVAL;
 	}
 
-	status = vpu_ipi_send(vpu->dev, vpu->id, msg, len);
+	status = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, vpu->id, msg,
+					len, 2000);
 	if (status) {
 		mtk_vcodec_err(vpu, "vpu_ipi_send msg_id %x len %d fail %d",
 			       *(uint32_t *)msg, len, status);
@@ -93,8 +95,9 @@ int vpu_enc_init(struct venc_vpu_inst *vpu)
 	vpu->signaled = 0;
 	vpu->failure = 0;
 
-	status = vpu_ipi_register(vpu->dev, vpu->id, vpu_enc_ipi_handler,
-				  NULL, NULL);
+	status = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler, vpu->id,
+		vpu_enc_ipi_handler, "venc", NULL);
+
 	if (status) {
 		mtk_vcodec_err(vpu, "vpu_ipi_register fail %d", status);
 		return -EINVAL;
drivers/media/platform/mtk-vcodec/venc_vpu_if.h +2 -3
index ba301a138a5a..edd411621b68 100644
@@ -7,7 +7,7 @@
 #ifndef _VENC_VPU_IF_H_
 #define _VENC_VPU_IF_H_
 
-#include "mtk_vpu.h"
+#include "mtk_vcodec_fw.h"
 #include "venc_drv_if.h"
 
 /*
@@ -34,9 +34,8 @@ struct venc_vpu_inst {
 	int is_key_frm;
 	unsigned int inst_addr;
 	void *vsi;
-	enum ipi_id id;
+	int id;
 	struct mtk_vcodec_ctx *ctx;
-	struct platform_device *dev;
 };
 
 int vpu_enc_init(struct venc_vpu_inst *vpu);
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#2 lore raw

PATCH v4 2/17 dt-bindings: media: mtk-vcodec: document SCP node

In reply to Alexandre Courbot

The mediatek codecs can use either the VPU or the SCP as their interface to firmware. Reflect this in the DT bindings.

---
 Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/mediatek-vcodec.txt +3 -1
index b6b5dde6abd8..99214faede90 100644
@@ -19,7 +19,9 @@ Required properties:
 - iommus : should point to the respective IOMMU block with master port as
   argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
   for details.
-- mediatek,vpu : the node of video processor unit
+One of the two following nodes:
+- mediatek,vpu : the node of the video processor unit, if using VPU.
+- mediatek,scp : the node of the SCP unit, if using SCP.
 
 
 Example:
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
maintainer Acked-by on v4 2/17
#3 lore raw

Re: [PATCH v4 02/17] dt-bindings: media: mtk-vcodec: document SCP node

Quoted 9 lines · Alexandre Courbot

The mediatek codecs can use either the VPU or the SCP as their interface to firmware. Reflect this in the DT bindings.

---
 Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
#4 lore raw

PATCH v4 3/17 media: mtk-vcodec: add SCP firmware ops

In reply to Alexandre Courbot

From: Yunfei Dong <[email protected]>

Add support for communicating with the SCP firmware, which will be used by MT8183.

---
 drivers/media/platform/Kconfig                |  1 +
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  |  3 +
 .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c  |  3 +
 .../media/platform/mtk-vcodec/mtk_vcodec_fw.c | 56 +++++++++++++++++++
 .../media/platform/mtk-vcodec/mtk_vcodec_fw.h |  2 +
 5 files changed, 65 insertions(+)
drivers/media/platform/Kconfig +1 -0
index c57ee78fa99d..f0dbe048efea 100644
@@ -256,6 +256,7 @@ config VIDEO_MEDIATEK_VCODEC
 	select VIDEOBUF2_DMA_CONTIG
 	select V4L2_MEM2MEM_DEV
 	select VIDEO_MEDIATEK_VPU
+	select MTK_SCP
 	help
 	    Mediatek video codec driver provides HW capability to
 	    encode and decode in a range of video formats
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +3 -0
index 4f07a5fcce7f..5b5765b98e57 100644
@@ -225,6 +225,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
 	if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu",
 				  &rproc_phandle)) {
 		fw_type = VPU;
+	} else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp",
+					 &rproc_phandle)) {
+		fw_type = SCP;
 	} else {
 		mtk_v4l2_err("Could not get vdec IPI device");
 		return -ENODEV;
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +3 -0
index 4340ea10afd0..42530cd01a30 100644
@@ -233,6 +233,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
 	if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu",
 				  &rproc_phandle)) {
 		fw_type = VPU;
+	} else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp",
+					 &rproc_phandle)) {
+		fw_type = SCP;
 	} else {
 		mtk_v4l2_err("Could not get venc IPI device");
 		return -ENODEV;
drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c +56 -0

92 lines not on this page · raw message

drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h +2 -0
index ff25b0c19f74..ced1b6a10e07 100644
@@ -4,6 +4,7 @@
 #define _MTK_VCODEC_FW_H_
 
 #include <linux/remoteproc.h>
+#include <linux/remoteproc/mtk_scp.h>
 
 #include "../mtk-vpu/mtk_vpu.h"
 
@@ -11,6 +12,7 @@ struct mtk_vcodec_dev;
 
 enum mtk_vcodec_fw_type {
 	VPU,
+	SCP,
 };
 
 struct mtk_vcodec_fw;
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#5 lore raw

Re: [PATCH v4 03/17] media: mtk-vcodec: add SCP firmware ops

Thank you for the patch! Yet something to improve:

Hi Alexandre,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on robh/for-next v5.9-rc1 next-20200821] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Alexandre-Courbot/media-mtk-vcodec-venc-support-for-MT8183/20200821-184118
base:   git://linuxtv.org/media_tree.git master
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "scp_get_venc_hw_capa" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
>> ERROR: modpost: "scp_ipi_send" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
>> ERROR: modpost: "scp_put" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
>> ERROR: modpost: "scp_get" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
>> ERROR: modpost: "scp_get_vdec_hw_capa" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
>> ERROR: modpost: "scp_ipi_register" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
>> ERROR: modpost: "scp_mapping_dm_addr" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
>> ERROR: modpost: "scp_get_rproc" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
>> ERROR: modpost: "rproc_boot" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!

ERROR: modpost: "__delay" [drivers/net/phy/mdio-cavium.ko] undefined!

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#6 lore raw

Re: [PATCH v4 03/17] media: mtk-vcodec: add SCP firmware ops

Quoted 35 lines · kernel test robot

Hi Alexandre,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on robh/for-next v5.9-rc1 next-20200821] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Alexandre-Courbot/media-mtk-vcodec-venc-support-for-MT8183/20200821-184118
base:   git://linuxtv.org/media_tree.git master
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

Quoted 9 lines
Quoted 9 lines

ERROR: modpost: "scp_get_venc_hw_capa" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
ERROR: modpost: "scp_ipi_send" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
ERROR: modpost: "scp_put" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
ERROR: modpost: "scp_get" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
ERROR: modpost: "scp_get_vdec_hw_capa" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
ERROR: modpost: "scp_ipi_register" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
ERROR: modpost: "scp_mapping_dm_addr" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
ERROR: modpost: "scp_get_rproc" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!
ERROR: modpost: "rproc_boot" [drivers/media/platform/mtk-vcodec/mtk-vcodec-common.ko] undefined!

Quoted 1 line

ERROR: modpost: "__delay" [drivers/net/phy/mdio-cavium.ko] undefined!

This issue should be fixed by the following patch, sent to the remoteproc tree:

https://lkml.org/lkml/2020/8/21/489

#7 lore raw

PATCH v4 4/17 media: mtk-vcodec: venc: support SCP firmware

In reply to Alexandre Courbot

From: Yunfei Dong <[email protected]>

Support the new extended firmware used by MT8183's encoder.

---
 .../platform/mtk-vcodec/mtk_vcodec_drv.h      | 14 +++
 .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c  | 58 ++++++-----
 .../platform/mtk-vcodec/venc/venc_h264_if.c   | 53 ++++++++--
 .../platform/mtk-vcodec/venc/venc_vp8_if.c    |  3 +-
 .../media/platform/mtk-vcodec/venc_drv_if.h   | 13 +++
 .../media/platform/mtk-vcodec/venc_ipi_msg.h  | 18 ++++
 .../media/platform/mtk-vcodec/venc_vpu_if.c   | 97 +++++++++++++------
 .../media/platform/mtk-vcodec/venc_vpu_if.h   |  3 +-
 8 files changed, 202 insertions(+), 57 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +14 -0
index e132c4ec463a..e92e52c0e601 100644
@@ -300,6 +300,19 @@ struct mtk_vcodec_ctx {
 
 };
 
+/**
+ * struct mtk_vcodec_enc_pdata - compatible data for each IC
+ *
+ * @uses_ext: whether the encoder uses the extended firmware messaging format
+ * @has_lt_irq: whether the encoder uses the LT irq
+ */
+struct mtk_vcodec_enc_pdata {
+	bool uses_ext;
+	bool has_lt_irq;
+};
+
+#define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext)
+
 /**
  * struct mtk_vcodec_dev - driver data
  * @v4l2_dev: V4L2 device to register video devices for.
@@ -348,6 +361,7 @@ struct mtk_vcodec_dev {
 	spinlock_t irqlock;
 	struct mtk_vcodec_ctx *curr_ctx;
 	void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
+	const struct mtk_vcodec_enc_pdata *venc_pdata;
 
 	struct mtk_vcodec_fw *fw_handler;
 
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +36 -22

93 lines not on this page · raw message

drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c +47 -6

116 lines not on this page · raw message

drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c +2 -1
index 6426af514526..11abb191ada5 100644
@@ -302,7 +302,8 @@ static int vp8_enc_encode_frame(struct venc_vp8_inst *inst,
 
 	mtk_vcodec_debug(inst, "->frm_cnt=%d", inst->frm_cnt);
 
-	ret = vpu_enc_encode(&inst->vpu_inst, 0, frm_buf, bs_buf, bs_size);
+	ret = vpu_enc_encode(&inst->vpu_inst, 0, frm_buf, bs_buf, bs_size,
+			     NULL);
 	if (ret)
 		return ret;
 
drivers/media/platform/mtk-vcodec/venc_drv_if.h +13 -0
index 52fc9cc812fc..0b04a1020873 100644
@@ -92,6 +92,19 @@ struct venc_enc_param {
 	unsigned int gop_size;
 };
 
+/**
+ * struct venc_frame_info - per-frame information to pass to the firmware.
+ *
+ * @frm_count:		sequential number for this frame
+ * @skip_frm_count:	number of frames skipped so far while decoding
+ * @frm_type:		type of the frame, from enum venc_h264_frame_type
+ */
+struct venc_frame_info {
+	unsigned int frm_count;		/* per frame update */
+	unsigned int skip_frm_count;	/* per frame update */
+	unsigned int frm_type;		/* per frame update */
+};
+
 /*
  * struct venc_frm_buf - frame buffer information used in venc_if_encode()
  * @fb_addr: plane frame buffer addresses
drivers/media/platform/mtk-vcodec/venc_ipi_msg.h +18 -0
index 28ee04ca6241..316f8ecd6b4c 100644
@@ -62,6 +62,11 @@ struct venc_ap_ipi_msg_set_param {
 	uint32_t data[8];
 };
 
+struct venc_ap_ipi_msg_set_param_ext {
+	struct venc_ap_ipi_msg_set_param base;
+	uint32_t data_ext[24];
+};
+
 /**
  * struct venc_ap_ipi_msg_enc - AP to VPU enc cmd structure
  * @msg_id:	message id (AP_IPIMSG_XXX_ENC_ENCODE)
@@ -82,6 +87,19 @@ struct venc_ap_ipi_msg_enc {
 	uint32_t bs_size;
 };
 
+/**
+ * struct venc_ap_ipi_msg_enc_ext - AP to SCP extended enc cmd structure
+ *
+ * @base:	base msg structure
+ * @data_item:	number of items in the data array
+ * @data[8]:	data array to store the set parameters
+ */
+struct venc_ap_ipi_msg_enc_ext {
+	struct venc_ap_ipi_msg_enc base;
+	uint32_t data_item;
+	uint32_t data[32];
+};
+
 /**
  * struct venc_ap_ipi_msg_deinit - AP to VPU deinit cmd structure
  * @msg_id:	message id (AP_IPIMSG_XXX_ENC_DEINIT)
drivers/media/platform/mtk-vcodec/venc_vpu_if.c +70 -27

152 lines not on this page · raw message

drivers/media/platform/mtk-vcodec/venc_vpu_if.h +2 -1
index edd411621b68..f9be9cab7ff7 100644
@@ -45,7 +45,8 @@ int vpu_enc_set_param(struct venc_vpu_inst *vpu,
 int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode,
 		   struct venc_frm_buf *frm_buf,
 		   struct mtk_vcodec_mem *bs_buf,
-		   unsigned int *bs_size);
+		   unsigned int *bs_size,
+		   struct venc_frame_info *frame_info);
 int vpu_enc_deinit(struct venc_vpu_inst *vpu);
 
 #endif
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#8 lore raw

PATCH v4 5/17 media: mtk-vcodec: venc: handle firmware version field

In reply to Alexandre Courbot

Firmwares for encoders newer than MT8173 will include an ABI version number in their initialization ack message. Add the capacity to manage it and make initialization fail if the firmware ABI is of a version that we don't support.

For MT8173, this ABI version field is reserved and thus undefined ; thus ignore it on this chip. There should only be one firmware version available for it anyway.

---
 .../platform/mtk-vcodec/mtk_vcodec_drv.h      |  8 ++++++
 .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c  |  1 +
 .../media/platform/mtk-vcodec/venc_ipi_msg.h  |  9 ++++---
 .../media/platform/mtk-vcodec/venc_vpu_if.c   | 27 ++++++++++++++++---
 4 files changed, 38 insertions(+), 7 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +8 -0
index e92e52c0e601..1676c26eb229 100644
@@ -300,13 +300,21 @@ struct mtk_vcodec_ctx {
 
 };
 
+enum mtk_chip {
+	MTK_MT8173,
+};
+
 /**
  * struct mtk_vcodec_enc_pdata - compatible data for each IC
  *
+ * @chip: chip this encoder is compatible with
+ *
  * @uses_ext: whether the encoder uses the extended firmware messaging format
  * @has_lt_irq: whether the encoder uses the LT irq
  */
 struct mtk_vcodec_enc_pdata {
+	enum mtk_chip chip;
+
 	bool uses_ext;
 	bool has_lt_irq;
 };
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +1 -0
index c05f9614e117..379b6638f7a9 100644
@@ -384,6 +384,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
 }
 
 static const struct mtk_vcodec_enc_pdata mt8173_pdata = {
+	.chip = MTK_MT8173,
 	.has_lt_irq = true,
 };
 
drivers/media/platform/mtk-vcodec/venc_ipi_msg.h +5 -4
index 316f8ecd6b4c..2feb0365179f 100644
@@ -138,16 +138,17 @@ struct venc_vpu_ipi_msg_common {
  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
  * @vpu_inst_addr:	VPU encoder instance addr
  *			(struct venc_vp8_vsi/venc_h264_vsi *)
- * @reserved:	reserved for future use. vpu is running in 32bit. Without
- *		this reserved field, if kernel run in 64bit. this struct size
- *		will be different between kernel and vpu
+ * @venc_abi_version:	ABI version of the firmware. Kernel can use it to
+ *			ensure that it is compatible with the firmware.
+ *			For MT8173 the value of this field is undefined and
+ *			should not be used.
  */
 struct venc_vpu_ipi_msg_init {
 	uint32_t msg_id;
 	uint32_t status;
 	uint64_t venc_inst;
 	uint32_t vpu_inst_addr;
-	uint32_t reserved;
+	uint32_t venc_abi_version;
 };
 
 /**
drivers/media/platform/mtk-vcodec/venc_vpu_if.c +24 -3
index c526cd504fcc..124295f0a470 100644
@@ -4,6 +4,7 @@
  * Author: PoChun Lin <[email protected]>
  */
 
+#include "mtk_vcodec_drv.h"
 #include "mtk_vcodec_fw.h"
 #include "venc_ipi_msg.h"
 #include "venc_vpu_if.h"
@@ -15,6 +16,23 @@ static void handle_enc_init_msg(struct venc_vpu_inst *vpu, const void *data)
 	vpu->inst_addr = msg->vpu_inst_addr;
 	vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler,
 					     msg->vpu_inst_addr);
+
+	/* Firmware version field value is unspecified on MT8173. */
+	if (vpu->ctx->dev->venc_pdata->chip == MTK_MT8173)
+		return;
+
+	/* Check firmware version. */
+	mtk_vcodec_debug(vpu, "firmware version: 0x%x\n",
+			 msg->venc_abi_version);
+	switch (msg->venc_abi_version) {
+	case 1:
+		break;
+	default:
+		mtk_vcodec_err(vpu, "unhandled firmware version 0x%x\n",
+			       msg->venc_abi_version);
+		vpu->failure = 1;
+		break;
+	}
 }
 
 static void handle_enc_encode_msg(struct venc_vpu_inst *vpu, const void *data)
@@ -35,6 +53,11 @@ static void vpu_enc_ipi_handler(void *data, unsigned int len, void *priv)
 	mtk_vcodec_debug(vpu, "msg_id %x inst %p status %d",
 			 msg->msg_id, vpu, msg->status);
 
+	vpu->signaled = 1;
+	vpu->failure = (msg->status != VENC_IPI_MSG_STATUS_OK);
+	if (vpu->failure)
+		goto failure;
+
 	switch (msg->msg_id) {
 	case VPU_IPIMSG_ENC_INIT_DONE:
 		handle_enc_init_msg(vpu, data);
@@ -51,9 +74,7 @@ static void vpu_enc_ipi_handler(void *data, unsigned int len, void *priv)
 		break;
 	}
 
-	vpu->signaled = 1;
-	vpu->failure = (msg->status != VENC_IPI_MSG_STATUS_OK);
-
+failure:
 	mtk_vcodec_debug_leave(vpu);
 }
 
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#9 lore raw

PATCH v4 6/17 media: mtk-vcodec: venc: specify bitrate range per-chip

In reply to Alexandre Courbot

Different chips have different supported bitrate ranges. Move the min and max supported bitrates to the platform data.

---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h     | 4 ++++
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c     | 3 ++-
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 2 ++
 3 files changed, 8 insertions(+), 1 deletion(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +4 -0
index 1676c26eb229..e4b28fefcc95 100644
@@ -311,12 +311,16 @@ enum mtk_chip {
  *
  * @uses_ext: whether the encoder uses the extended firmware messaging format
  * @has_lt_irq: whether the encoder uses the LT irq
+ * @min_birate: minimum supported encoding bitrate
+ * @max_bitrate: maximum supported encoding bitrate
  */
 struct mtk_vcodec_enc_pdata {
 	enum mtk_chip chip;
 
 	bool uses_ext;
 	bool has_lt_irq;
+	unsigned long min_bitrate;
+	unsigned long max_bitrate;
 };
 
 #define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +2 -1
index d469ff6464b2..50ba9da59153 100644
@@ -1232,7 +1232,8 @@ int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx *ctx)
 	v4l2_ctrl_handler_init(handler, MTK_MAX_CTRLS_HINT);
 
 	v4l2_ctrl_new_std(handler, ops, V4L2_CID_MPEG_VIDEO_BITRATE,
-			1, 4000000, 1, 4000000);
+			  ctx->dev->venc_pdata->min_bitrate,
+			  ctx->dev->venc_pdata->max_bitrate, 1, 4000000);
 	v4l2_ctrl_new_std(handler, ops, V4L2_CID_MPEG_VIDEO_B_FRAMES,
 			0, 2, 1, 0);
 	v4l2_ctrl_new_std(handler, ops, V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE,
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +2 -0
index 379b6638f7a9..602f6a9c13e3 100644
@@ -386,6 +386,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
 static const struct mtk_vcodec_enc_pdata mt8173_pdata = {
 	.chip = MTK_MT8173,
 	.has_lt_irq = true,
+	.min_bitrate = 1,
+	.max_bitrate = 4000000,
 };
 
 static const struct of_device_id mtk_vcodec_enc_match[] = {
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#10 lore raw

PATCH v4 7/17 media: mtk-vcodec: venc: specify supported formats per-chip

In reply to Alexandre Courbot

Different chips have different supported formats. Move the list of supported formats to the platform data, and split the output and capture formats into two lists to make it easier to find the default format for each queue.

---
 .../platform/mtk-vcodec/mtk_vcodec_drv.h      |   8 ++
 .../platform/mtk-vcodec/mtk_vcodec_enc.c      | 122 +++++++-----------
 .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c  |  40 ++++++
 3 files changed, 95 insertions(+), 75 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +8 -0
index e4b28fefcc95..ba4045d64212 100644
@@ -313,6 +313,10 @@ enum mtk_chip {
  * @has_lt_irq: whether the encoder uses the LT irq
  * @min_birate: minimum supported encoding bitrate
  * @max_bitrate: maximum supported encoding bitrate
+ * @capture_formats: array of supported capture formats
+ * @num_capture_formats: number of entries in capture_formats
+ * @output_formats: array of supported output formats
+ * @num_output_formats: number of entries in output_formats
  */
 struct mtk_vcodec_enc_pdata {
 	enum mtk_chip chip;
@@ -321,6 +325,10 @@ struct mtk_vcodec_enc_pdata {
 	bool has_lt_irq;
 	unsigned long min_bitrate;
 	unsigned long max_bitrate;
+	const struct mtk_video_fmt *capture_formats;
+	size_t num_capture_formats;
+	const struct mtk_video_fmt *output_formats;
+	size_t num_output_formats;
 };
 
 #define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +47 -75

215 lines not on this page · raw message

drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +40 -0
index 602f6a9c13e3..569698f63515 100644
@@ -26,6 +26,42 @@
 module_param(mtk_v4l2_dbg_level, int, S_IRUGO | S_IWUSR);
 module_param(mtk_vcodec_dbg, bool, S_IRUGO | S_IWUSR);
 
+static const struct mtk_video_fmt mtk_video_formats_output_mt8173[] = {
+	{
+		.fourcc = V4L2_PIX_FMT_NV12M,
+		.type = MTK_FMT_FRAME,
+		.num_planes = 2,
+	},
+	{
+		.fourcc = V4L2_PIX_FMT_NV21M,
+		.type = MTK_FMT_FRAME,
+		.num_planes = 2,
+	},
+	{
+		.fourcc = V4L2_PIX_FMT_YUV420M,
+		.type = MTK_FMT_FRAME,
+		.num_planes = 3,
+	},
+	{
+		.fourcc = V4L2_PIX_FMT_YVU420M,
+		.type = MTK_FMT_FRAME,
+		.num_planes = 3,
+	},
+};
+
+static const struct mtk_video_fmt mtk_video_formats_capture_mt8173[] =  {
+	{
+		.fourcc = V4L2_PIX_FMT_H264,
+		.type = MTK_FMT_ENC,
+		.num_planes = 1,
+	},
+	{
+		.fourcc = V4L2_PIX_FMT_VP8,
+		.type = MTK_FMT_ENC,
+		.num_planes = 1,
+	},
+};
+
 /* Wake up context wait_queue */
 static void wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int reason)
 {
@@ -386,6 +422,10 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
 static const struct mtk_vcodec_enc_pdata mt8173_pdata = {
 	.chip = MTK_MT8173,
 	.has_lt_irq = true,
+	.capture_formats = mtk_video_formats_capture_mt8173,
+	.num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8173),
+	.output_formats = mtk_video_formats_output_mt8173,
+	.num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
 	.min_bitrate = 1,
 	.max_bitrate = 4000000,
 };
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#11 lore raw

PATCH v4 8/17 dt-bindings: media: document mediatek,mt8183-vcodec-enc

In reply to Alexandre Courbot

MT8183's encoder is similar to MT8173's.

---
 Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/media/mediatek-vcodec.txt +3 -2
index 99214faede90..8217424fd4bd 100644
@@ -4,8 +4,9 @@ Mediatek Video Codec is the video codec hw present in Mediatek SoCs which
 supports high resolution encoding and decoding functionalities.
 
 Required properties:
-- compatible : "mediatek,mt8173-vcodec-enc" for encoder
-  "mediatek,mt8173-vcodec-dec" for decoder.
+- compatible : "mediatek,mt8173-vcodec-enc" for MT8173 encoder
+  "mediatek,mt8183-vcodec-enc" for MT8183 encoder.
+  "mediatek,mt8173-vcodec-dec" for MT8173 decoder.
 - reg : Physical base address of the video codec registers and length of
   memory mapped region.
 - interrupts : interrupt number to the cpu.
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#12 lore raw

PATCH v4 9/17 arm64: dts: mt8183: add encoder node

In reply to Alexandre Courbot

Now that the MT8183 encoder driver is ready, add its DT node. Also pull the iommu and scp ones, which the encoder depends upon.

---
 arch/arm64/boot/dts/mediatek/mt8183-evb.dts   | 10 ++++++
 .../arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 12 +++++++
 arch/arm64/boot/dts/mediatek/mt8183.dtsi      | 36 +++++++++++++++++++
 3 files changed, 58 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183-evb.dts +10 -0
index ae405bd8f06b..9e77b420eee8 100644
@@ -25,6 +25,16 @@ memory@40000000 {
 	chosen {
 		stdout-path = "serial0:921600n8";
 	};
+	reserved-memory {
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+		scp_mem_reserved: scp_mem_region {
+			compatible = "shared-dma-pool";
+			reg = <0 0x50000000 0 0x2900000>;
+			no-map;
+		};
+	};
 };
 
 &auxadc {
arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi +12 -0
index f0a070535b34..3c763be658da 100644
@@ -90,6 +90,18 @@ pp3300_alw: regulator6 {
 		regulator-max-microvolt = <3300000>;
 	};
 
+	reserved_memory: reserved-memory {
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+
+		scp_mem_reserved: scp_mem_region {
+			compatible = "shared-dma-pool";
+			reg = <0 0x50000000 0 0x2900000>;
+			no-map;
+		};
+	};
+
 	max98357a: codec0 {
 		compatible = "maxim,max98357a";
 		sdmode-gpios = <&pio 175 0>;
arch/arm64/boot/dts/mediatek/mt8183.dtsi +36 -0
index 102105871db2..8f77eea6df27 100644
@@ -8,6 +8,7 @@
 #include <dt-bindings/clock/mt8183-clk.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/memory/mt8183-larb-port.h>
 #include <dt-bindings/reset-controller/mt8183-resets.h>
 #include <dt-bindings/phy/phy.h>
 #include "mt8183-pinfunc.h"
@@ -339,6 +340,25 @@ pwrap: pwrap@1000d000 {
 			clock-names = "spi", "wrap";
 		};
 
+		iommu: iommu@10205000 {
+			compatible = "mediatek,mt8183-m4u";
+			reg = <0 0x10205000 0 0x1000>;
+			interrupts = <GIC_SPI 166 IRQ_TYPE_LEVEL_LOW>;
+			#iommu-cells = <1>;
+		};
+
+		scp: scp@10500000 {
+			compatible = "mediatek,mt8183-scp";
+			reg = <0 0x10500000 0 0x80000>,
+			      <0 0x105c0000 0 0x19080>;
+			reg-names = "sram", "cfg";
+			interrupts = <GIC_SPI 174 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&infracfg CLK_INFRA_SCPSYS>;
+			clock-names = "main";
+			memory-region = <&scp_mem_reserved>;
+			status = "disabled";
+		};
+
 		systimer: timer@10017000 {
 			compatible = "mediatek,mt8183-timer",
 				     "mediatek,mt6765-timer";
@@ -772,6 +792,22 @@ vencsys: syscon@17000000 {
 			#clock-cells = <1>;
 		};
 
+		vcodec_enc: vcodec@17020000 {
+			compatible = "mediatek,mt8183-vcodec-enc";
+			reg = <0 0x17020000 0 0x1000>;
+			interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_LOW>;
+			iommus = <&iommu M4U_PORT_VENC_REC>,
+				 <&iommu M4U_PORT_VENC_BSDMA>,
+				 <&iommu M4U_PORT_VENC_RD_COMV>,
+				 <&iommu M4U_PORT_VENC_CUR_LUMA>,
+				 <&iommu M4U_PORT_VENC_CUR_CHROMA>,
+				 <&iommu M4U_PORT_VENC_REF_LUMA>,
+				 <&iommu M4U_PORT_VENC_REF_CHROMA>;
+			mediatek,scp = <&scp>;
+			clocks = <&vencsys CLK_VENC_VENC>;
+			clock-names = "MT_CG_VENC";
+		};
+
 		ipu_conn: syscon@19000000 {
 			compatible = "mediatek,mt8183-ipu_conn", "syscon";
 			reg = <0 0x19000000 0 0x1000>;
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
maintainer
#13 lore raw

Re: [PATCH v4 09/17] arm64: dts: mt8183: add encoder node

Quoted 2 lines · Alexandre Courbot

Now that the MT8183 encoder driver is ready, add its DT node. Also pull the iommu and scp ones, which the encoder depends upon.

Please don't do that. Instead of pulling in other DT nodes, it would be handy to get a reference of the series this is based on.

Let me try to hunt them down now :)

Regards,
Matthias

Quoted 114 lines
---
  arch/arm64/boot/dts/mediatek/mt8183-evb.dts   | 10 ++++++
  .../arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 12 +++++++
  arch/arm64/boot/dts/mediatek/mt8183.dtsi      | 36 +++++++++++++++++++
  3 files changed, 58 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183-evb.dts +10 -0
index ae405bd8f06b..9e77b420eee8 100644
@@ -25,6 +25,16 @@ memory@40000000 {
  	chosen {
  		stdout-path = "serial0:921600n8";
  	};
+	reserved-memory {
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+		scp_mem_reserved: scp_mem_region {
+			compatible = "shared-dma-pool";
+			reg = <0 0x50000000 0 0x2900000>;
+			no-map;
+		};
+	};
  };
 
  &auxadc {
arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi +12 -0
index f0a070535b34..3c763be658da 100644
@@ -90,6 +90,18 @@ pp3300_alw: regulator6 {
  		regulator-max-microvolt = <3300000>;
  	};
 
+	reserved_memory: reserved-memory {
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+
+		scp_mem_reserved: scp_mem_region {
+			compatible = "shared-dma-pool";
+			reg = <0 0x50000000 0 0x2900000>;
+			no-map;
+		};
+	};
+
  	max98357a: codec0 {
  		compatible = "maxim,max98357a";
  		sdmode-gpios = <&pio 175 0>;
arch/arm64/boot/dts/mediatek/mt8183.dtsi +36 -0
index 102105871db2..8f77eea6df27 100644
@@ -8,6 +8,7 @@
  #include <dt-bindings/clock/mt8183-clk.h>
  #include <dt-bindings/interrupt-controller/arm-gic.h>
  #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/memory/mt8183-larb-port.h>
  #include <dt-bindings/reset-controller/mt8183-resets.h>
  #include <dt-bindings/phy/phy.h>
  #include "mt8183-pinfunc.h"
@@ -339,6 +340,25 @@ pwrap: pwrap@1000d000 {
  			clock-names = "spi", "wrap";
  		};
 
+		iommu: iommu@10205000 {
+			compatible = "mediatek,mt8183-m4u";
+			reg = <0 0x10205000 0 0x1000>;
+			interrupts = <GIC_SPI 166 IRQ_TYPE_LEVEL_LOW>;
+			#iommu-cells = <1>;
+		};
+
+		scp: scp@10500000 {
+			compatible = "mediatek,mt8183-scp";
+			reg = <0 0x10500000 0 0x80000>,
+			      <0 0x105c0000 0 0x19080>;
+			reg-names = "sram", "cfg";
+			interrupts = <GIC_SPI 174 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&infracfg CLK_INFRA_SCPSYS>;
+			clock-names = "main";
+			memory-region = <&scp_mem_reserved>;
+			status = "disabled";
+		};
+
  		systimer: timer@10017000 {
  			compatible = "mediatek,mt8183-timer",
  				     "mediatek,mt6765-timer";
@@ -772,6 +792,22 @@ vencsys: syscon@17000000 {
  			#clock-cells = <1>;
  		};
 
+		vcodec_enc: vcodec@17020000 {
+			compatible = "mediatek,mt8183-vcodec-enc";
+			reg = <0 0x17020000 0 0x1000>;
+			interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_LOW>;
+			iommus = <&iommu M4U_PORT_VENC_REC>,
+				 <&iommu M4U_PORT_VENC_BSDMA>,
+				 <&iommu M4U_PORT_VENC_RD_COMV>,
+				 <&iommu M4U_PORT_VENC_CUR_LUMA>,
+				 <&iommu M4U_PORT_VENC_CUR_CHROMA>,
+				 <&iommu M4U_PORT_VENC_REF_LUMA>,
+				 <&iommu M4U_PORT_VENC_REF_CHROMA>;
+			mediatek,scp = <&scp>;
+			clocks = <&vencsys CLK_VENC_VENC>;
+			clock-names = "MT_CG_VENC";
+		};
+
  		ipu_conn: syscon@19000000 {
  			compatible = "mediatek,mt8183-ipu_conn", "syscon";
  			reg = <0 0x19000000 0 0x1000>;
#14 lore raw

Re: [PATCH v4 09/17] arm64: dts: mt8183: add encoder node

Quoted 11 lines · Matthias Brugger
Quoted 2 lines · Alexandre Courbot

Now that the MT8183 encoder driver is ready, add its DT node. Also pull the iommu and scp ones, which the encoder depends upon.

Please don't do that. Instead of pulling in other DT nodes, it would be handy to get a reference of the series this is based on.

Let me try to hunt them down now :)

Sorry, I'm not sure to understand - do you mean each node should come with its own patch? Or that all the code should be merged before sending these nodes? The rest of this series should land into the media tree soon, if you prefer I can resend this patch separately once that happens.

Quoted 118 lines

Regards,
Matthias

Quoted 114 lines
---
  arch/arm64/boot/dts/mediatek/mt8183-evb.dts   | 10 ++++++
  .../arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 12 +++++++
  arch/arm64/boot/dts/mediatek/mt8183.dtsi      | 36 +++++++++++++++++++
  3 files changed, 58 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183-evb.dts +10 -0
index ae405bd8f06b..9e77b420eee8 100644
@@ -25,6 +25,16 @@ memory@40000000 {
      chosen {
              stdout-path = "serial0:921600n8";
      };
+     reserved-memory {
+             #address-cells = <2>;
+             #size-cells = <2>;
+             ranges;
+             scp_mem_reserved: scp_mem_region {
+                     compatible = "shared-dma-pool";
+                     reg = <0 0x50000000 0 0x2900000>;
+                     no-map;
+             };
+     };
  };
 
  &auxadc {
arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi +12 -0
index f0a070535b34..3c763be658da 100644
@@ -90,6 +90,18 @@ pp3300_alw: regulator6 {
              regulator-max-microvolt = <3300000>;
      };
 
+     reserved_memory: reserved-memory {
+             #address-cells = <2>;
+             #size-cells = <2>;
+             ranges;
+
+             scp_mem_reserved: scp_mem_region {
+                     compatible = "shared-dma-pool";
+                     reg = <0 0x50000000 0 0x2900000>;
+                     no-map;
+             };
+     };
+
      max98357a: codec0 {
              compatible = "maxim,max98357a";
              sdmode-gpios = <&pio 175 0>;
arch/arm64/boot/dts/mediatek/mt8183.dtsi +36 -0
index 102105871db2..8f77eea6df27 100644
@@ -8,6 +8,7 @@
  #include <dt-bindings/clock/mt8183-clk.h>
  #include <dt-bindings/interrupt-controller/arm-gic.h>
  #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/memory/mt8183-larb-port.h>
  #include <dt-bindings/reset-controller/mt8183-resets.h>
  #include <dt-bindings/phy/phy.h>
  #include "mt8183-pinfunc.h"
@@ -339,6 +340,25 @@ pwrap: pwrap@1000d000 {
                      clock-names = "spi", "wrap";
              };
 
+             iommu: iommu@10205000 {
+                     compatible = "mediatek,mt8183-m4u";
+                     reg = <0 0x10205000 0 0x1000>;
+                     interrupts = <GIC_SPI 166 IRQ_TYPE_LEVEL_LOW>;
+                     #iommu-cells = <1>;
+             };
+
+             scp: scp@10500000 {
+                     compatible = "mediatek,mt8183-scp";
+                     reg = <0 0x10500000 0 0x80000>,
+                           <0 0x105c0000 0 0x19080>;
+                     reg-names = "sram", "cfg";
+                     interrupts = <GIC_SPI 174 IRQ_TYPE_LEVEL_HIGH>;
+                     clocks = <&infracfg CLK_INFRA_SCPSYS>;
+                     clock-names = "main";
+                     memory-region = <&scp_mem_reserved>;
+                     status = "disabled";
+             };
+
              systimer: timer@10017000 {
                      compatible = "mediatek,mt8183-timer",
                                   "mediatek,mt6765-timer";
@@ -772,6 +792,22 @@ vencsys: syscon@17000000 {
                      #clock-cells = <1>;
              };
 
+             vcodec_enc: vcodec@17020000 {
+                     compatible = "mediatek,mt8183-vcodec-enc";
+                     reg = <0 0x17020000 0 0x1000>;
+                     interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_LOW>;
+                     iommus = <&iommu M4U_PORT_VENC_REC>,
+                              <&iommu M4U_PORT_VENC_BSDMA>,
+                              <&iommu M4U_PORT_VENC_RD_COMV>,
+                              <&iommu M4U_PORT_VENC_CUR_LUMA>,
+                              <&iommu M4U_PORT_VENC_CUR_CHROMA>,
+                              <&iommu M4U_PORT_VENC_REF_LUMA>,
+                              <&iommu M4U_PORT_VENC_REF_CHROMA>;
+                     mediatek,scp = <&scp>;
+                     clocks = <&vencsys CLK_VENC_VENC>;
+                     clock-names = "MT_CG_VENC";
+             };
+
              ipu_conn: syscon@19000000 {
                      compatible = "mediatek,mt8183-ipu_conn", "syscon";
                      reg = <0 0x19000000 0 0x1000>;
maintainer
#15 lore raw

Re: [PATCH v4 09/17] arm64: dts: mt8183: add encoder node

Hi Alexandre,

Quoted 11 lines · Alexandre Courbot
Quoted 10 lines · Matthias Brugger
Quoted 2 lines · Alexandre Courbot

Now that the MT8183 encoder driver is ready, add its DT node. Also pull the iommu and scp ones, which the encoder depends upon.

Please don't do that. Instead of pulling in other DT nodes, it would be handy to get a reference of the series this is based on.

Quoted 8 lines
Quoted 1 line

Let me try to hunt them down now :)

Sorry, I'm not sure to understand - do you mean each node should come with its own patch? Or that all the code should be merged before sending these nodes? The rest of this series should land into the media tree soon, if you prefer I can resend this patch separately once that happens.

What I'm talking about is the case when you send a series that's based on another one and the latter is not yet accepted in Torvalds tree. In that case it helps to point to the series you expect to be included as well.

In this case the SCP series was merged long time ago, but I missed the DTS change. It would have been good if you would have added that information in your series, instead of directly pulling in the SCP node.

For the iommu node: I understand that there was never a patch adding the node (at least I wasn't able to find one). So I'd prefer to have it send as a separate patch of this series.

Regarding this series now. If you want just resend the two DTS patches (iommu and vcodec_enc) once the rest of this series got accpeted. If for any other reason you have to send a v5, then feel free to include both in v5.

Hope I explained myself now :)

Regards,
Matthias

Quoted 118 lines
Quoted 118 lines

Regards,
Matthias

Quoted 114 lines
---
   arch/arm64/boot/dts/mediatek/mt8183-evb.dts   | 10 ++++++
   .../arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 12 +++++++
   arch/arm64/boot/dts/mediatek/mt8183.dtsi      | 36 +++++++++++++++++++
   3 files changed, 58 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183-evb.dts +10 -0
index ae405bd8f06b..9e77b420eee8 100644
@@ -25,6 +25,16 @@ memory@40000000 {
       chosen {
               stdout-path = "serial0:921600n8";
       };
+     reserved-memory {
+             #address-cells = <2>;
+             #size-cells = <2>;
+             ranges;
+             scp_mem_reserved: scp_mem_region {
+                     compatible = "shared-dma-pool";
+                     reg = <0 0x50000000 0 0x2900000>;
+                     no-map;
+             };
+     };
   };
 
   &auxadc {
arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi +12 -0
index f0a070535b34..3c763be658da 100644
@@ -90,6 +90,18 @@ pp3300_alw: regulator6 {
               regulator-max-microvolt = <3300000>;
       };
 
+     reserved_memory: reserved-memory {
+             #address-cells = <2>;
+             #size-cells = <2>;
+             ranges;
+
+             scp_mem_reserved: scp_mem_region {
+                     compatible = "shared-dma-pool";
+                     reg = <0 0x50000000 0 0x2900000>;
+                     no-map;
+             };
+     };
+
       max98357a: codec0 {
               compatible = "maxim,max98357a";
               sdmode-gpios = <&pio 175 0>;
arch/arm64/boot/dts/mediatek/mt8183.dtsi +36 -0
index 102105871db2..8f77eea6df27 100644
@@ -8,6 +8,7 @@
   #include <dt-bindings/clock/mt8183-clk.h>
   #include <dt-bindings/interrupt-controller/arm-gic.h>
   #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/memory/mt8183-larb-port.h>
   #include <dt-bindings/reset-controller/mt8183-resets.h>
   #include <dt-bindings/phy/phy.h>
   #include "mt8183-pinfunc.h"
@@ -339,6 +340,25 @@ pwrap: pwrap@1000d000 {
                       clock-names = "spi", "wrap";
               };
 
+             iommu: iommu@10205000 {
+                     compatible = "mediatek,mt8183-m4u";
+                     reg = <0 0x10205000 0 0x1000>;
+                     interrupts = <GIC_SPI 166 IRQ_TYPE_LEVEL_LOW>;
+                     #iommu-cells = <1>;
+             };
+
+             scp: scp@10500000 {
+                     compatible = "mediatek,mt8183-scp";
+                     reg = <0 0x10500000 0 0x80000>,
+                           <0 0x105c0000 0 0x19080>;
+                     reg-names = "sram", "cfg";
+                     interrupts = <GIC_SPI 174 IRQ_TYPE_LEVEL_HIGH>;
+                     clocks = <&infracfg CLK_INFRA_SCPSYS>;
+                     clock-names = "main";
+                     memory-region = <&scp_mem_reserved>;
+                     status = "disabled";
+             };
+
               systimer: timer@10017000 {
                       compatible = "mediatek,mt8183-timer",
                                    "mediatek,mt6765-timer";
@@ -772,6 +792,22 @@ vencsys: syscon@17000000 {
                       #clock-cells = <1>;
               };
 
+             vcodec_enc: vcodec@17020000 {
+                     compatible = "mediatek,mt8183-vcodec-enc";
+                     reg = <0 0x17020000 0 0x1000>;
+                     interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_LOW>;
+                     iommus = <&iommu M4U_PORT_VENC_REC>,
+                              <&iommu M4U_PORT_VENC_BSDMA>,
+                              <&iommu M4U_PORT_VENC_RD_COMV>,
+                              <&iommu M4U_PORT_VENC_CUR_LUMA>,
+                              <&iommu M4U_PORT_VENC_CUR_CHROMA>,
+                              <&iommu M4U_PORT_VENC_REF_LUMA>,
+                              <&iommu M4U_PORT_VENC_REF_CHROMA>;
+                     mediatek,scp = <&scp>;
+                     clocks = <&vencsys CLK_VENC_VENC>;
+                     clock-names = "MT_CG_VENC";
+             };
+
               ipu_conn: syscon@19000000 {
                       compatible = "mediatek,mt8183-ipu_conn", "syscon";
                       reg = <0 0x19000000 0 0x1000>;
#16 lore raw

Re: [PATCH v4 09/17] arm64: dts: mt8183: add encoder node

Hi Matthias,

Quoted 24 lines · Matthias Brugger

Hi Alexandre,

Quoted 11 lines · Alexandre Courbot
Quoted 10 lines · Matthias Brugger
Quoted 2 lines · Alexandre Courbot

Now that the MT8183 encoder driver is ready, add its DT node. Also pull the iommu and scp ones, which the encoder depends upon.

Please don't do that. Instead of pulling in other DT nodes, it would be handy to get a reference of the series this is based on.

Quoted 8 lines
Quoted 1 line

Let me try to hunt them down now :)

Sorry, I'm not sure to understand - do you mean each node should come with its own patch? Or that all the code should be merged before sending these nodes? The rest of this series should land into the media tree soon, if you prefer I can resend this patch separately once that happens.

Quoted 7 lines

What I'm talking about is the case when you send a series that's based on another one and the latter is not yet accepted in Torvalds tree. In that case it helps to point to the series you expect to be included as well.

In this case the SCP series was merged long time ago, but I missed the DTS change. It would have been good if you would have added that information in your series, instead of directly pulling in the SCP node.

Sorry about that, actually I was not even aware of this patch (or maybe I just forgot about it due to its date).

Quoted 8 lines

For the iommu node: I understand that there was never a patch adding the node (at least I wasn't able to find one). So I'd prefer to have it send as a separate patch of this series.

Regarding this series now. If you want just resend the two DTS patches (iommu and vcodec_enc) once the rest of this series got accpeted. If for any other reason you have to send a v5, then feel free to include both in v5.

Absolutely. I will wait until the patches land into the media tree and send you two DT-only patches.

Thanks for the explanation!

Quoted 124 lines

Hope I explained myself now :)

Regards,
Matthias

Quoted 118 lines
Quoted 118 lines

Regards,
Matthias

Quoted 114 lines
---
   arch/arm64/boot/dts/mediatek/mt8183-evb.dts   | 10 ++++++
   .../arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 12 +++++++
   arch/arm64/boot/dts/mediatek/mt8183.dtsi      | 36 +++++++++++++++++++
   3 files changed, 58 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183-evb.dts +10 -0
index ae405bd8f06b..9e77b420eee8 100644
@@ -25,6 +25,16 @@ memory@40000000 {
       chosen {
               stdout-path = "serial0:921600n8";
       };
+     reserved-memory {
+             #address-cells = <2>;
+             #size-cells = <2>;
+             ranges;
+             scp_mem_reserved: scp_mem_region {
+                     compatible = "shared-dma-pool";
+                     reg = <0 0x50000000 0 0x2900000>;
+                     no-map;
+             };
+     };
   };
 
   &auxadc {
arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi +12 -0
index f0a070535b34..3c763be658da 100644
@@ -90,6 +90,18 @@ pp3300_alw: regulator6 {
               regulator-max-microvolt = <3300000>;
       };
 
+     reserved_memory: reserved-memory {
+             #address-cells = <2>;
+             #size-cells = <2>;
+             ranges;
+
+             scp_mem_reserved: scp_mem_region {
+                     compatible = "shared-dma-pool";
+                     reg = <0 0x50000000 0 0x2900000>;
+                     no-map;
+             };
+     };
+
       max98357a: codec0 {
               compatible = "maxim,max98357a";
               sdmode-gpios = <&pio 175 0>;
arch/arm64/boot/dts/mediatek/mt8183.dtsi +36 -0
index 102105871db2..8f77eea6df27 100644
@@ -8,6 +8,7 @@
   #include <dt-bindings/clock/mt8183-clk.h>
   #include <dt-bindings/interrupt-controller/arm-gic.h>
   #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/memory/mt8183-larb-port.h>
   #include <dt-bindings/reset-controller/mt8183-resets.h>
   #include <dt-bindings/phy/phy.h>
   #include "mt8183-pinfunc.h"
@@ -339,6 +340,25 @@ pwrap: pwrap@1000d000 {
                       clock-names = "spi", "wrap";
               };
 
+             iommu: iommu@10205000 {
+                     compatible = "mediatek,mt8183-m4u";
+                     reg = <0 0x10205000 0 0x1000>;
+                     interrupts = <GIC_SPI 166 IRQ_TYPE_LEVEL_LOW>;
+                     #iommu-cells = <1>;
+             };
+
+             scp: scp@10500000 {
+                     compatible = "mediatek,mt8183-scp";
+                     reg = <0 0x10500000 0 0x80000>,
+                           <0 0x105c0000 0 0x19080>;
+                     reg-names = "sram", "cfg";
+                     interrupts = <GIC_SPI 174 IRQ_TYPE_LEVEL_HIGH>;
+                     clocks = <&infracfg CLK_INFRA_SCPSYS>;
+                     clock-names = "main";
+                     memory-region = <&scp_mem_reserved>;
+                     status = "disabled";
+             };
+
               systimer: timer@10017000 {
                       compatible = "mediatek,mt8183-timer",
                                    "mediatek,mt6765-timer";
@@ -772,6 +792,22 @@ vencsys: syscon@17000000 {
                       #clock-cells = <1>;
               };
 
+             vcodec_enc: vcodec@17020000 {
+                     compatible = "mediatek,mt8183-vcodec-enc";
+                     reg = <0 0x17020000 0 0x1000>;
+                     interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_LOW>;
+                     iommus = <&iommu M4U_PORT_VENC_REC>,
+                              <&iommu M4U_PORT_VENC_BSDMA>,
+                              <&iommu M4U_PORT_VENC_RD_COMV>,
+                              <&iommu M4U_PORT_VENC_CUR_LUMA>,
+                              <&iommu M4U_PORT_VENC_CUR_CHROMA>,
+                              <&iommu M4U_PORT_VENC_REF_LUMA>,
+                              <&iommu M4U_PORT_VENC_REF_CHROMA>;
+                     mediatek,scp = <&scp>;
+                     clocks = <&vencsys CLK_VENC_VENC>;
+                     clock-names = "MT_CG_VENC";
+             };
+
               ipu_conn: syscon@19000000 {
                       compatible = "mediatek,mt8183-ipu_conn", "syscon";
                       reg = <0 0x19000000 0 0x1000>;
#17 lore raw

PATCH v4 10/17 media: mtk-vcodec: add support for MT8183 encoder

In reply to Alexandre Courbot

From: Yunfei Dong <[email protected]>

Now that all the supporting blocks are present, enable encoder for MT8183.

---
 .../platform/mtk-vcodec/mtk_vcodec_drv.h      |  1 +
 .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c  | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+)
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +1 -0
index ba4045d64212..3dd010cba23e 100644
@@ -302,6 +302,7 @@ struct mtk_vcodec_ctx {
 
 enum mtk_chip {
 	MTK_MT8173,
+	MTK_MT8183,
 };
 
 /**
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +22 -0
index 569698f63515..d6438cb4eead 100644
@@ -62,6 +62,14 @@ static const struct mtk_video_fmt mtk_video_formats_capture_mt8173[] =  {
 	},
 };
 
+static const struct mtk_video_fmt mtk_video_formats_capture_mt8183[] =  {
+	{
+		.fourcc = V4L2_PIX_FMT_H264,
+		.type = MTK_FMT_ENC,
+		.num_planes = 1,
+	},
+};
+
 /* Wake up context wait_queue */
 static void wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int reason)
 {
@@ -430,8 +438,22 @@ static const struct mtk_vcodec_enc_pdata mt8173_pdata = {
 	.max_bitrate = 4000000,
 };
 
+static const struct mtk_vcodec_enc_pdata mt8183_pdata = {
+	.chip = MTK_MT8183,
+	.has_lt_irq = false,
+	.uses_ext = true,
+	.capture_formats = mtk_video_formats_capture_mt8183,
+	.num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8183),
+	/* MT8183 supports the same output formats as MT8173 */
+	.output_formats = mtk_video_formats_output_mt8173,
+	.num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
+	.min_bitrate = 64,
+	.max_bitrate = 40000000,
+};
+
 static const struct of_device_id mtk_vcodec_enc_match[] = {
 	{.compatible = "mediatek,mt8173-vcodec-enc", .data = &mt8173_pdata},
+	{.compatible = "mediatek,mt8183-vcodec-enc", .data = &mt8183_pdata},
 	{},
 };
 MODULE_DEVICE_TABLE(of, mtk_vcodec_enc_match);
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#18 lore raw

PATCH v4 11/17 Revert "media: mtk-vcodec: Remove extra area allocation in an input buffer on encoding"

In reply to Alexandre Courbot

This reverts commit 81735ecb62f882853a37a8c157407ec4aed44fd0.

The hardware needs data to follow the previous alignment, so this extra space was not superfluous after all. Besides, this also made v4l2-compliance's G_FMT and S_FMT tests regress.

---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +6 -3
index 05743a745a11..f2ba19c32400 100644
@@ -299,12 +299,14 @@ static int vidioc_try_fmt(struct v4l2_format *f,
 
 		pix_fmt_mp->num_planes = fmt->num_planes;
 		pix_fmt_mp->plane_fmt[0].sizeimage =
-			pix_fmt_mp->width * pix_fmt_mp->height;
+				pix_fmt_mp->width * pix_fmt_mp->height +
+				((ALIGN(pix_fmt_mp->width, 16) * 2) * 16);
 		pix_fmt_mp->plane_fmt[0].bytesperline = pix_fmt_mp->width;
 
 		if (pix_fmt_mp->num_planes == 2) {
 			pix_fmt_mp->plane_fmt[1].sizeimage =
-				(pix_fmt_mp->width * pix_fmt_mp->height) / 2;
+				(pix_fmt_mp->width * pix_fmt_mp->height) / 2 +
+				(ALIGN(pix_fmt_mp->width, 16) * 16);
 			pix_fmt_mp->plane_fmt[2].sizeimage = 0;
 			pix_fmt_mp->plane_fmt[1].bytesperline =
 							pix_fmt_mp->width;
@@ -312,7 +314,8 @@ static int vidioc_try_fmt(struct v4l2_format *f,
 		} else if (pix_fmt_mp->num_planes == 3) {
 			pix_fmt_mp->plane_fmt[1].sizeimage =
 			pix_fmt_mp->plane_fmt[2].sizeimage =
-				(pix_fmt_mp->width * pix_fmt_mp->height) / 4;
+				(pix_fmt_mp->width * pix_fmt_mp->height) / 4 +
+				((ALIGN(pix_fmt_mp->width, 16) / 2) * 16);
 			pix_fmt_mp->plane_fmt[1].bytesperline =
 				pix_fmt_mp->plane_fmt[2].bytesperline =
 				pix_fmt_mp->width / 2;
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#19 lore raw

PATCH v4 12/17 media: mtk-vcodec: venc support MIN_OUTPUT_BUFFERS control

In reply to Alexandre Courbot

This control is required by v4l2-compliance for encoders. A value of 1 should be suitable for all scenarios.

---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +2 -0
index f2ba19c32400..f833aee4a06f 100644
@@ -1206,6 +1206,8 @@ int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx *ctx)
 
 	v4l2_ctrl_handler_init(handler, MTK_MAX_CTRLS_HINT);
 
+	v4l2_ctrl_new_std(handler, ops, V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
+			  1, 1, 1, 1);
 	v4l2_ctrl_new_std(handler, ops, V4L2_CID_MPEG_VIDEO_BITRATE,
 			  ctx->dev->venc_pdata->min_bitrate,
 			  ctx->dev->venc_pdata->max_bitrate, 1, 4000000);
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#20 lore raw

PATCH v4 13/17 media: mtk-vcodec: venc: set OUTPUT buffers field to V4L2_FIELD_NONE

In reply to Alexandre Courbot

A default value of 0 means V4L2_FIELD_ANY, which is not correct. Reported by v4l2-compliance.

---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +9 -0
index f833aee4a06f..1a981d842c19 100644
@@ -893,8 +893,17 @@ static void vb2ops_venc_stop_streaming(struct vb2_queue *q)
 	ctx->state = MTK_STATE_FREE;
 }
 
+static int vb2ops_venc_buf_out_validate(struct vb2_buffer *vb)
+{
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+
+	vbuf->field = V4L2_FIELD_NONE;
+	return 0;
+}
+
 static const struct vb2_ops mtk_venc_vb2_ops = {
 	.queue_setup		= vb2ops_venc_queue_setup,
+	.buf_out_validate	= vb2ops_venc_buf_out_validate,
 	.buf_prepare		= vb2ops_venc_buf_prepare,
 	.buf_queue		= vb2ops_venc_buf_queue,
 	.wait_prepare		= vb2_ops_wait_prepare,
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#21 lore raw

PATCH v4 14/17 media: mtk-vcodec: venc: use platform data for ENUM_FRAMESIZES

In reply to Alexandre Courbot

vidioc_enum_framesizes() assumes that all encoders support H.264 and VP8, which is not necessarily true and requires to duplicate information about the supported codecs which is already stored in the platform data.

Fix this by referring to the platform data to find out whether a given format is supported. Since the supported sizes are all the same regardless of the format, we can then return a copy of a static value if the format is supported.

---
 .../platform/mtk-vcodec/mtk_vcodec_enc.c      | 24 ++++++++-----------
 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +10 -14
index 1a981d842c19..f8d4fbe927f9 100644
@@ -26,17 +26,9 @@
 
 static void mtk_venc_worker(struct work_struct *work);
 
-static const struct mtk_codec_framesizes mtk_venc_framesizes[] = {
-	{
-		.fourcc	= V4L2_PIX_FMT_H264,
-		.stepwise = { MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
-			      MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16 },
-	},
-	{
-		.fourcc = V4L2_PIX_FMT_VP8,
-		.stepwise = { MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
-			      MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16 },
-	},
+static const struct v4l2_frmsize_stepwise mtk_venc_framesizes = {
+	MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
+	MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16,
 };
 
 #define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_venc_framesizes)
@@ -134,17 +126,21 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f,
 static int vidioc_enum_framesizes(struct file *file, void *fh,
 				  struct v4l2_frmsizeenum *fsize)
 {
+	const struct mtk_vcodec_enc_pdata *pdata =
+		fh_to_ctx(fh)->dev->venc_pdata;
 	int i = 0;
 
 	if (fsize->index != 0)
 		return -EINVAL;
 
-	for (i = 0; i < NUM_SUPPORTED_FRAMESIZE; ++i) {
-		if (fsize->pixel_format != mtk_venc_framesizes[i].fourcc)
+	for (i = 0; i < pdata->num_capture_formats; ++i) {
+		const struct mtk_video_fmt *fmt = &pdata->capture_formats[i];
+
+		if (fsize->pixel_format != fmt->fourcc)
 			continue;
 
 		fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
-		fsize->stepwise = mtk_venc_framesizes[i].stepwise;
+		fsize->stepwise = mtk_venc_framesizes;
 		return 0;
 	}
 
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Acked-by on v4 14/17
#22 lore raw

Re: [PATCH v4 14/17] media: mtk-vcodec: venc: use platform data for ENUM_FRAMESIZES

Quoted 9 lines · Alexandre Courbot

vidioc_enum_framesizes() assumes that all encoders support H.264 and VP8, which is not necessarily true and requires to duplicate information about the supported codecs which is already stored in the platform data.

Fix this by referring to the platform data to find out whether a given format is supported. Since the supported sizes are all the same regardless of the format, we can then return a copy of a static value if the format is supported.

Quoted 55 lines
---
 .../platform/mtk-vcodec/mtk_vcodec_enc.c      | 24 ++++++++-----------
 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +10 -14
index 1a981d842c19..f8d4fbe927f9 100644
@@ -26,17 +26,9 @@
 
 static void mtk_venc_worker(struct work_struct *work);
 
-static const struct mtk_codec_framesizes mtk_venc_framesizes[] = {
-	{
-		.fourcc	= V4L2_PIX_FMT_H264,
-		.stepwise = { MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
-			      MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16 },
-	},
-	{
-		.fourcc = V4L2_PIX_FMT_VP8,
-		.stepwise = { MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
-			      MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16 },
-	},
+static const struct v4l2_frmsize_stepwise mtk_venc_framesizes = {
+	MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
+	MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16,
 };
 
 #define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_venc_framesizes)
@@ -134,17 +126,21 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f,
 static int vidioc_enum_framesizes(struct file *file, void *fh,
 				  struct v4l2_frmsizeenum *fsize)
 {
+	const struct mtk_vcodec_enc_pdata *pdata =
+		fh_to_ctx(fh)->dev->venc_pdata;
 	int i = 0;
 
 	if (fsize->index != 0)
 		return -EINVAL;
 
-	for (i = 0; i < NUM_SUPPORTED_FRAMESIZE; ++i) {
-		if (fsize->pixel_format != mtk_venc_framesizes[i].fourcc)
+	for (i = 0; i < pdata->num_capture_formats; ++i) {
+		const struct mtk_video_fmt *fmt = &pdata->capture_formats[i];
+
+		if (fsize->pixel_format != fmt->fourcc)
 			continue;
 
 		fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
-		fsize->stepwise = mtk_venc_framesizes[i].stepwise;
+		fsize->stepwise = mtk_venc_framesizes;
 		return 0;
 	}
 
#23 lore raw

PATCH v4 15/17 media: mtk-vcodec: venc: support ENUM_FRAMESIZES on OUTPUT formats

In reply to Alexandre Courbot

v4l2-compliance requires ENUM_FRAMESIZES to support OUTPUT formats. Reuse mtk_venc_find_format() to make sure both queues are considered when serving an ENUM_FRAMESIZES.

---
 .../platform/mtk-vcodec/mtk_vcodec_enc.c      | 71 +++++++++----------
 1 file changed, 33 insertions(+), 38 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +33 -38
index f8d4fbe927f9..1b79185cf922 100644
@@ -123,28 +123,44 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f,
 	return 0;
 }
 
+static const struct mtk_video_fmt *mtk_venc_find_format(u32 fourcc,
+	const struct mtk_vcodec_enc_pdata *pdata)
+{
+	const struct mtk_video_fmt *fmt;
+	unsigned int k;
+
+	for (k = 0; k < pdata->num_capture_formats; k++) {
+		fmt = &pdata->capture_formats[k];
+		if (fmt->fourcc == fourcc)
+			return fmt;
+	}
+
+	for (k = 0; k < pdata->num_output_formats; k++) {
+		fmt = &pdata->output_formats[k];
+		if (fmt->fourcc == fourcc)
+			return fmt;
+	}
+
+	return NULL;
+}
+
 static int vidioc_enum_framesizes(struct file *file, void *fh,
 				  struct v4l2_frmsizeenum *fsize)
 {
-	const struct mtk_vcodec_enc_pdata *pdata =
-		fh_to_ctx(fh)->dev->venc_pdata;
-	int i = 0;
+	const struct mtk_video_fmt *fmt;
 
 	if (fsize->index != 0)
 		return -EINVAL;
 
-	for (i = 0; i < pdata->num_capture_formats; ++i) {
-		const struct mtk_video_fmt *fmt = &pdata->capture_formats[i];
+	fmt = mtk_venc_find_format(fsize->pixel_format,
+				   fh_to_ctx(fh)->dev->venc_pdata);
+	if (!fmt)
+		return -EINVAL;
 
-		if (fsize->pixel_format != fmt->fourcc)
-			continue;
+	fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
+	fsize->stepwise = mtk_venc_framesizes;
 
-		fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
-		fsize->stepwise = mtk_venc_framesizes;
-		return 0;
-	}
-
-	return -EINVAL;
+	return 0;
 }
 
 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
@@ -222,27 +238,6 @@ static struct mtk_q_data *mtk_venc_get_q_data(struct mtk_vcodec_ctx *ctx,
 	return &ctx->q_data[MTK_Q_DATA_DST];
 }
 
-static const struct mtk_video_fmt *mtk_venc_find_format(struct v4l2_format *f,
-	const struct mtk_vcodec_enc_pdata *pdata)
-{
-	const struct mtk_video_fmt *fmt;
-	unsigned int k;
-
-	for (k = 0; k < pdata->num_capture_formats; k++) {
-		fmt = &pdata->capture_formats[k];
-		if (fmt->fourcc == f->fmt.pix.pixelformat)
-			return fmt;
-	}
-
-	for (k = 0; k < pdata->num_output_formats; k++) {
-		fmt = &pdata->output_formats[k];
-		if (fmt->fourcc == f->fmt.pix.pixelformat)
-			return fmt;
-	}
-
-	return NULL;
-}
-
 /* V4L2 specification suggests the driver corrects the format struct if any of
  * the dimensions is unsupported
  */
@@ -403,7 +398,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, void *priv,
 		return -EINVAL;
 	}
 
-	fmt = mtk_venc_find_format(f, pdata);
+	fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
 	if (!fmt) {
 		fmt = &ctx->dev->venc_pdata->capture_formats[0];
 		f->fmt.pix.pixelformat = fmt->fourcc;
@@ -467,7 +462,7 @@ static int vidioc_venc_s_fmt_out(struct file *file, void *priv,
 		return -EINVAL;
 	}
 
-	fmt = mtk_venc_find_format(f, pdata);
+	fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
 	if (!fmt) {
 		fmt = &ctx->dev->venc_pdata->output_formats[0];
 		f->fmt.pix.pixelformat = fmt->fourcc;
@@ -550,7 +545,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
 	struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
 	const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
 
-	fmt = mtk_venc_find_format(f, pdata);
+	fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
 	if (!fmt) {
 		fmt = &ctx->dev->venc_pdata->capture_formats[0];
 		f->fmt.pix.pixelformat = fmt->fourcc;
@@ -570,7 +565,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
 	struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
 	const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
 
-	fmt = mtk_venc_find_format(f, pdata);
+	fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
 	if (!fmt) {
 		fmt = &ctx->dev->venc_pdata->output_formats[0];
 		f->fmt.pix.pixelformat = fmt->fourcc;
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Acked-by on v4 15/17
#24 lore raw

Re: [PATCH v4 15/17] media: mtk-vcodec: venc: support ENUM_FRAMESIZES on OUTPUT formats

Quoted 4 lines · Alexandre Courbot

v4l2-compliance requires ENUM_FRAMESIZES to support OUTPUT formats. Reuse mtk_venc_find_format() to make sure both queues are considered when serving an ENUM_FRAMESIZES.

Quoted 131 lines
---
 .../platform/mtk-vcodec/mtk_vcodec_enc.c      | 71 +++++++++----------
 1 file changed, 33 insertions(+), 38 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +33 -38
index f8d4fbe927f9..1b79185cf922 100644
@@ -123,28 +123,44 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f,
 	return 0;
 }
 
+static const struct mtk_video_fmt *mtk_venc_find_format(u32 fourcc,
+	const struct mtk_vcodec_enc_pdata *pdata)
+{
+	const struct mtk_video_fmt *fmt;
+	unsigned int k;
+
+	for (k = 0; k < pdata->num_capture_formats; k++) {
+		fmt = &pdata->capture_formats[k];
+		if (fmt->fourcc == fourcc)
+			return fmt;
+	}
+
+	for (k = 0; k < pdata->num_output_formats; k++) {
+		fmt = &pdata->output_formats[k];
+		if (fmt->fourcc == fourcc)
+			return fmt;
+	}
+
+	return NULL;
+}
+
 static int vidioc_enum_framesizes(struct file *file, void *fh,
 				  struct v4l2_frmsizeenum *fsize)
 {
-	const struct mtk_vcodec_enc_pdata *pdata =
-		fh_to_ctx(fh)->dev->venc_pdata;
-	int i = 0;
+	const struct mtk_video_fmt *fmt;
 
 	if (fsize->index != 0)
 		return -EINVAL;
 
-	for (i = 0; i < pdata->num_capture_formats; ++i) {
-		const struct mtk_video_fmt *fmt = &pdata->capture_formats[i];
+	fmt = mtk_venc_find_format(fsize->pixel_format,
+				   fh_to_ctx(fh)->dev->venc_pdata);
+	if (!fmt)
+		return -EINVAL;
 
-		if (fsize->pixel_format != fmt->fourcc)
-			continue;
+	fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
+	fsize->stepwise = mtk_venc_framesizes;
 
-		fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
-		fsize->stepwise = mtk_venc_framesizes;
-		return 0;
-	}
-
-	return -EINVAL;
+	return 0;
 }
 
 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
@@ -222,27 +238,6 @@ static struct mtk_q_data *mtk_venc_get_q_data(struct mtk_vcodec_ctx *ctx,
 	return &ctx->q_data[MTK_Q_DATA_DST];
 }
 
-static const struct mtk_video_fmt *mtk_venc_find_format(struct v4l2_format *f,
-	const struct mtk_vcodec_enc_pdata *pdata)
-{
-	const struct mtk_video_fmt *fmt;
-	unsigned int k;
-
-	for (k = 0; k < pdata->num_capture_formats; k++) {
-		fmt = &pdata->capture_formats[k];
-		if (fmt->fourcc == f->fmt.pix.pixelformat)
-			return fmt;
-	}
-
-	for (k = 0; k < pdata->num_output_formats; k++) {
-		fmt = &pdata->output_formats[k];
-		if (fmt->fourcc == f->fmt.pix.pixelformat)
-			return fmt;
-	}
-
-	return NULL;
-}
-
 /* V4L2 specification suggests the driver corrects the format struct if any of
  * the dimensions is unsupported
  */
@@ -403,7 +398,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, void *priv,
 		return -EINVAL;
 	}
 
-	fmt = mtk_venc_find_format(f, pdata);
+	fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
 	if (!fmt) {
 		fmt = &ctx->dev->venc_pdata->capture_formats[0];
 		f->fmt.pix.pixelformat = fmt->fourcc;
@@ -467,7 +462,7 @@ static int vidioc_venc_s_fmt_out(struct file *file, void *priv,
 		return -EINVAL;
 	}
 
-	fmt = mtk_venc_find_format(f, pdata);
+	fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
 	if (!fmt) {
 		fmt = &ctx->dev->venc_pdata->output_formats[0];
 		f->fmt.pix.pixelformat = fmt->fourcc;
@@ -550,7 +545,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
 	struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
 	const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
 
-	fmt = mtk_venc_find_format(f, pdata);
+	fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
 	if (!fmt) {
 		fmt = &ctx->dev->venc_pdata->capture_formats[0];
 		f->fmt.pix.pixelformat = fmt->fourcc;
@@ -570,7 +565,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
 	struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
 	const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
 
-	fmt = mtk_venc_find_format(f, pdata);
+	fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
 	if (!fmt) {
 		fmt = &ctx->dev->venc_pdata->output_formats[0];
 		f->fmt.pix.pixelformat = fmt->fourcc;
#25 lore raw

PATCH v4 16/17 media: mtk-vcodec: venc: set default time per frame

In reply to Alexandre Courbot

The time per frame was left initialized to 0/0, which make the driver fail v4l2-compliance, and also leaves it potentially exposed to doing a division by zero.

---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +5 -0
index 1b79185cf922..09baac2dbc36 100644
@@ -24,6 +24,9 @@
 #define DFT_CFG_HEIGHT	MTK_VENC_MIN_H
 #define MTK_MAX_CTRLS_HINT	20
 
+#define MTK_DEFAULT_FRAMERATE_NUM 1001
+#define MTK_DEFAULT_FRAMERATE_DENOM 30000
+
 static void mtk_venc_worker(struct work_struct *work);
 
 static const struct v4l2_frmsize_stepwise mtk_venc_framesizes = {
@@ -1197,6 +1200,8 @@ void mtk_vcodec_enc_set_default_params(struct mtk_vcodec_ctx *ctx)
 		DFT_CFG_WIDTH * DFT_CFG_HEIGHT;
 	ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] = 0;
 
+	ctx->enc_params.framerate_num = MTK_DEFAULT_FRAMERATE_NUM;
+	ctx->enc_params.framerate_denom = MTK_DEFAULT_FRAMERATE_DENOM;
 }
 
 int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx *ctx)
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
Acked-by on v4 16/17
#26 lore raw

Re: [PATCH v4 16/17] media: mtk-vcodec: venc: set default time per frame

Quoted 4 lines · Alexandre Courbot

The time per frame was left initialized to 0/0, which make the driver fail v4l2-compliance, and also leaves it potentially exposed to doing a division by zero.

Quoted 28 lines
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +5 -0
index 1b79185cf922..09baac2dbc36 100644
@@ -24,6 +24,9 @@
 #define DFT_CFG_HEIGHT	MTK_VENC_MIN_H
 #define MTK_MAX_CTRLS_HINT	20
 
+#define MTK_DEFAULT_FRAMERATE_NUM 1001
+#define MTK_DEFAULT_FRAMERATE_DENOM 30000
+
 static void mtk_venc_worker(struct work_struct *work);
 
 static const struct v4l2_frmsize_stepwise mtk_venc_framesizes = {
@@ -1197,6 +1200,8 @@ void mtk_vcodec_enc_set_default_params(struct mtk_vcodec_ctx *ctx)
 		DFT_CFG_WIDTH * DFT_CFG_HEIGHT;
 	ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] = 0;
 
+	ctx->enc_params.framerate_num = MTK_DEFAULT_FRAMERATE_NUM;
+	ctx->enc_params.framerate_denom = MTK_DEFAULT_FRAMERATE_DENOM;
 }
 
 int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx *ctx)
#27 lore raw

PATCH v4 17/17 media: mtk-vcodec: venc: fix invalid time per frame in S_PARM

In reply to Alexandre Courbot

v4l2-compliance expects the driver to adjust the time per frame if it is invalid (numerator or denominator set to 0). Adjust it to the default value in these cases.

---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +8 -4
index 09baac2dbc36..82b04714f750 100644
@@ -200,14 +200,18 @@ static int vidioc_venc_s_parm(struct file *file, void *priv,
 			      struct v4l2_streamparm *a)
 {
 	struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+	struct v4l2_fract *timeperframe = &a->parm.output.timeperframe;
 
 	if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		return -EINVAL;
 
-	ctx->enc_params.framerate_num =
-			a->parm.output.timeperframe.denominator;
-	ctx->enc_params.framerate_denom =
-			a->parm.output.timeperframe.numerator;
+	if (timeperframe->numerator == 0 || timeperframe->denominator == 0) {
+		timeperframe->numerator = MTK_DEFAULT_FRAMERATE_NUM;
+		timeperframe->denominator = MTK_DEFAULT_FRAMERATE_DENOM;
+	}
+
+	ctx->enc_params.framerate_num = timeperframe->denominator;
+	ctx->enc_params.framerate_denom = timeperframe->numerator;
 	ctx->param_change |= MTK_ENCODE_PARAM_FRAMERATE;
 
 	a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
Signature · 7 lines
2.28.0.297.g1956fa8f8d-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Acked-by on v4 17/17
#28 lore raw

Re: [PATCH v4 17/17] media: mtk-vcodec: venc: fix invalid time per frame in S_PARM

Quoted 4 lines · Alexandre Courbot

v4l2-compliance expects the driver to adjust the time per frame if it is invalid (numerator or denominator set to 0). Adjust it to the default value in these cases.

Quoted 32 lines
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +8 -4
index 09baac2dbc36..82b04714f750 100644
@@ -200,14 +200,18 @@ static int vidioc_venc_s_parm(struct file *file, void *priv,
 			      struct v4l2_streamparm *a)
 {
 	struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+	struct v4l2_fract *timeperframe = &a->parm.output.timeperframe;
 
 	if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		return -EINVAL;
 
-	ctx->enc_params.framerate_num =
-			a->parm.output.timeperframe.denominator;
-	ctx->enc_params.framerate_denom =
-			a->parm.output.timeperframe.numerator;
+	if (timeperframe->numerator == 0 || timeperframe->denominator == 0) {
+		timeperframe->numerator = MTK_DEFAULT_FRAMERATE_NUM;
+		timeperframe->denominator = MTK_DEFAULT_FRAMERATE_DENOM;
+	}
+
+	ctx->enc_params.framerate_num = timeperframe->denominator;
+	ctx->enc_params.framerate_denom = timeperframe->numerator;
 	ctx->param_change |= MTK_ENCODE_PARAM_FRAMERATE;
 
 	a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;