diff options
author | Lee Jones <lee.jones@linaro.org> | 2015-05-11 17:08:50 +0100 |
---|---|---|
committer | Jassi Brar <jaswinder.singh@linaro.org> | 2015-06-11 22:19:45 +0530 |
commit | dfabde206aa10ae71a89ba75e68b1f58a6336a05 (patch) | |
tree | 830d0e9e2b7ae1a090c02bd9d0293ccb011bdb90 /drivers/mailbox/mailbox.c | |
parent | 0bae6af6d704f026d4938739786e0a69d50177ca (diff) |
mailbox: Add ability for clients to request channels by name
This patch supplies a new framework API; mbox_request_channel_byname().
It works by supplying the usual client pointer as the first argument and
a string as the second. The API will search the client's node for a
'mbox-names' property then request a channel in the normal way using the
requested string's index as the expected second 'index' argument.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
Diffstat (limited to 'drivers/mailbox/mailbox.c')
-rw-r--r-- | drivers/mailbox/mailbox.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index c3c42d42d017..c7fdb57fd166 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -362,6 +362,35 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) } EXPORT_SYMBOL_GPL(mbox_request_channel); +struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, + const char *name) +{ + struct device_node *np = cl->dev->of_node; + struct property *prop; + const char *mbox_name; + int index = 0; + + if (!np) { + dev_err(cl->dev, "%s() currently only supports DT\n", __func__); + return ERR_PTR(-ENOSYS); + } + + if (!of_get_property(np, "mbox-names", NULL)) { + dev_err(cl->dev, + "%s() requires an \"mbox-names\" property\n", __func__); + return ERR_PTR(-ENOSYS); + } + + of_property_for_each_string(np, "mbox-names", prop, mbox_name) { + if (!strncmp(name, mbox_name, strlen(name))) + break; + index++; + } + + return mbox_request_channel(cl, index); +} +EXPORT_SYMBOL_GPL(mbox_request_channel_byname); + /** * mbox_free_channel - The client relinquishes control of a mailbox * channel by this call. |