1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2016, NVIDIA CORPORATION.
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <mailbox.h>
9 #include <asm/io.h>
10 
11 struct sandbox_mbox_test {
12 	struct mbox_chan chan;
13 };
14 
sandbox_mbox_test_get(struct udevice * dev)15 int sandbox_mbox_test_get(struct udevice *dev)
16 {
17 	struct sandbox_mbox_test *sbmt = dev_get_priv(dev);
18 
19 	return mbox_get_by_name(dev, "test", &sbmt->chan);
20 }
21 
sandbox_mbox_test_send(struct udevice * dev,uint32_t msg)22 int sandbox_mbox_test_send(struct udevice *dev, uint32_t msg)
23 {
24 	struct sandbox_mbox_test *sbmt = dev_get_priv(dev);
25 
26 	return mbox_send(&sbmt->chan, &msg);
27 }
28 
sandbox_mbox_test_recv(struct udevice * dev,uint32_t * msg)29 int sandbox_mbox_test_recv(struct udevice *dev, uint32_t *msg)
30 {
31 	struct sandbox_mbox_test *sbmt = dev_get_priv(dev);
32 
33 	return mbox_recv(&sbmt->chan, msg, 100);
34 }
35 
sandbox_mbox_test_free(struct udevice * dev)36 int sandbox_mbox_test_free(struct udevice *dev)
37 {
38 	struct sandbox_mbox_test *sbmt = dev_get_priv(dev);
39 
40 	return mbox_free(&sbmt->chan);
41 }
42 
43 static const struct udevice_id sandbox_mbox_test_ids[] = {
44 	{ .compatible = "sandbox,mbox-test" },
45 	{ }
46 };
47 
48 U_BOOT_DRIVER(sandbox_mbox_test) = {
49 	.name = "sandbox_mbox_test",
50 	.id = UCLASS_MISC,
51 	.of_match = sandbox_mbox_test_ids,
52 	.priv_auto_alloc_size = sizeof(struct sandbox_mbox_test),
53 };
54