1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: Tiffany Lin <tiffany.lin@mediatek.com>
7 #include <linux/errno.h>
8 #include <linux/wait.h>
10 #include "mtk_vcodec_drv.h"
11 #include "mtk_vcodec_intr.h"
12 #include "mtk_vcodec_util.h"
14 int mtk_vcodec_wait_for_done_ctx(void *priv, int command, unsigned int timeout_ms,
17 int instance_type = *((int *)priv);
18 long timeout_jiff, ret;
19 int ctx_id, ctx_type, status = 0;
20 int *ctx_int_cond, *ctx_int_type;
21 wait_queue_head_t *ctx_queue;
22 struct platform_device *pdev;
24 if (instance_type == DECODER) {
25 struct mtk_vcodec_dec_ctx *ctx;
30 ctx_int_cond = ctx->int_cond;
31 ctx_int_type = ctx->int_type;
32 ctx_queue = ctx->queue;
33 pdev = ctx->dev->plat_dev;
35 struct mtk_vcodec_enc_ctx *ctx;
40 ctx_int_cond = ctx->int_cond;
41 ctx_int_type = ctx->int_type;
42 ctx_queue = ctx->queue;
43 pdev = ctx->dev->plat_dev;
46 timeout_jiff = msecs_to_jiffies(timeout_ms);
47 ret = wait_event_interruptible_timeout(ctx_queue[hw_id],
52 status = -1; /* timeout */
53 dev_err(&pdev->dev, "[%d] cmd=%d, type=%d, dec timeout=%ums (%d %d)",
54 ctx_id, command, ctx_type, timeout_ms,
55 ctx_int_cond[hw_id], ctx_int_type[hw_id]);
56 } else if (-ERESTARTSYS == ret) {
58 dev_err(&pdev->dev, "[%d] cmd=%d, type=%d, dec inter fail (%d %d)",
59 ctx_id, command, ctx_type,
60 ctx_int_cond[hw_id], ctx_int_type[hw_id]);
63 ctx_int_cond[hw_id] = 0;
64 ctx_int_type[hw_id] = 0;
68 EXPORT_SYMBOL(mtk_vcodec_wait_for_done_ctx);