Re: [PATCH v5 05/23] mailbox: Allow controller specific mapping using fwnode

From: Anup Patel
Date: Wed Jun 18 2025 - 00:09:10 EST


On Wed, Jun 11, 2025 at 9:05 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
>
> On Wed, Jun 11, 2025 at 11:52:20AM +0530, Anup Patel wrote:
> > 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.
>
> ...
>
> > struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
> > {
> > + struct fwnode_reference_args fwspec;
>
> Define
>
> struct fwnode_handle *fwnode;
>
>
> > struct device *dev = cl->dev;
>
> This better to be just a declaration.
>
> > struct mbox_controller *mbox;
> > struct of_phandle_args spec;
> > struct mbox_chan *chan;
> > + unsigned int i;
> > int ret;
>
> With the above the below will look like...
>
> > - if (!dev || !dev->of_node) {
> > - pr_debug("%s: No owner device node\n", __func__);
> > + if (!dev || !dev_fwnode(dev)) {
> > + pr_debug("No owner %s\n", dev ? "fwnode" : "device");
> > return ERR_PTR(-ENODEV);
> > }
> >
> > - ret = of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells",
> > - index, &spec);
> > + ret = fwnode_property_get_reference_args(dev_fwnode(dev), "mboxes",
> > + "#mbox-cells", 0, index, &fwspec);
> > if (ret) {
> > dev_err(dev, "%s: can't parse \"mboxes\" property\n", __func__);
> > return ERR_PTR(ret);
> > }
>
> ...this
>
> dev = cl->dev;
> if (!dev) {
> pr_debug("No owner device\n");
> return ERR_PTR(-ENODEV);
> }
>
> fwnode = dev_fwnode(dev);
> if (!fwnode) {
> dev_dbg(dev, "No owner fwnode\n");
> return ERR_PTR(-ENODEV);
> }
>
> ret = fwnode_property_get_reference_args(fwnode, "mboxes",
> "#mbox-cells", 0, index, &fwspec);
> if (ret) {
> dev_err(dev, "%s: can't parse \"mboxes\" property\n", __func__);
>
> You may save a few bytes by doing it as
>
> dev_err(dev, "%s: can't parse \"%s\" property\n", __func__, "mboxes");
>
> return ERR_PTR(ret);
> }
>
> > + spec.np = to_of_node(fwspec.fwnode);
> > + spec.args_count = fwspec.nargs;
> > + for (i = 0; i < spec.args_count; i++)
> > + spec.args[i] = fwspec.args[i];
> > +
> > scoped_guard(mutex, &con_mutex) {
> > chan = ERR_PTR(-EPROBE_DEFER);
> > - list_for_each_entry(mbox, &mbox_cons, node)
> > - if (mbox->dev->of_node == spec.np) {
> > + list_for_each_entry(mbox, &mbox_cons, node) {
>
> > + if (mbox->fw_xlate && dev_fwnode(mbox->dev) == fwspec.fwnode) {
>
> We have a helper device_match_fwnode()
>
> > + chan = mbox->fw_xlate(mbox, &fwspec);
> > + if (!IS_ERR(chan))
> > + break;
> > + } else if (mbox->of_xlate && mbox->dev->of_node == spec.np) {
>
> No need to check OF node (again). Instead refactor as
>
> if (device_match_fwnode(...)) {
> if (fw_xlate) {
> ...
> } else if (of_xlate) {
> ...
> }
> }
>

Okay, I will update like you suggested.

Regards,
Anup