[PATCH v2, 8/9] media: mtk-jpegenc: Generalize jpegenc HW operations interfaces

kyrie.wu kyrie.wu at mediatek.com
Wed Jun 30 00:27:58 PDT 2021


Generalizes jpegenc select/deselect HW and set params interfaces.

Signed-off-by: kyrie.wu <kyrie.wu at mediatek.com>
---
 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 46 +++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
index bf519ba..0143baf8 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -939,6 +939,52 @@ static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx,
 	return 0;
 }
 
+static int mtk_jpeg_select_hw(struct mtk_jpeg_ctx *ctx)
+{
+	int hw_id = -1;
+	int i;
+	unsigned long flags;
+	struct mtk_jpeg_dev *jpeg = ctx->jpeg, *comp_jpeg = NULL;
+
+	spin_lock_irqsave(&jpeg->hw_lock, flags);
+	for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) {
+		comp_jpeg = jpeg->hw_dev[i];
+		if (comp_jpeg->hw_state == MTK_JPEG_HW_IDLE) {
+			hw_id = i;
+			comp_jpeg->hw_state = MTK_JPEG_HW_BUSY;
+			break;
+		}
+	}
+	spin_unlock_irqrestore(&jpeg->hw_lock, flags);
+
+	return hw_id;
+}
+
+static int mtk_jpeg_deselect_hw(struct mtk_jpeg_dev *jpeg, int hw_id)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&jpeg->hw_lock, flags);
+	jpeg->hw_dev[hw_id]->hw_state = MTK_JPEG_HW_IDLE;
+	spin_unlock_irqrestore(&jpeg->hw_lock, flags);
+
+	return 0;
+}
+
+static int mtk_jpeg_set_hw_param(struct mtk_jpeg_ctx *ctx,
+				 int hw_id,
+				 struct vb2_v4l2_buffer *src_buf,
+				 struct vb2_v4l2_buffer *dst_buf)
+{
+	struct mtk_jpeg_dev *jpeg = ctx->jpeg->hw_dev[hw_id];
+
+	jpeg->hw_param.curr_ctx = ctx;
+	jpeg->hw_param.src_buffer = src_buf;
+	jpeg->hw_param.dst_buffer = dst_buf;
+
+	return 0;
+}
+
 static void mtk_jpeg_enc_device_run(void *priv)
 {
 	struct mtk_jpeg_ctx *ctx = priv;
-- 
2.6.4


More information about the Linux-mediatek mailing list