Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / media / platform / mtk-vcodec / mtk_vcodec_intr.c
bloba3c7a380c9308481256cfd5a97fdfb43050df0dc
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: Tiffany Lin <tiffany.lin@mediatek.com>
5 */
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(struct mtk_vcodec_ctx *ctx, int command,
15 unsigned int timeout_ms)
17 wait_queue_head_t *waitqueue;
18 long timeout_jiff, ret;
19 int status = 0;
21 waitqueue = (wait_queue_head_t *)&ctx->queue;
22 timeout_jiff = msecs_to_jiffies(timeout_ms);
24 ret = wait_event_interruptible_timeout(*waitqueue,
25 ctx->int_cond,
26 timeout_jiff);
28 if (!ret) {
29 status = -1; /* timeout */
30 mtk_v4l2_err("[%d] cmd=%d, ctx->type=%d, wait_event_interruptible_timeout time=%ums out %d %d!",
31 ctx->id, ctx->type, command, timeout_ms,
32 ctx->int_cond, ctx->int_type);
33 } else if (-ERESTARTSYS == ret) {
34 mtk_v4l2_err("[%d] cmd=%d, ctx->type=%d, wait_event_interruptible_timeout interrupted by a signal %d %d",
35 ctx->id, ctx->type, command, ctx->int_cond,
36 ctx->int_type);
37 status = -1;
40 ctx->int_cond = 0;
41 ctx->int_type = 0;
43 return status;
45 EXPORT_SYMBOL(mtk_vcodec_wait_for_done_ctx);