1 // SPDX-License-Identifier: GPL-2.0
2
3 #include "mtk_vcodec_fw_priv.h"
4 #include "mtk_vcodec_util.h"
5 #include "mtk_vcodec_drv.h"
6
mtk_vcodec_scp_load_firmware(struct mtk_vcodec_fw * fw)7 static int mtk_vcodec_scp_load_firmware(struct mtk_vcodec_fw *fw)
8 {
9 return rproc_boot(scp_get_rproc(fw->scp));
10 }
11
mtk_vcodec_scp_get_vdec_capa(struct mtk_vcodec_fw * fw)12 static unsigned int mtk_vcodec_scp_get_vdec_capa(struct mtk_vcodec_fw *fw)
13 {
14 return scp_get_vdec_hw_capa(fw->scp);
15 }
16
mtk_vcodec_scp_get_venc_capa(struct mtk_vcodec_fw * fw)17 static unsigned int mtk_vcodec_scp_get_venc_capa(struct mtk_vcodec_fw *fw)
18 {
19 return scp_get_venc_hw_capa(fw->scp);
20 }
21
mtk_vcodec_vpu_scp_dm_addr(struct mtk_vcodec_fw * fw,u32 dtcm_dmem_addr)22 static void *mtk_vcodec_vpu_scp_dm_addr(struct mtk_vcodec_fw *fw,
23 u32 dtcm_dmem_addr)
24 {
25 return scp_mapping_dm_addr(fw->scp, dtcm_dmem_addr);
26 }
27
mtk_vcodec_scp_set_ipi_register(struct mtk_vcodec_fw * fw,int id,mtk_vcodec_ipi_handler handler,const char * name,void * priv)28 static int mtk_vcodec_scp_set_ipi_register(struct mtk_vcodec_fw *fw, int id,
29 mtk_vcodec_ipi_handler handler,
30 const char *name, void *priv)
31 {
32 return scp_ipi_register(fw->scp, id, handler, priv);
33 }
34
mtk_vcodec_scp_ipi_send(struct mtk_vcodec_fw * fw,int id,void * buf,unsigned int len,unsigned int wait)35 static int mtk_vcodec_scp_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
36 unsigned int len, unsigned int wait)
37 {
38 return scp_ipi_send(fw->scp, id, buf, len, wait);
39 }
40
mtk_vcodec_scp_release(struct mtk_vcodec_fw * fw)41 static void mtk_vcodec_scp_release(struct mtk_vcodec_fw *fw)
42 {
43 scp_put(fw->scp);
44 }
45
46 static const struct mtk_vcodec_fw_ops mtk_vcodec_rproc_msg = {
47 .load_firmware = mtk_vcodec_scp_load_firmware,
48 .get_vdec_capa = mtk_vcodec_scp_get_vdec_capa,
49 .get_venc_capa = mtk_vcodec_scp_get_venc_capa,
50 .map_dm_addr = mtk_vcodec_vpu_scp_dm_addr,
51 .ipi_register = mtk_vcodec_scp_set_ipi_register,
52 .ipi_send = mtk_vcodec_scp_ipi_send,
53 .release = mtk_vcodec_scp_release,
54 };
55
mtk_vcodec_fw_scp_init(struct mtk_vcodec_dev * dev)56 struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(struct mtk_vcodec_dev *dev)
57 {
58 struct mtk_vcodec_fw *fw;
59 struct mtk_scp *scp;
60
61 scp = scp_get(dev->plat_dev);
62 if (!scp) {
63 mtk_v4l2_err("could not get vdec scp handle");
64 return ERR_PTR(-EPROBE_DEFER);
65 }
66
67 fw = devm_kzalloc(&dev->plat_dev->dev, sizeof(*fw), GFP_KERNEL);
68 fw->type = SCP;
69 fw->ops = &mtk_vcodec_rproc_msg;
70 fw->scp = scp;
71
72 return fw;
73 }
74