1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2020-2021 NXP
6 #include <linux/init.h>
7 #include <linux/interconnect.h>
8 #include <linux/ioctl.h>
9 #include <linux/list.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/of_device.h>
13 #include <linux/of_address.h>
14 #include <linux/platform_device.h>
19 static void vpu_mbox_rx_callback(struct mbox_client *cl, void *msg)
21 struct vpu_mbox *rx = container_of(cl, struct vpu_mbox, cl);
22 struct vpu_core *core = container_of(rx, struct vpu_core, rx);
24 vpu_isr(core, *(u32 *)msg);
27 static int vpu_mbox_request_channel(struct device *dev, struct vpu_mbox *mbox)
30 struct mbox_client *cl;
45 cl->knows_txdone = false;
46 cl->rx_callback = vpu_mbox_rx_callback;
48 ch = mbox_request_channel_byname(cl, mbox->name);
50 dev_err(dev, "Failed to request mbox chan %s, ret : %ld\n",
51 mbox->name, PTR_ERR(ch));
59 int vpu_mbox_init(struct vpu_core *core)
61 scnprintf(core->tx_type.name, sizeof(core->tx_type.name) - 1, "tx0");
62 core->tx_type.block = true;
64 scnprintf(core->tx_data.name, sizeof(core->tx_data.name) - 1, "tx1");
65 core->tx_data.block = false;
67 scnprintf(core->rx.name, sizeof(core->rx.name) - 1, "rx");
68 core->rx.block = true;
73 int vpu_mbox_request(struct vpu_core *core)
77 ret = vpu_mbox_request_channel(core->dev, &core->tx_type);
80 ret = vpu_mbox_request_channel(core->dev, &core->tx_data);
83 ret = vpu_mbox_request_channel(core->dev, &core->rx);
87 dev_dbg(core->dev, "%s request mbox\n", vpu_core_type_desc(core->type));
94 void vpu_mbox_free(struct vpu_core *core)
96 mbox_free_channel(core->tx_type.ch);
97 mbox_free_channel(core->tx_data.ch);
98 mbox_free_channel(core->rx.ch);
99 core->tx_type.ch = NULL;
100 core->tx_data.ch = NULL;
102 dev_dbg(core->dev, "%s free mbox\n", vpu_core_type_desc(core->type));
105 void vpu_mbox_send_type(struct vpu_core *core, u32 type)
107 mbox_send_message(core->tx_type.ch, &type);
110 void vpu_mbox_send_msg(struct vpu_core *core, u32 type, u32 data)
112 mbox_send_message(core->tx_data.ch, &data);
113 mbox_send_message(core->tx_type.ch, &type);
116 void vpu_mbox_enable_rx(struct vpu_dev *dev)