From nobody Tue Dec 23 14:14:45 2025 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA128275AEB for ; Fri, 4 Jul 2025 07:05:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751612715; cv=none; b=sITObs6P/brCKJIdTejWE68QHnYWn6lGzSPZ7wGNAsnYsqYLMaXmGSeLqaUslZ31R8leFSNbHZEwFMjzWEMsfuszq2QPrYSa0FNQfEyKJSJiBoh7fp2p1BFVDfcpkqXN0xYhpKz4wjhnXXCsIv9uuPIxal8003bVUC8uXh/ino8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751612715; c=relaxed/simple; bh=eP0nLjelGbOd1owGOdUwIHJWAQpQfBfflyMTXkP8FKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gsviB65a6SJ3TbksbCqLJ55WHSsE+gkoXoIb3YxgD3KyelHnEywAIc1dquD7V+NjS1xkR6pMo3KuyP81ww8ECQQi4Fde/r+iMC4MaY1VMyxGF488yjglZKKNFIkQKIEuSnE8ykjfUCfAo8QiUkIUKmsBinuKOGhGCkxgyISPUCc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=DYsfgCY+; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="DYsfgCY+" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-3122368d7cfso521566a91.1 for ; Fri, 04 Jul 2025 00:05:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1751612713; x=1752217513; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oP6ThGaZGs8MyIgO+nprUM8QR3vfVMjtp+0dcAYkEZA=; b=DYsfgCY+wbM9oecZ3bbLLI2XQ+lq3kCUS6NTEX94U9W3c9CKwH0BGk06fqyUwYGNhD X8tY07p0l4wcsWt4m+L31alM1JSyXrPW4ykfJFZuWbTQic3GM+uPJycNMMcKxh0piyx9 oE6Vya9Luvqgm8e+lZmFurTVYqvU/vYVUb6+PuM258F4PumFbNuHeY2VJRN64p6Ynipf 3YZHcbg0NJWtRGhlqrx57w+vLJN7VoMLrhcU+/zz92ewTsxkjNqhLjgIucEHAS1KtYM+ 6XJun5NENi2zv4zqzRBG6rpkiKsAxLqTEA8eAlu+P364HYt/TaqqXx4NfQ8iLw56nNj4 xpfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751612713; x=1752217513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oP6ThGaZGs8MyIgO+nprUM8QR3vfVMjtp+0dcAYkEZA=; b=F6Gtqz8fTPpOEX9yhdQ8NPcucnm0ZLT8EgcroN0X433/CgeRkeJOk8w+FuhBE3g+Xn tCemyL0u0QuKm3WgQU3UGXPvGWLQSY3D3Kq7rikxim5cLzEYhRcbfwab2DL/FSVbFrgK bGMMD4svX2a8uMNUrbYvPO+MIUgPpCkh2dwweraYppYd4PEuEKDI2AkI0z08FgACzj7L 4Nr51y/xPseThETev/3exBlQxt5QjASiWWVJQHAG9i35/+1iMjDYUeRKLJOJ26YF1Hxu qtCo8YQnYIFK6hvBl87lj1nKMqEdnaakmQTIlBU/rrV5M40tvg/WjwkJwuIDeNbYEZ3Q XNdw== X-Forwarded-Encrypted: i=1; AJvYcCWR1pQ+h8SkF5Sr576jEKE1b00f8hrm6ymiFTIdJd+bYJo0wEBsQR+agPjjR5QkuAjvtwXoL+LMxroDXBs=@vger.kernel.org X-Gm-Message-State: AOJu0YwG5W1XPE6XkEzuKqWnB+WgZcxINDzm8wffEaBeWl2sqrV+slGB z0Aqcd7uLxTBNKcg8WI5FUUTCV7Ua1fWKe83Ulqvb2DP9oDcPbHCNwe5hIxY5H8U6vM= X-Gm-Gg: ASbGncteBqFhgeASgh26gPEQI208+O8KKNXH3Bvxgd0LvFyomKuR60NYCv8kZKptsMh 3MlDq9YbWywnWjpKho18/RgKochiaRg8E1iSOM+lfLeMiyWgMvO7pd+lNElBGhBn9N9bHr2cBLI PcSQyx4d2bote+mv/FxMT5gwkvQq29wJ249BUzWCLWQF+RW5D/oHTAJ0YW8vy3gZamFY6QYMfFW xO4Q6TO2kVaLJfBLzw57JgboOfX+pTb6CmVAgIhLPvjPIej8qsM2UzlkOCmOZh5EjOJBNyAZedS HQCd6J5o8xbvNHy6DEB12FfY+2tMLg9aOyNFe1yS71EXRDyup3sX1vXLMl7G7SDfwDbeIVLimtO izdN7MaBmfUoIMLTvvE0mFpE6Vny7PgbKgaA4 X-Google-Smtp-Source: AGHT+IHi9rVu5CdAwKebMT1+NvqjKYD4zSk3DhlfFOzizsRoQJO/I4guA1z3PM0Z8s+uXhbtEpdKbQ== X-Received: by 2002:a17:90b:180f:b0:315:9cae:bd8 with SMTP id 98e67ed59e1d1-31aac4f05f6mr1880490a91.23.1751612712917; Fri, 04 Jul 2025 00:05:12 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31aaae59a93sm1358697a91.12.2025.07.04.00.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 00:05:12 -0700 (PDT) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar , Thomas Gleixner , "Rafael J . Wysocki" , Mika Westerberg , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: Palmer Dabbelt , Paul Walmsley , Alexandre Ghiti , Len Brown , Sunil V L , Rahul Pathak , Leyfoon Tan , Atish Patra , Andrew Jones , Samuel Holland , Anup Patel , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v8 05/24] mailbox: Allow controller specific mapping using fwnode Date: Fri, 4 Jul 2025 12:33:37 +0530 Message-ID: <20250704070356.1683992-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704070356.1683992-1-apatel@ventanamicro.com> References: <20250704070356.1683992-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Anup Patel --- drivers/mailbox/mailbox.c | 65 ++++++++++++++++++------------ include/linux/mailbox_controller.h | 3 ++ 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 5cd8ae222073..2acc6ec229a4 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -15,6 +15,7 @@ #include #include #include +#include #include =20 #include "mailbox.h" @@ -383,34 +384,56 @@ EXPORT_SYMBOL_GPL(mbox_bind_client); */ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) { - struct device *dev =3D cl->dev; + struct fwnode_reference_args fwspec; + struct fwnode_handle *fwnode; struct mbox_controller *mbox; struct of_phandle_args spec; struct mbox_chan *chan; + struct device *dev; + unsigned int i; int ret; =20 - if (!dev || !dev->of_node) { - pr_debug("%s: No owner device node\n", __func__); + dev =3D cl->dev; + if (!dev) { + pr_debug("No owner device\n"); return ERR_PTR(-ENODEV); } =20 - ret =3D of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells", - index, &spec); + fwnode =3D dev_fwnode(dev); + if (!fwnode) { + dev_dbg(dev, "No owner fwnode\n"); + return ERR_PTR(-ENODEV); + } + + ret =3D 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__); + dev_err(dev, "%s: can't parse \"%s\" property\n", __func__, "mboxes"); return ERR_PTR(ret); } =20 + spec.np =3D to_of_node(fwspec.fwnode); + spec.args_count =3D fwspec.nargs; + for (i =3D 0; i < spec.args_count; i++) + spec.args[i] =3D fwspec.args[i]; + scoped_guard(mutex, &con_mutex) { chan =3D ERR_PTR(-EPROBE_DEFER); - list_for_each_entry(mbox, &mbox_cons, node) - if (mbox->dev->of_node =3D=3D spec.np) { - chan =3D mbox->of_xlate(mbox, &spec); - if (!IS_ERR(chan)) - break; + list_for_each_entry(mbox, &mbox_cons, node) { + if (device_match_fwnode(mbox->dev, fwspec.fwnode)) { + if (mbox->fw_xlate) { + chan =3D mbox->fw_xlate(mbox, &fwspec); + if (!IS_ERR(chan)) + break; + } else if (mbox->of_xlate) { + chan =3D mbox->of_xlate(mbox, &spec); + if (!IS_ERR(chan)) + break; + } } + } =20 - of_node_put(spec.np); + fwnode_handle_put(fwspec.fwnode); =20 if (IS_ERR(chan)) return chan; @@ -427,15 +450,8 @@ EXPORT_SYMBOL_GPL(mbox_request_channel); struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, const char *name) { - struct device_node *np =3D cl->dev->of_node; - int index; - - if (!np) { - dev_err(cl->dev, "%s() currently only supports DT\n", __func__); - return ERR_PTR(-EINVAL); - } + int index =3D device_property_match_string(cl->dev, "mbox-names", name); =20 - index =3D of_property_match_string(np, "mbox-names", name); if (index < 0) { dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n", __func__, name); @@ -470,9 +486,8 @@ void mbox_free_channel(struct mbox_chan *chan) } EXPORT_SYMBOL_GPL(mbox_free_channel); =20 -static struct mbox_chan * -of_mbox_index_xlate(struct mbox_controller *mbox, - const struct of_phandle_args *sp) +static struct mbox_chan *fw_mbox_index_xlate(struct mbox_controller *mbox, + const struct fwnode_reference_args *sp) { int ind =3D sp->args[0]; =20 @@ -523,8 +538,8 @@ int mbox_controller_register(struct mbox_controller *mb= ox) spin_lock_init(&chan->lock); } =20 - if (!mbox->of_xlate) - mbox->of_xlate =3D of_mbox_index_xlate; + if (!mbox->fw_xlate && !mbox->of_xlate) + mbox->fw_xlate =3D fw_mbox_index_xlate; =20 scoped_guard(mutex, &con_mutex) list_add_tail(&mbox->node, &mbox_cons); diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_con= troller.h index ad01c4082358..80a427c7ca29 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -66,6 +66,7 @@ struct mbox_chan_ops { * no interrupt rises. Ignored if 'txdone_irq' is set. * @txpoll_period: If 'txdone_poll' is in effect, the API polls for * last TX's status after these many millisecs + * @fw_xlate: Controller driver specific mapping of channel via fwnode * @of_xlate: Controller driver specific mapping of channel via DT * @poll_hrt: API private. hrtimer used to poll for TXDONE on all * channels. @@ -79,6 +80,8 @@ struct mbox_controller { bool txdone_irq; bool txdone_poll; unsigned txpoll_period; + struct mbox_chan *(*fw_xlate)(struct mbox_controller *mbox, + const struct fwnode_reference_args *sp); struct mbox_chan *(*of_xlate)(struct mbox_controller *mbox, const struct of_phandle_args *sp); /* Internal to API */ --=20 2.43.0