1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (c) 2016 MediaTek Inc. 4 * Author: PC Chen <pc.chen@mediatek.com> 5 * Tiffany Lin <tiffany.lin@mediatek.com> 6 */ 7 8 #ifndef _MTK_VCODEC_UTIL_H_ 9 #define _MTK_VCODEC_UTIL_H_ 10 11 #include <linux/types.h> 12 #include <linux/dma-direction.h> 13 14 #define MTK_DBG_VCODEC_STR "[MTK_VCODEC]" 15 #define MTK_DBG_V4L2_STR "[MTK_V4L2]" 16 17 struct mtk_vcodec_mem { 18 size_t size; 19 void *va; 20 dma_addr_t dma_addr; 21 }; 22 23 struct mtk_vcodec_fb { 24 size_t size; 25 dma_addr_t dma_addr; 26 }; 27 28 struct mtk_vcodec_dec_ctx; 29 struct mtk_vcodec_dec_dev; 30 31 #undef pr_fmt 32 #define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__ 33 34 #define mtk_v4l2_err(plat_dev, fmt, args...) \ 35 dev_err(&(plat_dev)->dev, "[MTK_V4L2][ERROR] " fmt "\n", ##args) 36 37 #define mtk_vcodec_err(inst_id, plat_dev, fmt, args...) \ 38 dev_err(&(plat_dev)->dev, "[MTK_VCODEC][ERROR][%d]: " fmt "\n", inst_id, ##args) 39 40 #if defined(CONFIG_DEBUG_FS) 41 extern int mtk_v4l2_dbg_level; 42 extern int mtk_vcodec_dbg; 43 44 #define mtk_v4l2_debug(plat_dev, level, fmt, args...) \ 45 do { \ 46 if (mtk_v4l2_dbg_level >= (level)) \ 47 dev_dbg(&(plat_dev)->dev, "[MTK_V4L2] %s, %d: " fmt "\n", \ 48 __func__, __LINE__, ##args); \ 49 } while (0) 50 51 #define mtk_vcodec_debug(inst_id, plat_dev, fmt, args...) \ 52 do { \ 53 if (mtk_vcodec_dbg) \ 54 dev_dbg(&(plat_dev)->dev, "[MTK_VCODEC][%d]: %s, %d " fmt "\n", \ 55 inst_id, __func__, __LINE__, ##args); \ 56 } while (0) 57 #else 58 #define mtk_v4l2_debug(plat_dev, level, fmt, args...) \ 59 dev_dbg(&(plat_dev)->dev, "[MTK_V4L2]: " fmt "\n", ##args) 60 61 #define mtk_vcodec_debug(inst_id, plat_dev, fmt, args...) \ 62 dev_dbg(&(plat_dev)->dev, "[MTK_VCODEC][%d]: " fmt "\n", inst_id, ##args) 63 #endif 64 65 void __iomem *mtk_vcodec_get_reg_addr(void __iomem **reg_base, unsigned int reg_idx); 66 int mtk_vcodec_write_vdecsys(struct mtk_vcodec_dec_ctx *ctx, unsigned int reg, unsigned int val); 67 int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem); 68 void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem); 69 void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev, 70 struct mtk_vcodec_dec_ctx *ctx, int hw_idx); 71 struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev, 72 unsigned int hw_idx); 73 void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dec_dev *dev, int hw_idx); 74 75 #endif /* _MTK_VCODEC_UTIL_H_ */ 76