Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mailbox: Allow controller specific mapping using fwnode

Introduce optional fw_node() callback which allows a mailbox controller
driver to provide controller specific mapping using fwnode.

The Linux OF framework already implements fwnode operations for the
Linux DD framework so the fw_xlate() callback works fine with device
tree as well.

Acked-by: Jassi Brar <jassisinghbrar@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Link: https://lore.kernel.org/r/20250818040920.272664-6-apatel@ventanamicro.com
Signed-off-by: Paul Walmsley <pjw@kernel.org>

authored by

Anup Patel and committed by
Paul Walmsley
ba879dfc 340974c4

+43 -25
+40 -25
drivers/mailbox/mailbox.c
··· 15 15 #include <linux/module.h> 16 16 #include <linux/mutex.h> 17 17 #include <linux/of.h> 18 + #include <linux/property.h> 18 19 #include <linux/spinlock.h> 19 20 20 21 #include "mailbox.h" ··· 384 383 */ 385 384 struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) 386 385 { 387 - struct device *dev = cl->dev; 386 + struct fwnode_reference_args fwspec; 387 + struct fwnode_handle *fwnode; 388 388 struct mbox_controller *mbox; 389 389 struct of_phandle_args spec; 390 390 struct mbox_chan *chan; 391 + struct device *dev; 392 + unsigned int i; 391 393 int ret; 392 394 393 - if (!dev || !dev->of_node) { 394 - pr_debug("%s: No owner device node\n", __func__); 395 + dev = cl->dev; 396 + if (!dev) { 397 + pr_debug("No owner device\n"); 395 398 return ERR_PTR(-ENODEV); 396 399 } 397 400 398 - ret = of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells", 399 - index, &spec); 401 + fwnode = dev_fwnode(dev); 402 + if (!fwnode) { 403 + dev_dbg(dev, "No owner fwnode\n"); 404 + return ERR_PTR(-ENODEV); 405 + } 406 + 407 + ret = fwnode_property_get_reference_args(fwnode, "mboxes", "#mbox-cells", 408 + 0, index, &fwspec); 400 409 if (ret) { 401 - dev_err(dev, "%s: can't parse \"mboxes\" property\n", __func__); 410 + dev_err(dev, "%s: can't parse \"%s\" property\n", __func__, "mboxes"); 402 411 return ERR_PTR(ret); 403 412 } 404 413 414 + spec.np = to_of_node(fwspec.fwnode); 415 + spec.args_count = fwspec.nargs; 416 + for (i = 0; i < spec.args_count; i++) 417 + spec.args[i] = fwspec.args[i]; 418 + 405 419 scoped_guard(mutex, &con_mutex) { 406 420 chan = ERR_PTR(-EPROBE_DEFER); 407 - list_for_each_entry(mbox, &mbox_cons, node) 408 - if (mbox->dev->of_node == spec.np) { 409 - chan = mbox->of_xlate(mbox, &spec); 410 - if (!IS_ERR(chan)) 411 - break; 421 + list_for_each_entry(mbox, &mbox_cons, node) { 422 + if (device_match_fwnode(mbox->dev, fwspec.fwnode)) { 423 + if (mbox->fw_xlate) { 424 + chan = mbox->fw_xlate(mbox, &fwspec); 425 + if (!IS_ERR(chan)) 426 + break; 427 + } else if (mbox->of_xlate) { 428 + chan = mbox->of_xlate(mbox, &spec); 429 + if (!IS_ERR(chan)) 430 + break; 431 + } 412 432 } 433 + } 413 434 414 - of_node_put(spec.np); 435 + fwnode_handle_put(fwspec.fwnode); 415 436 416 437 if (IS_ERR(chan)) 417 438 return chan; ··· 450 427 struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, 451 428 const char *name) 452 429 { 453 - struct device_node *np = cl->dev->of_node; 454 - int index; 430 + int index = device_property_match_string(cl->dev, "mbox-names", name); 455 431 456 - if (!np) { 457 - dev_err(cl->dev, "%s() currently only supports DT\n", __func__); 458 - return ERR_PTR(-EINVAL); 459 - } 460 - 461 - index = of_property_match_string(np, "mbox-names", name); 462 432 if (index < 0) { 463 433 dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n", 464 434 __func__, name); ··· 486 470 } 487 471 EXPORT_SYMBOL_GPL(mbox_free_channel); 488 472 489 - static struct mbox_chan * 490 - of_mbox_index_xlate(struct mbox_controller *mbox, 491 - const struct of_phandle_args *sp) 473 + static struct mbox_chan *fw_mbox_index_xlate(struct mbox_controller *mbox, 474 + const struct fwnode_reference_args *sp) 492 475 { 493 476 int ind = sp->args[0]; 494 477 ··· 538 523 spin_lock_init(&chan->lock); 539 524 } 540 525 541 - if (!mbox->of_xlate) 542 - mbox->of_xlate = of_mbox_index_xlate; 526 + if (!mbox->fw_xlate && !mbox->of_xlate) 527 + mbox->fw_xlate = fw_mbox_index_xlate; 543 528 544 529 scoped_guard(mutex, &con_mutex) 545 530 list_add_tail(&mbox->node, &mbox_cons);
+3
include/linux/mailbox_controller.h
··· 66 66 * no interrupt rises. Ignored if 'txdone_irq' is set. 67 67 * @txpoll_period: If 'txdone_poll' is in effect, the API polls for 68 68 * last TX's status after these many millisecs 69 + * @fw_xlate: Controller driver specific mapping of channel via fwnode 69 70 * @of_xlate: Controller driver specific mapping of channel via DT 70 71 * @poll_hrt: API private. hrtimer used to poll for TXDONE on all 71 72 * channels. ··· 80 79 bool txdone_irq; 81 80 bool txdone_poll; 82 81 unsigned txpoll_period; 82 + struct mbox_chan *(*fw_xlate)(struct mbox_controller *mbox, 83 + const struct fwnode_reference_args *sp); 83 84 struct mbox_chan *(*of_xlate)(struct mbox_controller *mbox, 84 85 const struct of_phandle_args *sp); 85 86 /* Internal to API */