1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: Tiffany Lin <tiffany.lin@mediatek.com>
5 */
6 
7 #include <linux/errno.h>
8 #include <linux/wait.h>
9 
10 #include "mtk_vcodec_drv.h"
11 #include "mtk_vcodec_intr.h"
12 #include "mtk_vcodec_util.h"
13 
mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx * ctx,int command,unsigned int timeout_ms,unsigned int hw_id)14 int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx,
15 				 int command, unsigned int timeout_ms,
16 				 unsigned int hw_id)
17 {
18 	long timeout_jiff, ret;
19 	int status = 0;
20 
21 	timeout_jiff = msecs_to_jiffies(timeout_ms);
22 	ret = wait_event_interruptible_timeout(ctx->queue[hw_id],
23 					       ctx->int_cond[hw_id],
24 					       timeout_jiff);
25 
26 	if (!ret) {
27 		status = -1;	/* timeout */
28 		mtk_v4l2_err("[%d] cmd=%d, type=%d, dec timeout=%ums (%d %d)",
29 			     ctx->id, command, ctx->type, timeout_ms,
30 			     ctx->int_cond[hw_id], ctx->int_type[hw_id]);
31 	} else if (-ERESTARTSYS == ret) {
32 		status = -1;
33 		mtk_v4l2_err("[%d] cmd=%d, type=%d, dec inter fail (%d %d)",
34 			     ctx->id, command, ctx->type,
35 			     ctx->int_cond[hw_id], ctx->int_type[hw_id]);
36 	}
37 
38 	ctx->int_cond[hw_id] = 0;
39 	ctx->int_type[hw_id] = 0;
40 
41 	return status;
42 }
43 EXPORT_SYMBOL(mtk_vcodec_wait_for_done_ctx);
44