blob: 17b46545f5f9d7df46fdde18c33bbed4d5238c43 [file] [log] [blame]
Ibai Erkiaga4b1264d2019-09-27 11:36:56 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Xilinx Zynq MPSoC Mailbox driver
4 *
5 * Copyright (C) 2018-2019 Xilinx, Inc.
6 */
7
8#include <common.h>
9#include <asm/io.h>
10#include <dm.h>
11#include <mailbox-uclass.h>
Simon Glass9bc15642020-02-03 07:36:16 -070012#include <dm/device_compat.h>
Ibai Erkiaga4b1264d2019-09-27 11:36:56 +010013#include <mach/sys_proto.h>
14#include <linux/ioport.h>
15#include <linux/io.h>
16#include <wait_bit.h>
17
18/* IPI bitmasks, register base */
19/* TODO: move reg base to DT */
20#define IPI_BIT_MASK_PMU0 0x10000
21#define IPI_INT_REG_BASE_APU 0xFF300000
22
23struct ipi_int_regs {
24 u32 trig; /* 0x0 */
25 u32 obs; /* 0x4 */
26 u32 ist; /* 0x8 */
27 u32 imr; /* 0xC */
28 u32 ier; /* 0x10 */
29 u32 idr; /* 0x14 */
30};
31
32#define ipi_int_apu ((struct ipi_int_regs *)IPI_INT_REG_BASE_APU)
33
34struct zynqmp_ipi {
35 void __iomem *local_req_regs;
36 void __iomem *local_res_regs;
37 void __iomem *remote_req_regs;
38 void __iomem *remote_res_regs;
39};
40
41static int zynqmp_ipi_send(struct mbox_chan *chan, const void *data)
42{
43 const struct zynqmp_ipi_msg *msg = (struct zynqmp_ipi_msg *)data;
44 struct zynqmp_ipi *zynqmp = dev_get_priv(chan->dev);
45 u32 ret;
46 u32 *mbx = (u32 *)zynqmp->local_req_regs;
47
48 for (size_t i = 0; i < msg->len; i++)
49 writel(msg->buf[i], &mbx[i]);
50
51 /* Write trigger interrupt */
52 writel(IPI_BIT_MASK_PMU0, &ipi_int_apu->trig);
53
54 /* Wait until observation bit is cleared */
55 ret = wait_for_bit_le32(&ipi_int_apu->obs, IPI_BIT_MASK_PMU0, false,
56 100, false);
57
58 debug("%s, send %ld bytes\n", __func__, msg->len);
59 return ret;
60};
61
62static int zynqmp_ipi_recv(struct mbox_chan *chan, void *data)
63{
64 struct zynqmp_ipi_msg *msg = (struct zynqmp_ipi_msg *)data;
65 struct zynqmp_ipi *zynqmp = dev_get_priv(chan->dev);
66 u32 *mbx = (u32 *)zynqmp->local_res_regs;
67
68 for (size_t i = 0; i < msg->len; i++)
69 msg->buf[i] = readl(&mbx[i]);
70
71 debug("%s, recv %ld bytes\n", __func__, msg->len);
72 return 0;
73};
74
75static int zynqmp_ipi_probe(struct udevice *dev)
76{
77 struct zynqmp_ipi *zynqmp = dev_get_priv(dev);
78 struct resource res;
79 ofnode node;
80
81 debug("%s(dev=%p)\n", __func__, dev);
82
83 /* Get subnode where the regs are defined */
84 /* Note IPI mailbox node needs to be the first one in DT */
85 node = ofnode_first_subnode(dev_ofnode(dev));
86
87 if (ofnode_read_resource_byname(node, "local_request_region", &res)) {
88 dev_err(dev, "No reg property for local_request_region\n");
89 return -EINVAL;
90 };
91 zynqmp->local_req_regs = devm_ioremap(dev, res.start,
92 (res.start - res.end));
93
94 if (ofnode_read_resource_byname(node, "local_response_region", &res)) {
95 dev_err(dev, "No reg property for local_response_region\n");
96 return -EINVAL;
97 };
98 zynqmp->local_res_regs = devm_ioremap(dev, res.start,
99 (res.start - res.end));
100
101 if (ofnode_read_resource_byname(node, "remote_request_region", &res)) {
102 dev_err(dev, "No reg property for remote_request_region\n");
103 return -EINVAL;
104 };
105 zynqmp->remote_req_regs = devm_ioremap(dev, res.start,
106 (res.start - res.end));
107
108 if (ofnode_read_resource_byname(node, "remote_response_region", &res)) {
109 dev_err(dev, "No reg property for remote_response_region\n");
110 return -EINVAL;
111 };
112 zynqmp->remote_res_regs = devm_ioremap(dev, res.start,
113 (res.start - res.end));
114
115 return 0;
116};
117
118static const struct udevice_id zynqmp_ipi_ids[] = {
119 { .compatible = "xlnx,zynqmp-ipi-mailbox" },
120 { }
121};
122
123struct mbox_ops zynqmp_ipi_mbox_ops = {
124 .send = zynqmp_ipi_send,
125 .recv = zynqmp_ipi_recv,
126};
127
128U_BOOT_DRIVER(zynqmp_ipi) = {
129 .name = "zynqmp-ipi",
130 .id = UCLASS_MAILBOX,
131 .of_match = zynqmp_ipi_ids,
132 .probe = zynqmp_ipi_probe,
133 .priv_auto_alloc_size = sizeof(struct zynqmp_ipi),
134 .ops = &zynqmp_ipi_mbox_ops,
135};