1 // SPDX-License-Identifier: GPL-2.0+
3 * Xilinx Zynq MPSoC Mailbox driver
5 * Copyright (C) 2018-2019 Xilinx, Inc.
11 #include <mailbox-uclass.h>
12 #include <mach/sys_proto.h>
13 #include <linux/ioport.h>
17 /* IPI bitmasks, register base */
18 /* TODO: move reg base to DT */
19 #define IPI_BIT_MASK_PMU0 0x10000
20 #define IPI_INT_REG_BASE_APU 0xFF300000
31 #define ipi_int_apu ((struct ipi_int_regs *)IPI_INT_REG_BASE_APU)
34 void __iomem *local_req_regs;
35 void __iomem *local_res_regs;
36 void __iomem *remote_req_regs;
37 void __iomem *remote_res_regs;
40 static int zynqmp_ipi_send(struct mbox_chan *chan, const void *data)
42 const struct zynqmp_ipi_msg *msg = (struct zynqmp_ipi_msg *)data;
43 struct zynqmp_ipi *zynqmp = dev_get_priv(chan->dev);
45 u32 *mbx = (u32 *)zynqmp->local_req_regs;
47 for (size_t i = 0; i < msg->len; i++)
48 writel(msg->buf[i], &mbx[i]);
50 /* Write trigger interrupt */
51 writel(IPI_BIT_MASK_PMU0, &ipi_int_apu->trig);
53 /* Wait until observation bit is cleared */
54 ret = wait_for_bit_le32(&ipi_int_apu->obs, IPI_BIT_MASK_PMU0, false,
57 debug("%s, send %ld bytes\n", __func__, msg->len);
61 static int zynqmp_ipi_recv(struct mbox_chan *chan, void *data)
63 struct zynqmp_ipi_msg *msg = (struct zynqmp_ipi_msg *)data;
64 struct zynqmp_ipi *zynqmp = dev_get_priv(chan->dev);
65 u32 *mbx = (u32 *)zynqmp->local_res_regs;
67 for (size_t i = 0; i < msg->len; i++)
68 msg->buf[i] = readl(&mbx[i]);
70 debug("%s, recv %ld bytes\n", __func__, msg->len);
74 static int zynqmp_ipi_probe(struct udevice *dev)
76 struct zynqmp_ipi *zynqmp = dev_get_priv(dev);
80 debug("%s(dev=%p)\n", __func__, dev);
82 /* Get subnode where the regs are defined */
83 /* Note IPI mailbox node needs to be the first one in DT */
84 node = ofnode_first_subnode(dev_ofnode(dev));
86 if (ofnode_read_resource_byname(node, "local_request_region", &res)) {
87 dev_err(dev, "No reg property for local_request_region\n");
90 zynqmp->local_req_regs = devm_ioremap(dev, res.start,
91 (res.start - res.end));
93 if (ofnode_read_resource_byname(node, "local_response_region", &res)) {
94 dev_err(dev, "No reg property for local_response_region\n");
97 zynqmp->local_res_regs = devm_ioremap(dev, res.start,
98 (res.start - res.end));
100 if (ofnode_read_resource_byname(node, "remote_request_region", &res)) {
101 dev_err(dev, "No reg property for remote_request_region\n");
104 zynqmp->remote_req_regs = devm_ioremap(dev, res.start,
105 (res.start - res.end));
107 if (ofnode_read_resource_byname(node, "remote_response_region", &res)) {
108 dev_err(dev, "No reg property for remote_response_region\n");
111 zynqmp->remote_res_regs = devm_ioremap(dev, res.start,
112 (res.start - res.end));
117 static const struct udevice_id zynqmp_ipi_ids[] = {
118 { .compatible = "xlnx,zynqmp-ipi-mailbox" },
122 struct mbox_ops zynqmp_ipi_mbox_ops = {
123 .send = zynqmp_ipi_send,
124 .recv = zynqmp_ipi_recv,
127 U_BOOT_DRIVER(zynqmp_ipi) = {
128 .name = "zynqmp-ipi",
129 .id = UCLASS_MAILBOX,
130 .of_match = zynqmp_ipi_ids,
131 .probe = zynqmp_ipi_probe,
132 .priv_auto_alloc_size = sizeof(struct zynqmp_ipi),
133 .ops = &zynqmp_ipi_mbox_ops,