blob: 959cce923c5982266003be5396f487ce49697e64 [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>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Ibai Erkiaga4b1264d2019-09-27 11:36:56 +010010#include <asm/io.h>
11#include <dm.h>
12#include <mailbox-uclass.h>
Simon Glass9bc15642020-02-03 07:36:16 -070013#include <dm/device_compat.h>
Ibai Erkiaga4b1264d2019-09-27 11:36:56 +010014#include <mach/sys_proto.h>
15#include <linux/ioport.h>
16#include <linux/io.h>
17#include <wait_bit.h>
18
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
23
24struct ipi_int_regs {
25 u32 trig; /* 0x0 */
26 u32 obs; /* 0x4 */
Ibai Erkiagaab07ce52020-08-04 23:17:32 +010027 u32 dummy0;
28 u32 dummy1;
29 u32 isr; /* 0x10 */
30 u32 imr; /* 0x14 */
31 u32 ier; /* 0x18 */
32 u32 idr; /* 0x1C */
Ibai Erkiaga4b1264d2019-09-27 11:36:56 +010033};
34
35#define ipi_int_apu ((struct ipi_int_regs *)IPI_INT_REG_BASE_APU)
36
37struct zynqmp_ipi {
38 void __iomem *local_req_regs;
39 void __iomem *local_res_regs;
40 void __iomem *remote_req_regs;
41 void __iomem *remote_res_regs;
42};
43
44static int zynqmp_ipi_send(struct mbox_chan *chan, const void *data)
45{
46 const struct zynqmp_ipi_msg *msg = (struct zynqmp_ipi_msg *)data;
47 struct zynqmp_ipi *zynqmp = dev_get_priv(chan->dev);
48 u32 ret;
49 u32 *mbx = (u32 *)zynqmp->local_req_regs;
50
51 for (size_t i = 0; i < msg->len; i++)
52 writel(msg->buf[i], &mbx[i]);
53
54 /* Write trigger interrupt */
55 writel(IPI_BIT_MASK_PMU0, &ipi_int_apu->trig);
56
57 /* Wait until observation bit is cleared */
58 ret = wait_for_bit_le32(&ipi_int_apu->obs, IPI_BIT_MASK_PMU0, false,
Michal Simekac1c7a32020-10-05 15:23:00 +020059 1000, false);
Ibai Erkiaga4b1264d2019-09-27 11:36:56 +010060
61 debug("%s, send %ld bytes\n", __func__, msg->len);
62 return ret;
63};
64
65static int zynqmp_ipi_recv(struct mbox_chan *chan, void *data)
66{
67 struct zynqmp_ipi_msg *msg = (struct zynqmp_ipi_msg *)data;
68 struct zynqmp_ipi *zynqmp = dev_get_priv(chan->dev);
69 u32 *mbx = (u32 *)zynqmp->local_res_regs;
70
Ibai Erkiagaab07ce52020-08-04 23:17:32 +010071 /*
72 * PMU Firmware does not trigger IPI interrupt for API call responses so
73 * there is no need to check ISR flags
74 */
Ibai Erkiaga4b1264d2019-09-27 11:36:56 +010075 for (size_t i = 0; i < msg->len; i++)
76 msg->buf[i] = readl(&mbx[i]);
77
78 debug("%s, recv %ld bytes\n", __func__, msg->len);
79 return 0;
80};
81
82static int zynqmp_ipi_probe(struct udevice *dev)
83{
84 struct zynqmp_ipi *zynqmp = dev_get_priv(dev);
85 struct resource res;
86 ofnode node;
87
88 debug("%s(dev=%p)\n", __func__, dev);
89
90 /* Get subnode where the regs are defined */
91 /* Note IPI mailbox node needs to be the first one in DT */
92 node = ofnode_first_subnode(dev_ofnode(dev));
93
94 if (ofnode_read_resource_byname(node, "local_request_region", &res)) {
95 dev_err(dev, "No reg property for local_request_region\n");
96 return -EINVAL;
97 };
98 zynqmp->local_req_regs = devm_ioremap(dev, res.start,
99 (res.start - res.end));
100
101 if (ofnode_read_resource_byname(node, "local_response_region", &res)) {
102 dev_err(dev, "No reg property for local_response_region\n");
103 return -EINVAL;
104 };
105 zynqmp->local_res_regs = devm_ioremap(dev, res.start,
106 (res.start - res.end));
107
108 if (ofnode_read_resource_byname(node, "remote_request_region", &res)) {
109 dev_err(dev, "No reg property for remote_request_region\n");
110 return -EINVAL;
111 };
112 zynqmp->remote_req_regs = devm_ioremap(dev, res.start,
113 (res.start - res.end));
114
115 if (ofnode_read_resource_byname(node, "remote_response_region", &res)) {
116 dev_err(dev, "No reg property for remote_response_region\n");
117 return -EINVAL;
118 };
119 zynqmp->remote_res_regs = devm_ioremap(dev, res.start,
120 (res.start - res.end));
121
122 return 0;
123};
124
125static const struct udevice_id zynqmp_ipi_ids[] = {
126 { .compatible = "xlnx,zynqmp-ipi-mailbox" },
127 { }
128};
129
130struct mbox_ops zynqmp_ipi_mbox_ops = {
131 .send = zynqmp_ipi_send,
132 .recv = zynqmp_ipi_recv,
133};
134
135U_BOOT_DRIVER(zynqmp_ipi) = {
Michal Simek33093082020-01-07 08:50:34 +0100136 .name = "zynqmp_ipi",
Ibai Erkiaga4b1264d2019-09-27 11:36:56 +0100137 .id = UCLASS_MAILBOX,
138 .of_match = zynqmp_ipi_ids,
139 .probe = zynqmp_ipi_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700140 .priv_auto = sizeof(struct zynqmp_ipi),
Ibai Erkiaga4b1264d2019-09-27 11:36:56 +0100141 .ops = &zynqmp_ipi_mbox_ops,
142};