1 // SPDX-License-Identifier: GPL-2.0
2
3 #include "../decoder/mtk_vcodec_dec_drv.h"
4 #include "../encoder/mtk_vcodec_enc_drv.h"
5 #include "mtk_vcodec_fw_priv.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(void * priv,enum mtk_vcodec_fw_use fw_use)56 struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(void *priv, enum mtk_vcodec_fw_use fw_use)
57 {
58 struct mtk_vcodec_fw *fw;
59 struct platform_device *plat_dev;
60 struct mtk_scp *scp;
61
62 if (fw_use == ENCODER) {
63 struct mtk_vcodec_enc_dev *enc_dev = priv;
64
65 plat_dev = enc_dev->plat_dev;
66 } else if (fw_use == DECODER) {
67 struct mtk_vcodec_dec_dev *dec_dev = priv;
68
69 plat_dev = dec_dev->plat_dev;
70 } else {
71 pr_err("Invalid fw_use %d (use a reasonable fw id here)\n", fw_use);
72 return ERR_PTR(-EINVAL);
73 }
74
75 scp = scp_get(plat_dev);
76 if (!scp) {
77 dev_err(&plat_dev->dev, "could not get vdec scp handle");
78 return ERR_PTR(-EPROBE_DEFER);
79 }
80
81 fw = devm_kzalloc(&plat_dev->dev, sizeof(*fw), GFP_KERNEL);
82 if (!fw)
83 return ERR_PTR(-ENOMEM);
84 fw->type = SCP;
85 fw->ops = &mtk_vcodec_rproc_msg;
86 fw->scp = scp;
87
88 return fw;
89 }
90