From patchwork Thu Sep 17 12:56:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7207181 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 326C39F380 for ; Thu, 17 Sep 2015 13:11:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 423692084B for ; Thu, 17 Sep 2015 13:11:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC8AB208AC for ; Thu, 17 Sep 2015 13:11:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZcYwy-0007ou-92; Thu, 17 Sep 2015 13:10:08 +0000 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZcYlJ-0006jk-J7 for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2015 12:58:06 +0000 Received: by wiclk2 with SMTP id lk2so26203760wic.1 for ; Thu, 17 Sep 2015 05:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=CQOMpZyyfOy1IMYqFhRzh3Pm1H22bDJCj4gRG6pWqug=; b=Mpbp1T3xo7AwDGCOsE2fueZSd+EDkMPy1nUAIq0s8gG0ZsJQRchKYlV29lI3XQMJVQ CAZ+TfmTSIuzQYcmyMCKzjyg9cwm3lA+UB/14b6v43fzd3z8A+7RPrKZoEEgJ9l1kHBe kdbRntdFIfIpKqtKj5PmdDKodPs5YLtaBU1k0a9NXlIpvOSCg6iEB82wMfml1vHHazdU iC5zGSvRzeDRyOIzlTfNxVJrdP5FLCo9gh48Xo5B8d9fVKDTm741n+g6DHu80EV9w4Vw Tl9U96C5SYIZvCLhzprahCyVo23CXhJmunOhvj8JRXdDI5a7giKO3xeyWFIINyfGYQGY m7iw== X-Received: by 10.181.27.138 with SMTP id jg10mr30698950wid.29.1442494664324; Thu, 17 Sep 2015 05:57:44 -0700 (PDT) Received: from cizrna.lan ([109.72.12.203]) by smtp.gmail.com with ESMTPSA id jr5sm2203032wjc.26.2015.09.17.05.57.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 05:57:43 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v5 02/23] ARM: amba: Move reading of periphid to pre_probe() Date: Thu, 17 Sep 2015 14:56:56 +0200 Message-Id: <1442494637-3674-3-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1442494637-3674-1-git-send-email-tomeu.vizoso@collabora.com> References: <1442494637-3674-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150917_055805_900689_5733D3D2 X-CRM114-Status: GOOD ( 22.95 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, Arnd Bergmann , Stephen Warren , Greg Kroah-Hartman , Linus Walleij , Dmitry Torokhov , "Rafael J. Wysocki" , Rob Herring , Javier Martinez Canillas , Mark Brown , Thierry Reding , Alan Stern , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reading the periphid when the Primecell device is registered means that the apb pclk must be available by then or the device won't be registered at all. By moving this code to pre_probe (to be called by the device-driver core before the device is matched to a driver) we remove any order requirements. Signed-off-by: Tomeu Vizoso --- Changes in v5: None Changes in v4: - Added bus.pre_probe callback so the probes of Primecell devices can be deferred if their device IDs cannot be yet read because of the clock driver not having probed when they are registered. Maybe this goes overboard and the matching information should be in the DT if there is one. Changes in v3: None Changes in v2: None drivers/amba/bus.c | 78 ++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index f0099360039e..1cbe43b4acd3 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -24,6 +24,8 @@ #define to_amba_driver(d) container_of(d, struct amba_driver, drv) +static int amba_pre_probe(struct device *dev); + static const struct amba_id * amba_lookup(const struct amba_id *table, struct amba_device *dev) { @@ -193,6 +195,7 @@ struct bus_type amba_bustype = { .name = "amba", .dev_attrs = amba_dev_attrs, .match = amba_match, + .pre_probe = amba_pre_probe, .uevent = amba_uevent, .pm = &amba_pm, }; @@ -336,44 +339,26 @@ static void amba_device_release(struct device *dev) kfree(d); } -/** - * amba_device_add - add a previously allocated AMBA device structure - * @dev: AMBA device allocated by amba_device_alloc - * @parent: resource parent for this devices resources - * - * Claim the resource, and read the device cell ID if not already - * initialized. Register the AMBA device with the Linux device - * manager. - */ -int amba_device_add(struct amba_device *dev, struct resource *parent) +static int amba_pre_probe(struct device *dev) { + struct amba_device *d = to_amba_device(dev); u32 size; void __iomem *tmp; int i, ret; - WARN_ON(dev->irq[0] == (unsigned int)-1); - WARN_ON(dev->irq[1] == (unsigned int)-1); - - ret = request_resource(parent, &dev->res); - if (ret) - goto err_out; - - /* Hard-coded primecell ID instead of plug-n-play */ - if (dev->periphid != 0) - goto skip_probe; + if (d->periphid != 0) + return 0; /* * Dynamically calculate the size of the resource * and use this for iomap */ - size = resource_size(&dev->res); - tmp = ioremap(dev->res.start, size); - if (!tmp) { - ret = -ENOMEM; - goto err_release; - } + size = resource_size(&d->res); + tmp = ioremap(d->res.start, size); + if (!tmp) + return -ENOMEM; - ret = amba_get_enable_pclk(dev); + ret = amba_get_enable_pclk(d); if (ret == 0) { u32 pid, cid; @@ -388,37 +373,50 @@ int amba_device_add(struct amba_device *dev, struct resource *parent) cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) << (i * 8); - amba_put_disable_pclk(dev); + amba_put_disable_pclk(d); if (cid == AMBA_CID || cid == CORESIGHT_CID) - dev->periphid = pid; + d->periphid = pid; - if (!dev->periphid) + if (!d->periphid) ret = -ENODEV; } iounmap(tmp); + return ret; +} + +/** + * amba_device_add - add a previously allocated AMBA device structure + * @dev: AMBA device allocated by amba_device_alloc + * @parent: resource parent for this devices resources + * + * Claim the resource, and register the AMBA device with the Linux device + * manager. + */ +int amba_device_add(struct amba_device *dev, struct resource *parent) +{ + int ret; + + WARN_ON(dev->irq[0] == (unsigned int)-1); + WARN_ON(dev->irq[1] == (unsigned int)-1); + + ret = request_resource(parent, &dev->res); if (ret) - goto err_release; + return ret; - skip_probe: ret = device_add(&dev->dev); if (ret) - goto err_release; + return ret; if (dev->irq[0]) ret = device_create_file(&dev->dev, &dev_attr_irq0); if (ret == 0 && dev->irq[1]) ret = device_create_file(&dev->dev, &dev_attr_irq1); - if (ret == 0) - return ret; - - device_unregister(&dev->dev); + if (ret) + device_unregister(&dev->dev); - err_release: - release_resource(&dev->res); - err_out: return ret; } EXPORT_SYMBOL_GPL(amba_device_add);