treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / media / platform / mtk-mdp / mtk_mdp_vpu.c
blob6720d11f50cf67cc311d8cb9faf3cde24d0e68cf
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2015-2016 MediaTek Inc.
4 * Author: Houlong Wei <houlong.wei@mediatek.com>
5 * Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
6 */
8 #include "mtk_mdp_core.h"
9 #include "mtk_mdp_vpu.h"
10 #include "mtk_vpu.h"
13 static inline struct mtk_mdp_ctx *vpu_to_ctx(struct mtk_mdp_vpu *vpu)
15 return container_of(vpu, struct mtk_mdp_ctx, vpu);
18 static void mtk_mdp_vpu_handle_init_ack(struct mdp_ipi_comm_ack *msg)
20 struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)
21 (unsigned long)msg->ap_inst;
23 /* mapping VPU address to kernel virtual address */
24 vpu->vsi = (struct mdp_process_vsi *)
25 vpu_mapping_dm_addr(vpu->pdev, msg->vpu_inst_addr);
26 vpu->inst_addr = msg->vpu_inst_addr;
29 static void mtk_mdp_vpu_ipi_handler(void *data, unsigned int len, void *priv)
31 unsigned int msg_id = *(unsigned int *)data;
32 struct mdp_ipi_comm_ack *msg = (struct mdp_ipi_comm_ack *)data;
33 struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)
34 (unsigned long)msg->ap_inst;
35 struct mtk_mdp_ctx *ctx;
37 vpu->failure = msg->status;
38 if (!vpu->failure) {
39 switch (msg_id) {
40 case VPU_MDP_INIT_ACK:
41 mtk_mdp_vpu_handle_init_ack(data);
42 break;
43 case VPU_MDP_DEINIT_ACK:
44 case VPU_MDP_PROCESS_ACK:
45 break;
46 default:
47 ctx = vpu_to_ctx(vpu);
48 dev_err(&ctx->mdp_dev->pdev->dev,
49 "handle unknown ipi msg:0x%x\n",
50 msg_id);
51 break;
53 } else {
54 ctx = vpu_to_ctx(vpu);
55 mtk_mdp_dbg(0, "[%d]:msg 0x%x, failure:%d", ctx->id,
56 msg_id, vpu->failure);
60 int mtk_mdp_vpu_register(struct platform_device *pdev)
62 struct mtk_mdp_dev *mdp = platform_get_drvdata(pdev);
63 int err;
65 err = vpu_ipi_register(mdp->vpu_dev, IPI_MDP,
66 mtk_mdp_vpu_ipi_handler, "mdp_vpu", NULL);
67 if (err)
68 dev_err(&mdp->pdev->dev,
69 "vpu_ipi_registration fail status=%d\n", err);
71 return err;
74 static int mtk_mdp_vpu_send_msg(void *msg, int len, struct mtk_mdp_vpu *vpu,
75 int id)
77 struct mtk_mdp_ctx *ctx = vpu_to_ctx(vpu);
78 int err;
80 if (!vpu->pdev) {
81 mtk_mdp_dbg(1, "[%d]:vpu pdev is NULL", ctx->id);
82 return -EINVAL;
85 mutex_lock(&ctx->mdp_dev->vpulock);
86 err = vpu_ipi_send(vpu->pdev, (enum ipi_id)id, msg, len);
87 if (err)
88 dev_err(&ctx->mdp_dev->pdev->dev,
89 "vpu_ipi_send fail status %d\n", err);
90 mutex_unlock(&ctx->mdp_dev->vpulock);
92 return err;
95 static int mtk_mdp_vpu_send_ap_ipi(struct mtk_mdp_vpu *vpu, uint32_t msg_id)
97 int err;
98 struct mdp_ipi_comm msg;
100 msg.msg_id = msg_id;
101 msg.ipi_id = IPI_MDP;
102 msg.vpu_inst_addr = vpu->inst_addr;
103 msg.ap_inst = (unsigned long)vpu;
104 err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
105 if (!err && vpu->failure)
106 err = -EINVAL;
108 return err;
111 int mtk_mdp_vpu_init(struct mtk_mdp_vpu *vpu)
113 int err;
114 struct mdp_ipi_init msg;
115 struct mtk_mdp_ctx *ctx = vpu_to_ctx(vpu);
117 vpu->pdev = ctx->mdp_dev->vpu_dev;
119 msg.msg_id = AP_MDP_INIT;
120 msg.ipi_id = IPI_MDP;
121 msg.ap_inst = (unsigned long)vpu;
122 err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
123 if (!err && vpu->failure)
124 err = -EINVAL;
126 return err;
129 int mtk_mdp_vpu_deinit(struct mtk_mdp_vpu *vpu)
131 return mtk_mdp_vpu_send_ap_ipi(vpu, AP_MDP_DEINIT);
134 int mtk_mdp_vpu_process(struct mtk_mdp_vpu *vpu)
136 return mtk_mdp_vpu_send_ap_ipi(vpu, AP_MDP_PROCESS);