Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp992915imm; Fri, 11 May 2018 09:24:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo8ETtm5ALueTxYwoL8b6T6haQxYnO81VeIThajueNRQgZMD4yItRafBEFUTfHUaelwFwKZ X-Received: by 2002:a62:568f:: with SMTP id h15-v6mr6164196pfj.131.1526055880092; Fri, 11 May 2018 09:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526055880; cv=none; d=google.com; s=arc-20160816; b=d3wwvKdNf8A/XkcmShvSOCdaFyxBJKVFL6d3yFX5C4pKe23OJdW3c2C4wMFIPLrKjd afazmsjvQkQtt/iP6tmVOvUu/BsaB1FwMdlYaqqz7QG74BNdDatEjeHQvBMn9kkbZz/6 iJnOxjoiODRLllt5Fo/kSl6B4SAddyz5QvCKnaesN51ZjS39DOixXAmLSZP0mUG0Hqfs 5BnqDzKDrqe39W1uPBYSRrjT5vK990ipJq6XDOQpYGxjK9vxUbDd9/nU+4P03oPyExU/ TX60I5fGlpWdZojQqYKdgQuugCgQDuyAODmaWcRmOAeETvh2yhqiPQ9KHNkE3tbysqEZ /RLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=PPNBeHEVM4bty8bTLpU82Dny7zq6HjBV/Zr9vUd6vqc=; b=ufUf0wNuyRXV5OKafA83jLg09oPkqnGN2puid7CzqnjySSj4CfexRTXYy8aSBkLD8M E9KYYawkopk1/JzzxYmfSjMKKPIX0DhPl+XLQXAGHGW0n1cVuZUjx3thSaf1FZ2JP1a5 ZFplWRBrW2CX0R7Z57zXrmVAfydZOn/xOIEUSphhMu7cRaTB2HcyNoJeO6YaTILfDL7M gNzMQkpPNyTjuRnaOEgSrLBNM4bwbUMxl4DX2FmnmGBRyY387nVbSnQ6XS31pTNQa7iM WifQq87edLsXWeJfXMTg43GbDIzWYcRj/ctEduhrAbIboo/Q2yAtKMZk1qfzLqxqAoup ZhFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=OZUsq7dG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j20-v6si3598437pfa.57.2018.05.11.09.24.24; Fri, 11 May 2018 09:24:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=OZUsq7dG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752398AbeEKQXU (ORCPT + 99 others); Fri, 11 May 2018 12:23:20 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:52382 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752157AbeEKQVk (ORCPT ); Fri, 11 May 2018 12:21:40 -0400 Received: by mail-wm0-f66.google.com with SMTP id w194-v6so3535919wmf.2 for ; Fri, 11 May 2018 09:21:39 -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=qsCqUF2eTMFFsEl0xvf4AvTFrAtNtAJikqdXuXPXdU2UgXlpr4Lm7cnCA3QKUZe8Bf KPteqWHNXYZ9NQXB7+aKyP8RDOovjQrnZxbtHLdranFdHOCt8axD/RDPtuvqqVqvOmY/ fmitABxeCQISubFXuTd698GBbrDoJ/dPlflX2a+REKFPcP9UM4i3JecyKlqT8YH0s+Wa mYabFbJgjq1FLzN5htj8nkTer+Toj588/l+FqYZ2CJB3ERBFsG4OrE2noUk1H9P1dC1A j9OE3y1hv8R1WQ7H7eZ8zZF1YBiUybwbQAMfJGsa5938mT1HTAMLHS5eZcd1IgISnq1T kkNQ== X-Gm-Message-State: ALKqPwd9A5WwyxAxPtFI6U8JqLVGQKSi4KRbqqcbIcuYGCv1Rs78bRiu yMg6TT7fuKQffcJdJ6rIzuQQKA== 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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