1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2021 Mark Kettenis <kettenis@openbsd.org>
8 #include <mailbox-uclass.h>
10 #include <linux/apple-mailbox.h>
11 #include <linux/delay.h>
13 #define REG_A2I_STAT 0x110
14 #define REG_A2I_STAT_EMPTY BIT(17)
15 #define REG_A2I_STAT_FULL BIT(16)
16 #define REG_I2A_STAT 0x114
17 #define REG_I2A_STAT_EMPTY BIT(17)
18 #define REG_I2A_STAT_FULL BIT(16)
19 #define REG_A2I_MSG0 0x800
20 #define REG_A2I_MSG1 0x808
21 #define REG_I2A_MSG0 0x830
22 #define REG_I2A_MSG1 0x838
24 struct apple_mbox_priv {
28 static int apple_mbox_of_xlate(struct mbox_chan *chan,
29 struct ofnode_phandle_args *args)
31 if (args->args_count != 0)
37 static int apple_mbox_send(struct mbox_chan *chan, const void *data)
39 struct apple_mbox_priv *priv = dev_get_priv(chan->dev);
40 const struct apple_mbox_msg *msg = data;
42 writeq(msg->msg0, priv->base + REG_A2I_MSG0);
43 writeq(msg->msg1, priv->base + REG_A2I_MSG1);
44 while (readl(priv->base + REG_A2I_STAT) & REG_A2I_STAT_FULL)
50 static int apple_mbox_recv(struct mbox_chan *chan, void *data)
52 struct apple_mbox_priv *priv = dev_get_priv(chan->dev);
53 struct apple_mbox_msg *msg = data;
55 if (readl(priv->base + REG_I2A_STAT) & REG_I2A_STAT_EMPTY)
58 msg->msg0 = readq(priv->base + REG_I2A_MSG0);
59 msg->msg1 = readq(priv->base + REG_I2A_MSG1);
63 struct mbox_ops apple_mbox_ops = {
64 .of_xlate = apple_mbox_of_xlate,
65 .send = apple_mbox_send,
66 .recv = apple_mbox_recv,
69 static int apple_mbox_probe(struct udevice *dev)
71 struct apple_mbox_priv *priv = dev_get_priv(dev);
73 priv->base = dev_read_addr_ptr(dev);
80 static const struct udevice_id apple_mbox_of_match[] = {
81 { .compatible = "apple,asc-mailbox-v4" },
85 U_BOOT_DRIVER(apple_mbox) = {
88 .of_match = apple_mbox_of_match,
89 .probe = apple_mbox_probe,
90 .priv_auto = sizeof(struct apple_mbox_priv),
91 .ops = &apple_mbox_ops,