From patchwork Fri May 11 16:20:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 912068 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="OZUsq7dG"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40jFlr555Qz9ry1 for ; Sat, 12 May 2018 02:24:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752155AbeEKQXT (ORCPT ); Fri, 11 May 2018 12:23:19 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:52384 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752158AbeEKQVk (ORCPT ); Fri, 11 May 2018 12:21:40 -0400 Received: by mail-wm0-f68.google.com with SMTP id w194-v6so3535921wmf.2 for ; Fri, 11 May 2018 09:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PPNBeHEVM4bty8bTLpU82Dny7zq6HjBV/Zr9vUd6vqc=; b=OZUsq7dGtPZjjvw+NxnWdfA0/hzOftYYAd023Zx0UHRwJkB0WEXXegiPjwXHT2qRNi ozVl753NgE1b5oRatcaZIOARjJXHnpU58lSYbXGpHgsIgCQ49PaP3BOyioAxwSMNaDo9 RWW7xT0h5BHxi5OWqo0/ixhhLnge9DwuhuvpONQ1FnGRnHFfsgRZjNPVreU8FRrGob6c gGeyN1HFjTHZJJsy9qrSaxFJCnwXRdX0HSJE8xFhzEstHrOo2VHh/RZ5rGKUyAfnTTqX wLwTWVJxXyws7Gj/MUa9jZH+TQkMo3w2A3OdBJf6OCQiiWzrc7Gwn7Qy6g9UA8UHGcik 0CeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PPNBeHEVM4bty8bTLpU82Dny7zq6HjBV/Zr9vUd6vqc=; b=rIgTcAXaG+VO2XVLmH30YivVp114rwA4/AE4vNzb99tUIQRsRuuZZVZ3KtIVh21RHU ZGTHSk8UFUp/Wy1iHnB3ORoOvl85qBjcjoE4UeiV2+eVta00qxCamOItli+VF/838Ne1 fdJ+GrHwda7Rvh8aDtJZ2w80mBkjWbOmp2Ys/K7MA19nSq09gMiXkZtZ1prspsUbCvgG PWo2ZL6Dl1V1gnQYnJ2m6QSyDmUg43ba/Xkox2P6RIxzYL1Kc9+O54blCmxuQMz1Pu72 jo2IOxMoqkM4rWASG7mEG3/9ML0lGC4TKQTvryq/xdYBVaeSzXFJ+H2hO+YVvZj4oZ43 +JQg== X-Gm-Message-State: ALKqPwcMuXGstQnT+gQFL3VgqDU19uh3K7mPJgKJZ/Lgr+DqsgtdGav4 ojhIlvahxoSrhVCKXnKuH7zxQw== X-Google-Smtp-Source: AB8JxZrAgmPhohulf1wo8K2OuEVURyLaxaESV6FZvzYdD6E+26mvWltlQT8D+OwrTOf4ZZ6zWHckAA== X-Received: by 2002:a1c:9186:: with SMTP id t128-v6mr2528043wmd.41.1526055699191; Fri, 11 May 2018 09:21:39 -0700 (PDT) Received: from brgl-bgdev.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id q17-v6sm1429523wmf.3.2018.05.11.09.21.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 09:21:38 -0700 (PDT) From: Bartosz Golaszewski To: Sekhar Nori , Kevin Hilman , David Lechner , Michael Turquette , Stephen Boyd , Arnd Bergmann , Greg Kroah-Hartman , Mark Rutland , Yoshinori Sato , Rich Felker , Andy Shevchenko , Marc Zyngier , "Rafael J . Wysocki" , Peter Rosin , Jiri Slaby , Thomas Gleixner , Daniel Lezcano , Geert Uytterhoeven , Magnus Damm , Johan Hovold , Rob Herring , Frank Rowand Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 07/12] of/platform: provide a separate routine for setting up device resources Date: Fri, 11 May 2018 18:20:23 +0200 Message-Id: <20180511162028.20616-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511162028.20616-1-brgl@bgdev.pl> References: <20180511162028.20616-1-brgl@bgdev.pl> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Bartosz Golaszewski 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 Reviewed-by: Geert Uytterhoeven --- 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