/src/u-boot/drivers/mailbox/sandbox-mbox.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0 |
2 | | /* |
3 | | * Copyright (c) 2016, NVIDIA CORPORATION. |
4 | | */ |
5 | | |
6 | | #include <dm.h> |
7 | | #include <log.h> |
8 | | #include <mailbox-uclass.h> |
9 | | #include <malloc.h> |
10 | | #include <asm/io.h> |
11 | | #include <asm/mbox.h> |
12 | | |
13 | 0 | #define SANDBOX_MBOX_CHANNELS 2 |
14 | | |
15 | | struct sandbox_mbox_chan { |
16 | | bool rx_msg_valid; |
17 | | uint32_t rx_msg; |
18 | | }; |
19 | | |
20 | | struct sandbox_mbox { |
21 | | struct sandbox_mbox_chan chans[SANDBOX_MBOX_CHANNELS]; |
22 | | }; |
23 | | |
24 | | static int sandbox_mbox_request(struct mbox_chan *chan) |
25 | 0 | { |
26 | 0 | debug("%s(chan=%p)\n", __func__, chan); |
27 | |
|
28 | 0 | if (chan->id >= SANDBOX_MBOX_CHANNELS) |
29 | 0 | return -EINVAL; |
30 | | |
31 | 0 | return 0; |
32 | 0 | } |
33 | | |
34 | | static int sandbox_mbox_free(struct mbox_chan *chan) |
35 | 0 | { |
36 | 0 | debug("%s(chan=%p)\n", __func__, chan); |
37 | |
|
38 | 0 | return 0; |
39 | 0 | } |
40 | | |
41 | | static int sandbox_mbox_send(struct mbox_chan *chan, const void *data) |
42 | 0 | { |
43 | 0 | struct sandbox_mbox *sbm = dev_get_priv(chan->dev); |
44 | 0 | const uint32_t *pmsg = data; |
45 | |
|
46 | 0 | debug("%s(chan=%p, data=%p)\n", __func__, chan, data); |
47 | |
|
48 | 0 | sbm->chans[chan->id].rx_msg = *pmsg ^ SANDBOX_MBOX_PING_XOR; |
49 | 0 | sbm->chans[chan->id].rx_msg_valid = true; |
50 | |
|
51 | 0 | return 0; |
52 | 0 | } |
53 | | |
54 | | static int sandbox_mbox_recv(struct mbox_chan *chan, void *data) |
55 | 0 | { |
56 | 0 | struct sandbox_mbox *sbm = dev_get_priv(chan->dev); |
57 | 0 | uint32_t *pmsg = data; |
58 | |
|
59 | 0 | debug("%s(chan=%p, data=%p)\n", __func__, chan, data); |
60 | |
|
61 | 0 | if (!sbm->chans[chan->id].rx_msg_valid) |
62 | 0 | return -ENODATA; |
63 | | |
64 | 0 | *pmsg = sbm->chans[chan->id].rx_msg; |
65 | 0 | sbm->chans[chan->id].rx_msg_valid = false; |
66 | |
|
67 | 0 | return 0; |
68 | 0 | } |
69 | | |
70 | | static int sandbox_mbox_bind(struct udevice *dev) |
71 | 0 | { |
72 | 0 | debug("%s(dev=%p)\n", __func__, dev); |
73 | |
|
74 | 0 | return 0; |
75 | 0 | } |
76 | | |
77 | | static int sandbox_mbox_probe(struct udevice *dev) |
78 | 0 | { |
79 | 0 | debug("%s(dev=%p)\n", __func__, dev); |
80 | |
|
81 | 0 | return 0; |
82 | 0 | } |
83 | | |
84 | | static const struct udevice_id sandbox_mbox_ids[] = { |
85 | | { .compatible = "sandbox,mbox" }, |
86 | | { } |
87 | | }; |
88 | | |
89 | | struct mbox_ops sandbox_mbox_mbox_ops = { |
90 | | .request = sandbox_mbox_request, |
91 | | .rfree = sandbox_mbox_free, |
92 | | .send = sandbox_mbox_send, |
93 | | .recv = sandbox_mbox_recv, |
94 | | }; |
95 | | |
96 | | U_BOOT_DRIVER(sandbox_mbox) = { |
97 | | .name = "sandbox_mbox", |
98 | | .id = UCLASS_MAILBOX, |
99 | | .of_match = sandbox_mbox_ids, |
100 | | .bind = sandbox_mbox_bind, |
101 | | .probe = sandbox_mbox_probe, |
102 | | .priv_auto = sizeof(struct sandbox_mbox), |
103 | | .ops = &sandbox_mbox_mbox_ops, |
104 | | }; |