]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
firmware: tegra: bpmp: Add tegra_bpmp_get_with_id() function
authorThierry Reding <treding@nvidia.com>
Thu, 26 Mar 2026 13:58:49 +0000 (14:58 +0100)
committerThierry Reding <treding@nvidia.com>
Fri, 27 Mar 2026 15:24:36 +0000 (16:24 +0100)
Some device tree bindings need to specify a parameter along with a BPMP
phandle reference to designate the ID associated with a given controller
that needs to interoperate with BPMP. Typically this is specified as an
extra cell in the nvidia,bpmp property, so add a helper to parse this ID
while resolving the phandle reference.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/firmware/tegra/bpmp.c
include/soc/tegra/bpmp.h

index e74bba7ccc4431d167b90a76576ef9c87b1d90b6..753472b53bd84952391833780a48b583d61a8c0a 100644 (file)
@@ -32,6 +32,40 @@ channel_to_ops(struct tegra_bpmp_channel *channel)
        return bpmp->soc->ops;
 }
 
+struct tegra_bpmp *tegra_bpmp_get_with_id(struct device *dev, unsigned int *id)
+{
+       struct platform_device *pdev;
+       struct of_phandle_args args;
+       struct tegra_bpmp *bpmp;
+       int err;
+
+       err = __of_parse_phandle_with_args(dev->of_node, "nvidia,bpmp", NULL,
+                                          1, 0, &args);
+       if (err < 0)
+               return ERR_PTR(err);
+
+       pdev = of_find_device_by_node(args.np);
+       if (!pdev) {
+               bpmp = ERR_PTR(-ENODEV);
+               goto put;
+       }
+
+       bpmp = platform_get_drvdata(pdev);
+       if (!bpmp) {
+               bpmp = ERR_PTR(-EPROBE_DEFER);
+               put_device(&pdev->dev);
+               goto put;
+       }
+
+       if (id)
+               *id = args.args[0];
+
+put:
+       of_node_put(args.np);
+       return bpmp;
+}
+EXPORT_SYMBOL_GPL(tegra_bpmp_get_with_id);
+
 struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
 {
        struct platform_device *pdev;
index f5e4ac5b8cce8961455a51d7151493d429549863..822851ef4bf8817291c5409accb1b7d3de76005a 100644 (file)
@@ -127,6 +127,7 @@ struct tegra_bpmp_message {
 
 #if IS_ENABLED(CONFIG_TEGRA_BPMP)
 struct tegra_bpmp *tegra_bpmp_get(struct device *dev);
+struct tegra_bpmp *tegra_bpmp_get_with_id(struct device *dev, unsigned int *id);
 void tegra_bpmp_put(struct tegra_bpmp *bpmp);
 int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
                               struct tegra_bpmp_message *msg);
@@ -145,6 +146,13 @@ static inline struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
 {
        return ERR_PTR(-ENOTSUPP);
 }
+
+static inline struct tegra_bpmp *tegra_bpmp_get_with_id(struct device *dev,
+                                                       unsigned int *id)
+{
+       return ERR_PTR(-ENODEV);
+}
+
 static inline void tegra_bpmp_put(struct tegra_bpmp *bpmp)
 {
 }