]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/mailbox/mailbox-uclass.c
2 * Copyright (c) 2016, NVIDIA CORPORATION.
4 * SPDX-License-Identifier: GPL-2.0
11 #include <mailbox-uclass.h>
13 DECLARE_GLOBAL_DATA_PTR
;
15 static inline struct mbox_ops
*mbox_dev_ops(struct udevice
*dev
)
17 return (struct mbox_ops
*)dev
->driver
->ops
;
20 static int mbox_of_xlate_default(struct mbox_chan
*chan
,
21 struct fdtdec_phandle_args
*args
)
23 debug("%s(chan=%p)\n", __func__
, chan
);
25 if (args
->args_count
!= 1) {
26 debug("Invaild args_count: %d\n", args
->args_count
);
30 chan
->id
= args
->args
[0];
35 int mbox_get_by_index(struct udevice
*dev
, int index
, struct mbox_chan
*chan
)
37 struct fdtdec_phandle_args args
;
39 struct udevice
*dev_mbox
;
42 debug("%s(dev=%p, index=%d, chan=%p)\n", __func__
, dev
, index
, chan
);
44 ret
= fdtdec_parse_phandle_with_args(gd
->fdt_blob
, dev
->of_offset
,
45 "mboxes", "#mbox-cells", 0,
48 debug("%s: fdtdec_parse_phandle_with_args failed: %d\n",
53 ret
= uclass_get_device_by_of_offset(UCLASS_MAILBOX
, args
.node
,
56 debug("%s: uclass_get_device_by_of_offset failed: %d\n",
60 ops
= mbox_dev_ops(dev_mbox
);
64 ret
= ops
->of_xlate(chan
, &args
);
66 ret
= mbox_of_xlate_default(chan
, &args
);
68 debug("of_xlate() failed: %d\n", ret
);
72 ret
= ops
->request(chan
);
74 debug("ops->request() failed: %d\n", ret
);
81 int mbox_get_by_name(struct udevice
*dev
, const char *name
,
82 struct mbox_chan
*chan
)
86 debug("%s(dev=%p, name=%s, chan=%p)\n", __func__
, dev
, name
, chan
);
88 index
= fdt_find_string(gd
->fdt_blob
, dev
->of_offset
, "mbox-names",
91 debug("fdt_find_string() failed: %d\n", index
);
95 return mbox_get_by_index(dev
, index
, chan
);
98 int mbox_free(struct mbox_chan
*chan
)
100 struct mbox_ops
*ops
= mbox_dev_ops(chan
->dev
);
102 debug("%s(chan=%p)\n", __func__
, chan
);
104 return ops
->free(chan
);
107 int mbox_send(struct mbox_chan
*chan
, const void *data
)
109 struct mbox_ops
*ops
= mbox_dev_ops(chan
->dev
);
111 debug("%s(chan=%p, data=%p)\n", __func__
, chan
, data
);
113 return ops
->send(chan
, data
);
116 int mbox_recv(struct mbox_chan
*chan
, void *data
, ulong timeout_us
)
118 struct mbox_ops
*ops
= mbox_dev_ops(chan
->dev
);
122 debug("%s(chan=%p, data=%p, timeout_us=%ld)\n", __func__
, chan
, data
,
125 start_time
= timer_get_us();
127 * Account for partial us ticks, but if timeout_us is 0, ensure we
128 * still don't wait at all.
134 ret
= ops
->recv(chan
, data
);
137 if ((timer_get_us() - start_time
) >= timeout_us
)
142 UCLASS_DRIVER(mailbox
) = {
143 .id
= UCLASS_MAILBOX
,