1 // SPDX-License-Identifier: GPL-2.0
3 #include "mtk_vcodec_fw_priv.h"
4 #include "mtk_vcodec_util.h"
5 #include "mtk_vcodec_drv.h"
7 static int mtk_vcodec_vpu_load_firmware(struct mtk_vcodec_fw *fw)
9 return vpu_load_firmware(fw->pdev);
12 static unsigned int mtk_vcodec_vpu_get_vdec_capa(struct mtk_vcodec_fw *fw)
14 return vpu_get_vdec_hw_capa(fw->pdev);
17 static unsigned int mtk_vcodec_vpu_get_venc_capa(struct mtk_vcodec_fw *fw)
19 return vpu_get_venc_hw_capa(fw->pdev);
22 static void *mtk_vcodec_vpu_map_dm_addr(struct mtk_vcodec_fw *fw,
25 return vpu_mapping_dm_addr(fw->pdev, dtcm_dmem_addr);
28 static int mtk_vcodec_vpu_set_ipi_register(struct mtk_vcodec_fw *fw, int id,
29 mtk_vcodec_ipi_handler handler,
30 const char *name, void *priv)
33 * The handler we receive takes a void * as its first argument. We
34 * cannot change this because it needs to be passed down to the rproc
35 * subsystem when SCP is used. VPU takes a const argument, which is
36 * more constrained, so the conversion below is safe.
38 ipi_handler_t handler_const = (ipi_handler_t)handler;
40 return vpu_ipi_register(fw->pdev, id, handler_const, name, priv);
43 static int mtk_vcodec_vpu_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
44 unsigned int len, unsigned int wait)
46 return vpu_ipi_send(fw->pdev, id, buf, len);
49 static void mtk_vcodec_vpu_release(struct mtk_vcodec_fw *fw)
51 put_device(&fw->pdev->dev);
54 static void mtk_vcodec_vpu_reset_handler(void *priv)
56 struct mtk_vcodec_dev *dev = priv;
57 struct mtk_vcodec_ctx *ctx;
59 mtk_v4l2_err("Watchdog timeout!!");
61 mutex_lock(&dev->dev_mutex);
62 list_for_each_entry(ctx, &dev->ctx_list, list) {
63 ctx->state = MTK_STATE_ABORT;
64 mtk_v4l2_debug(0, "[%d] Change to state MTK_STATE_ABORT",
67 mutex_unlock(&dev->dev_mutex);
70 static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = {
71 .load_firmware = mtk_vcodec_vpu_load_firmware,
72 .get_vdec_capa = mtk_vcodec_vpu_get_vdec_capa,
73 .get_venc_capa = mtk_vcodec_vpu_get_venc_capa,
74 .map_dm_addr = mtk_vcodec_vpu_map_dm_addr,
75 .ipi_register = mtk_vcodec_vpu_set_ipi_register,
76 .ipi_send = mtk_vcodec_vpu_ipi_send,
77 .release = mtk_vcodec_vpu_release,
80 struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(struct mtk_vcodec_dev *dev,
81 enum mtk_vcodec_fw_use fw_use)
83 struct platform_device *fw_pdev;
84 struct mtk_vcodec_fw *fw;
97 fw_pdev = vpu_get_plat_device(dev->plat_dev);
99 mtk_v4l2_err("firmware device is not ready");
100 return ERR_PTR(-EINVAL);
102 vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_handler, dev, rst_id);
104 fw = devm_kzalloc(&dev->plat_dev->dev, sizeof(*fw), GFP_KERNEL);
106 return ERR_PTR(-ENOMEM);
108 fw->ops = &mtk_vcodec_vpu_msg;