[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180511162028.20616-8-brgl@bgdev.pl>
Date: Fri, 11 May 2018 18:20:23 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Sekhar Nori <nsekhar@...com>, Kevin Hilman <khilman@...nel.org>,
David Lechner <david@...hnology.com>,
Michael Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...nel.org>, Arnd Bergmann <arnd@...db.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Mark Rutland <mark.rutland@....com>,
Yoshinori Sato <ysato@...rs.sourceforge.jp>,
Rich Felker <dalias@...c.org>,
Andy Shevchenko <andy.shevchenko@...il.com>,
Marc Zyngier <marc.zyngier@....com>,
"Rafael J . Wysocki" <rafael.j.wysocki@...el.com>,
Peter Rosin <peda@...ntia.se>, Jiri Slaby <jslaby@...e.com>,
Thomas Gleixner <tglx@...utronix.de>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Magnus Damm <magnus.damm@...il.com>,
Johan Hovold <johan@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Frank Rowand <frowand.list@...il.com>
Cc: linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
devicetree@...r.kernel.org, linux-arch@...r.kernel.org,
Bartosz Golaszewski <bgolaszewski@...libre.com>
Subject: [PATCH 07/12] of/platform: provide a separate routine for setting up device resources
From: Bartosz Golaszewski <bgolaszewski@...libre.com>
The early platform driver framework will need to setup the device
resources before the regular populating of the device tree happens.
Provide a separate function for that.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@...libre.com>
---
drivers/of/platform.c | 54 +++++++++++++++++++++++--------------
include/linux/of_platform.h | 2 ++
2 files changed, 36 insertions(+), 20 deletions(-)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index c00d81dfac0b..24791e558ec5 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -99,24 +99,12 @@ static void of_device_make_bus_id(struct device *dev)
}
}
-/**
- * of_device_alloc - Allocate and initialize an of_device
- * @np: device node to assign to device
- * @bus_id: Name to assign to the device. May be null to use default name.
- * @parent: Parent device.
- */
-struct platform_device *of_device_alloc(struct device_node *np,
- const char *bus_id,
- struct device *parent)
+int of_device_init_resources(struct platform_device *pdev,
+ struct device_node *np)
{
- struct platform_device *dev;
int rc, i, num_reg = 0, num_irq;
struct resource *res, temp_res;
- dev = platform_device_alloc("", PLATFORM_DEVID_NONE);
- if (!dev)
- return NULL;
-
/* count the io and irq resources */
while (of_address_to_resource(np, num_reg, &temp_res) == 0)
num_reg++;
@@ -125,22 +113,48 @@ struct platform_device *of_device_alloc(struct device_node *np,
/* Populate the resource table */
if (num_irq || num_reg) {
res = kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL);
- if (!res) {
- platform_device_put(dev);
- return NULL;
- }
+ if (!res)
+ return -ENOMEM;
+
+ pdev->num_resources = num_reg + num_irq;
+ pdev->resource = res;
- dev->num_resources = num_reg + num_irq;
- dev->resource = res;
for (i = 0; i < num_reg; i++, res++) {
rc = of_address_to_resource(np, i, res);
WARN_ON(rc);
}
+
if (of_irq_to_resource_table(np, res, num_irq) != num_irq)
pr_debug("not all legacy IRQ resources mapped for %s\n",
np->name);
}
+ return 0;
+}
+
+/**
+ * of_device_alloc - Allocate and initialize an of_device
+ * @np: device node to assign to device
+ * @bus_id: Name to assign to the device. May be null to use default name.
+ * @parent: Parent device.
+ */
+struct platform_device *of_device_alloc(struct device_node *np,
+ const char *bus_id,
+ struct device *parent)
+{
+ struct platform_device *dev;
+ int rc;
+
+ dev = platform_device_alloc("", PLATFORM_DEVID_NONE);
+ if (!dev)
+ return NULL;
+
+ rc = of_device_init_resources(dev, np);
+ if (rc) {
+ platform_device_put(dev);
+ return NULL;
+ }
+
dev->dev.of_node = of_node_get(np);
dev->dev.fwnode = &np->fwnode;
dev->dev.parent = parent ? : &platform_bus;
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 84a966623e78..387ab4d4a210 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -52,6 +52,8 @@ extern const struct of_device_id of_default_bus_match_table[];
extern struct platform_device *of_device_alloc(struct device_node *np,
const char *bus_id,
struct device *parent);
+extern int of_device_init_resources(struct platform_device *pdev,
+ struct device_node *np);
#ifdef CONFIG_OF
extern struct platform_device *of_find_device_by_node(struct device_node *np);
#else
--
2.17.0
Powered by blists - more mailing lists