2 * Copyright (c) 2016, NVIDIA CORPORATION.
4 * SPDX-License-Identifier: GPL-2.0
9 #include <mailbox-uclass.h>
13 #define SANDBOX_MBOX_CHANNELS 2
15 struct sandbox_mbox_chan {
21 struct sandbox_mbox_chan chans[SANDBOX_MBOX_CHANNELS];
24 static int sandbox_mbox_request(struct mbox_chan *chan)
26 debug("%s(chan=%p)\n", __func__, chan);
28 if (chan->id >= SANDBOX_MBOX_CHANNELS)
34 static int sandbox_mbox_free(struct mbox_chan *chan)
36 debug("%s(chan=%p)\n", __func__, chan);
41 static int sandbox_mbox_send(struct mbox_chan *chan, const void *data)
43 struct sandbox_mbox *sbm = dev_get_priv(chan->dev);
44 const uint32_t *pmsg = data;
46 debug("%s(chan=%p, data=%p)\n", __func__, chan, data);
48 sbm->chans[chan->id].rx_msg = *pmsg ^ SANDBOX_MBOX_PING_XOR;
49 sbm->chans[chan->id].rx_msg_valid = true;
54 static int sandbox_mbox_recv(struct mbox_chan *chan, void *data)
56 struct sandbox_mbox *sbm = dev_get_priv(chan->dev);
57 uint32_t *pmsg = data;
59 debug("%s(chan=%p, data=%p)\n", __func__, chan, data);
61 if (!sbm->chans[chan->id].rx_msg_valid)
64 *pmsg = sbm->chans[chan->id].rx_msg;
65 sbm->chans[chan->id].rx_msg_valid = false;
70 static int sandbox_mbox_bind(struct udevice *dev)
72 debug("%s(dev=%p)\n", __func__, dev);
77 static int sandbox_mbox_probe(struct udevice *dev)
79 debug("%s(dev=%p)\n", __func__, dev);
84 static const struct udevice_id sandbox_mbox_ids[] = {
85 { .compatible = "sandbox,mbox" },
89 struct mbox_ops sandbox_mbox_mbox_ops = {
90 .request = sandbox_mbox_request,
91 .free = sandbox_mbox_free,
92 .send = sandbox_mbox_send,
93 .recv = sandbox_mbox_recv,
96 U_BOOT_DRIVER(sandbox_mbox) = {
97 .name = "sandbox_mbox",
99 .of_match = sandbox_mbox_ids,
100 .bind = sandbox_mbox_bind,
101 .probe = sandbox_mbox_probe,
102 .priv_auto_alloc_size = sizeof(struct sandbox_mbox),
103 .ops = &sandbox_mbox_mbox_ops,