1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016, NVIDIA CORPORATION.
9 #include <mailbox-uclass.h>
14 #define SANDBOX_MBOX_CHANNELS 2
16 struct sandbox_mbox_chan {
22 struct sandbox_mbox_chan chans[SANDBOX_MBOX_CHANNELS];
25 static int sandbox_mbox_request(struct mbox_chan *chan)
27 debug("%s(chan=%p)\n", __func__, chan);
29 if (chan->id >= SANDBOX_MBOX_CHANNELS)
35 static int sandbox_mbox_free(struct mbox_chan *chan)
37 debug("%s(chan=%p)\n", __func__, chan);
42 static int sandbox_mbox_send(struct mbox_chan *chan, const void *data)
44 struct sandbox_mbox *sbm = dev_get_priv(chan->dev);
45 const uint32_t *pmsg = data;
47 debug("%s(chan=%p, data=%p)\n", __func__, chan, data);
49 sbm->chans[chan->id].rx_msg = *pmsg ^ SANDBOX_MBOX_PING_XOR;
50 sbm->chans[chan->id].rx_msg_valid = true;
55 static int sandbox_mbox_recv(struct mbox_chan *chan, void *data)
57 struct sandbox_mbox *sbm = dev_get_priv(chan->dev);
58 uint32_t *pmsg = data;
60 debug("%s(chan=%p, data=%p)\n", __func__, chan, data);
62 if (!sbm->chans[chan->id].rx_msg_valid)
65 *pmsg = sbm->chans[chan->id].rx_msg;
66 sbm->chans[chan->id].rx_msg_valid = false;
71 static int sandbox_mbox_bind(struct udevice *dev)
73 debug("%s(dev=%p)\n", __func__, dev);
78 static int sandbox_mbox_probe(struct udevice *dev)
80 debug("%s(dev=%p)\n", __func__, dev);
85 static const struct udevice_id sandbox_mbox_ids[] = {
86 { .compatible = "sandbox,mbox" },
90 struct mbox_ops sandbox_mbox_mbox_ops = {
91 .request = sandbox_mbox_request,
92 .rfree = sandbox_mbox_free,
93 .send = sandbox_mbox_send,
94 .recv = sandbox_mbox_recv,
97 U_BOOT_DRIVER(sandbox_mbox) = {
98 .name = "sandbox_mbox",
100 .of_match = sandbox_mbox_ids,
101 .bind = sandbox_mbox_bind,
102 .probe = sandbox_mbox_probe,
103 .priv_auto = sizeof(struct sandbox_mbox),
104 .ops = &sandbox_mbox_mbox_ops,