forked from neggles/copr-linux-phytium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0057-mailbox-Add-support-for-Phytium-SoC-mailbox-driver.patch
265 lines (259 loc) · 7.06 KB
/
0057-mailbox-Add-support-for-Phytium-SoC-mailbox-driver.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
From a5a8d6a2b28f691e5c8f94fd8b16fb2fc167c763 Mon Sep 17 00:00:00 2001
From: Chen Baozi <[email protected]>
Date: Mon, 17 Jun 2024 19:33:05 +0800
Subject: [PATCH 057/150] mailbox: Add support for Phytium SoC mailbox driver
Add the driver to support Phytium SoC mailbox controller.
Signed-off-by: Chen Baozi <[email protected]>
Change-Id: If08b9c960a9050fe6495d564e644f03a211a95bc
Signed-off-by: Andrew Powers-Holmes <[email protected]>
---
MAINTAINERS | 1 +
drivers/mailbox/Kconfig | 9 ++
drivers/mailbox/Makefile | 2 +
drivers/mailbox/phytium_mailbox.c | 196 ++++++++++++++++++++++++++++++
4 files changed, 208 insertions(+)
create mode 100644 drivers/mailbox/phytium_mailbox.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 2d85f363c97d..78e1a3431c15 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2563,6 +2563,7 @@ F: drivers/i2c/busses/i2c-phytium-*
F: drivers/iio/adc/phytium-adc.c
F: drivers/input/keyboard/phytium-keypad.c
F: drivers/input/serio/phytium-ps2.c
+F: drivers/mailbox/phytium_mailbox.c
F: drivers/media/platform/phytium-jpeg/phytium_jpeg*
F: drivers/mmc/host/phytium-mci*
F: drivers/mmc/host/phytium-sdci.*
diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
index bc2e265cb02d..771f8fabded3 100644
--- a/drivers/mailbox/Kconfig
+++ b/drivers/mailbox/Kconfig
@@ -41,6 +41,15 @@ config IMX_MBOX
help
Mailbox implementation for i.MX Messaging Unit (MU).
+config PHYTIUM_MBOX
+ tristate "Phytium SoC Mailbox Support"
+ depends on ARCH_PHYTIUM || COMPILE_TEST
+ help
+ Mailbox driver implementation for the Phytium platform. It is used
+ to send message between application processors and on-chip management
+ firmware. Say Y here if you want to build this mailbox controller
+ driver.
+
config PLATFORM_MHU
tristate "Platform MHU Mailbox"
depends on OF
diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile
index fc9376117111..487f62094c9e 100644
--- a/drivers/mailbox/Makefile
+++ b/drivers/mailbox/Makefile
@@ -62,3 +62,5 @@ obj-$(CONFIG_SPRD_MBOX) += sprd-mailbox.o
obj-$(CONFIG_QCOM_IPCC) += qcom-ipcc.o
obj-$(CONFIG_APPLE_MAILBOX) += apple-mailbox.o
+
+obj-$(CONFIG_PHYTIUM_MBOX) += phytium_mailbox.o
diff --git a/drivers/mailbox/phytium_mailbox.c b/drivers/mailbox/phytium_mailbox.c
new file mode 100644
index 000000000000..afab8f401556
--- /dev/null
+++ b/drivers/mailbox/phytium_mailbox.c
@@ -0,0 +1,196 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Phytium SoC mailbox driver
+ *
+ * Copyright (c) 2020-2023, Phytium Technology Co., Ltd.
+ *
+ * Derived from drivers/mailbox/arm_mhu.c
+ * Copyright (C) 2013-2015 Fujitsu Semiconductor Ltd.
+ * Copyright (C) 2015 Linaro Ltd.
+ */
+
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/mailbox_controller.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+
+#define INTR_STAT 0x0
+#define INTR_SET 0x8
+#define INTR_CLR 0x10
+
+#define TX_REG 0x100
+
+#define NR_CHANS 1
+
+struct phytium_mbox_link {
+ unsigned int irq;
+ void __iomem *tx_reg;
+ void __iomem *rx_reg;
+};
+
+struct phytium_mbox {
+ void __iomem *base;
+ struct phytium_mbox_link mlink;
+ struct mbox_chan chan;
+ struct mbox_controller mbox;
+};
+
+static irqreturn_t phytium_mbox_rx_irq(int irq, void *ch)
+{
+ struct mbox_chan *chan = ch;
+ struct phytium_mbox_link *mlink = chan->con_priv;
+ u32 val;
+
+ val = readl_relaxed(mlink->rx_reg + INTR_STAT);
+ if (!val)
+ return IRQ_NONE;
+
+ mbox_chan_received_data(chan, (void *)&val);
+
+ writel_relaxed(val, mlink->rx_reg + INTR_CLR);
+
+ return IRQ_HANDLED;
+}
+
+static int phytium_mbox_send_data(struct mbox_chan *chan, void *data)
+{
+ struct phytium_mbox_link *mlink = chan->con_priv;
+ u32 *arg = data;
+
+ writel_relaxed(*arg, mlink->tx_reg + INTR_SET);
+
+ return 0;
+}
+
+static int phytium_mbox_startup(struct mbox_chan *chan)
+{
+ struct phytium_mbox_link *mlink = chan->con_priv;
+ u32 val;
+ int ret;
+
+ val = readl_relaxed(mlink->tx_reg + INTR_STAT);
+ writel_relaxed(val, mlink->tx_reg + INTR_CLR);
+
+ ret = request_irq(mlink->irq, phytium_mbox_rx_irq,
+ IRQF_SHARED, "phytium_mbox_link", chan);
+ if (ret) {
+ dev_err(chan->mbox->dev,
+ "Unable to acquire IRQ %d\n", mlink->irq);
+ }
+
+ return ret;
+}
+
+static void phytium_mbox_shutdown(struct mbox_chan *chan)
+{
+ struct phytium_mbox_link *mlink = chan->con_priv;
+
+ free_irq(mlink->irq, chan);
+}
+
+static bool phytium_mbox_last_tx_done(struct mbox_chan *chan)
+{
+ struct phytium_mbox_link *mlink = chan->con_priv;
+ u32 val = readl_relaxed(mlink->tx_reg + INTR_STAT);
+
+ return (val == (u32)(1U << 31));
+}
+
+static const struct mbox_chan_ops phytium_mbox_ops = {
+ .send_data = phytium_mbox_send_data,
+ .startup = phytium_mbox_startup,
+ .shutdown = phytium_mbox_shutdown,
+ .last_tx_done = phytium_mbox_last_tx_done,
+};
+
+static const struct acpi_device_id phytium_mbox_acpi_match[] = {
+ { "PHYT0009", 0 },
+ { },
+};
+MODULE_DEVICE_TABLE(acpi, phytium_mbox_acpi_match);
+
+static const struct of_device_id phytium_mbox_of_match[] = {
+ { .compatible = "phytium,mbox", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, phytium_mbox_of_match);
+
+static int phytium_mbox_probe(struct platform_device *pdev)
+{
+ struct phytium_mbox *mbox;
+ struct resource *res;
+ int err, irq;
+
+ /* Allocate memory for device */
+ mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL);
+ if (!mbox)
+ return -ENOMEM;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ mbox->base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(mbox->base)) {
+ dev_err(&pdev->dev, "ioremap base failed\n");
+ return PTR_ERR(mbox->base);
+ }
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0) {
+ dev_err(&pdev->dev, "cannot obtain irq\n");
+ return irq;
+ }
+
+ mbox->chan.con_priv = &mbox->mlink;
+ mbox->mlink.irq = irq;
+ mbox->mlink.rx_reg = mbox->base;
+ mbox->mlink.tx_reg = mbox->mlink.rx_reg + TX_REG;
+
+ mbox->mbox.dev = &pdev->dev;
+ mbox->mbox.chans = &mbox->chan;
+ mbox->mbox.num_chans = NR_CHANS;
+ mbox->mbox.ops = &phytium_mbox_ops;
+ mbox->mbox.txdone_irq = false;
+ mbox->mbox.txdone_poll = true;
+ mbox->mbox.txpoll_period = 1;
+
+ platform_set_drvdata(pdev, mbox);
+
+ err = mbox_controller_register(&mbox->mbox);
+ if (err) {
+ dev_err(&pdev->dev, "Failed to register mailboxes %d\n", err);
+ goto fail;
+ }
+
+ dev_info(&pdev->dev, "Phytium SoC Mailbox registered\n");
+fail:
+ return err;
+}
+
+static int phytium_mbox_remove(struct platform_device *pdev)
+{
+ struct phytium_mbox *mbox = platform_get_drvdata(pdev);
+
+ mbox_controller_unregister(&mbox->mbox);
+
+ return 0;
+}
+
+static struct platform_driver phytium_mbox_driver = {
+ .probe = phytium_mbox_probe,
+ .remove = phytium_mbox_remove,
+ .driver = {
+ .name = "phytium-mbox",
+ .of_match_table = of_match_ptr(phytium_mbox_of_match),
+ .acpi_match_table = ACPI_PTR(phytium_mbox_acpi_match),
+ },
+};
+
+module_platform_driver(phytium_mbox_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Phytium SoC Mailbox Driver");
+MODULE_AUTHOR("Chen Baozi <[email protected]>");
--
2.47.0