1 // SPDX-License-Identifier: GPL-2.0+
3 * Xilinx Zynq MPSoC Mailbox driver
5 * Copyright (C) 2018-2019 Xilinx, Inc.
12 #include <mailbox-uclass.h>
13 #include <dm/device_compat.h>
14 #include <mach/sys_proto.h>
15 #include <linux/ioport.h>
19 /* IPI bitmasks, register base */
20 /* TODO: move reg base to DT */
21 #define IPI_BIT_MASK_PMU0 0x10000
22 #define IPI_INT_REG_BASE_APU 0xFF300000
33 #define ipi_int_apu ((struct ipi_int_regs *)IPI_INT_REG_BASE_APU)
36 void __iomem *local_req_regs;
37 void __iomem *local_res_regs;
38 void __iomem *remote_req_regs;
39 void __iomem *remote_res_regs;
42 static int zynqmp_ipi_send(struct mbox_chan *chan, const void *data)
44 const struct zynqmp_ipi_msg *msg = (struct zynqmp_ipi_msg *)data;
45 struct zynqmp_ipi *zynqmp = dev_get_priv(chan->dev);
47 u32 *mbx = (u32 *)zynqmp->local_req_regs;
49 for (size_t i = 0; i < msg->len; i++)
50 writel(msg->buf[i], &mbx[i]);
52 /* Write trigger interrupt */
53 writel(IPI_BIT_MASK_PMU0, &ipi_int_apu->trig);
55 /* Wait until observation bit is cleared */
56 ret = wait_for_bit_le32(&ipi_int_apu->obs, IPI_BIT_MASK_PMU0, false,
59 debug("%s, send %ld bytes\n", __func__, msg->len);
63 static int zynqmp_ipi_recv(struct mbox_chan *chan, void *data)
65 struct zynqmp_ipi_msg *msg = (struct zynqmp_ipi_msg *)data;
66 struct zynqmp_ipi *zynqmp = dev_get_priv(chan->dev);
67 u32 *mbx = (u32 *)zynqmp->local_res_regs;
69 for (size_t i = 0; i < msg->len; i++)
70 msg->buf[i] = readl(&mbx[i]);
72 debug("%s, recv %ld bytes\n", __func__, msg->len);
76 static int zynqmp_ipi_probe(struct udevice *dev)
78 struct zynqmp_ipi *zynqmp = dev_get_priv(dev);
82 debug("%s(dev=%p)\n", __func__, dev);
84 /* Get subnode where the regs are defined */
85 /* Note IPI mailbox node needs to be the first one in DT */
86 node = ofnode_first_subnode(dev_ofnode(dev));
88 if (ofnode_read_resource_byname(node, "local_request_region", &res)) {
89 dev_err(dev, "No reg property for local_request_region\n");
92 zynqmp->local_req_regs = devm_ioremap(dev, res.start,
93 (res.start - res.end));
95 if (ofnode_read_resource_byname(node, "local_response_region", &res)) {
96 dev_err(dev, "No reg property for local_response_region\n");
99 zynqmp->local_res_regs = devm_ioremap(dev, res.start,
100 (res.start - res.end));
102 if (ofnode_read_resource_byname(node, "remote_request_region", &res)) {
103 dev_err(dev, "No reg property for remote_request_region\n");
106 zynqmp->remote_req_regs = devm_ioremap(dev, res.start,
107 (res.start - res.end));
109 if (ofnode_read_resource_byname(node, "remote_response_region", &res)) {
110 dev_err(dev, "No reg property for remote_response_region\n");
113 zynqmp->remote_res_regs = devm_ioremap(dev, res.start,
114 (res.start - res.end));
119 static const struct udevice_id zynqmp_ipi_ids[] = {
120 { .compatible = "xlnx,zynqmp-ipi-mailbox" },
124 struct mbox_ops zynqmp_ipi_mbox_ops = {
125 .send = zynqmp_ipi_send,
126 .recv = zynqmp_ipi_recv,
129 U_BOOT_DRIVER(zynqmp_ipi) = {
130 .name = "zynqmp-ipi",
131 .id = UCLASS_MAILBOX,
132 .of_match = zynqmp_ipi_ids,
133 .probe = zynqmp_ipi_probe,
134 .priv_auto_alloc_size = sizeof(struct zynqmp_ipi),
135 .ops = &zynqmp_ipi_mbox_ops,