diff options
Diffstat (limited to 'drivers/mailbox/mailbox.c')
-rw-r--r-- | drivers/mailbox/mailbox.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 19b491d2964f..c7fdb57fd166 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c | |||
@@ -318,7 +318,7 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) | |||
318 | return ERR_PTR(-ENODEV); | 318 | return ERR_PTR(-ENODEV); |
319 | } | 319 | } |
320 | 320 | ||
321 | chan = NULL; | 321 | chan = ERR_PTR(-EPROBE_DEFER); |
322 | list_for_each_entry(mbox, &mbox_cons, node) | 322 | list_for_each_entry(mbox, &mbox_cons, node) |
323 | if (mbox->dev->of_node == spec.np) { | 323 | if (mbox->dev->of_node == spec.np) { |
324 | chan = mbox->of_xlate(mbox, &spec); | 324 | chan = mbox->of_xlate(mbox, &spec); |
@@ -327,7 +327,12 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) | |||
327 | 327 | ||
328 | of_node_put(spec.np); | 328 | of_node_put(spec.np); |
329 | 329 | ||
330 | if (!chan || chan->cl || !try_module_get(mbox->dev->driver->owner)) { | 330 | if (IS_ERR(chan)) { |
331 | mutex_unlock(&con_mutex); | ||
332 | return chan; | ||
333 | } | ||
334 | |||
335 | if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { | ||
331 | dev_dbg(dev, "%s: mailbox not free\n", __func__); | 336 | dev_dbg(dev, "%s: mailbox not free\n", __func__); |
332 | mutex_unlock(&con_mutex); | 337 | mutex_unlock(&con_mutex); |
333 | return ERR_PTR(-EBUSY); | 338 | return ERR_PTR(-EBUSY); |
@@ -357,6 +362,35 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) | |||
357 | } | 362 | } |
358 | EXPORT_SYMBOL_GPL(mbox_request_channel); | 363 | EXPORT_SYMBOL_GPL(mbox_request_channel); |
359 | 364 | ||
365 | struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, | ||
366 | const char *name) | ||
367 | { | ||
368 | struct device_node *np = cl->dev->of_node; | ||
369 | struct property *prop; | ||
370 | const char *mbox_name; | ||
371 | int index = 0; | ||
372 | |||
373 | if (!np) { | ||
374 | dev_err(cl->dev, "%s() currently only supports DT\n", __func__); | ||
375 | return ERR_PTR(-ENOSYS); | ||
376 | } | ||
377 | |||
378 | if (!of_get_property(np, "mbox-names", NULL)) { | ||
379 | dev_err(cl->dev, | ||
380 | "%s() requires an \"mbox-names\" property\n", __func__); | ||
381 | return ERR_PTR(-ENOSYS); | ||
382 | } | ||
383 | |||
384 | of_property_for_each_string(np, "mbox-names", prop, mbox_name) { | ||
385 | if (!strncmp(name, mbox_name, strlen(name))) | ||
386 | break; | ||
387 | index++; | ||
388 | } | ||
389 | |||
390 | return mbox_request_channel(cl, index); | ||
391 | } | ||
392 | EXPORT_SYMBOL_GPL(mbox_request_channel_byname); | ||
393 | |||
360 | /** | 394 | /** |
361 | * mbox_free_channel - The client relinquishes control of a mailbox | 395 | * mbox_free_channel - The client relinquishes control of a mailbox |
362 | * channel by this call. | 396 | * channel by this call. |
@@ -390,7 +424,7 @@ of_mbox_index_xlate(struct mbox_controller *mbox, | |||
390 | int ind = sp->args[0]; | 424 | int ind = sp->args[0]; |
391 | 425 | ||
392 | if (ind >= mbox->num_chans) | 426 | if (ind >= mbox->num_chans) |
393 | return NULL; | 427 | return ERR_PTR(-EINVAL); |
394 | 428 | ||
395 | return &mbox->chans[ind]; | 429 | return &mbox->chans[ind]; |
396 | } | 430 | } |