From patchwork Mon Sep 7 12:23:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7134321 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 EA04B9F380 for ; Mon, 7 Sep 2015 12:26:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E79072066C for ; Mon, 7 Sep 2015 12:26:34 +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 E9E2B2066B for ; Mon, 7 Sep 2015 12:26:33 +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 1ZYvTT-0007yx-PW; Mon, 07 Sep 2015 12:24:39 +0000 Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZYvTJ-0007r2-Iy for linux-arm-kernel@lists.infradead.org; Mon, 07 Sep 2015 12:24:30 +0000 Received: by wicfx3 with SMTP id fx3so82222520wic.0 for ; Mon, 07 Sep 2015 05:24:10 -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=80GxG8Q9dvk4hfO/nHQiOe1Hc9ErJM5Yh+RyKiKTvTs=; b=FtXRj5v7Rh5WHmfq7WOn9LPV1/IKHUjBOQsD3X5r4Ebf6GTVHI+jfIcjEIEMWuiJrl 4sVmDZBJrItt8lNCmWzCrolDCmh7XvZkAZjYJ9m9p7KveCZCZNnNvwLMM1DhJGGscs+P Adf7L0sP8ZDCQc4Mdra/Ph3D8BGUIRqsyoQ9DkPAqViAVfrJbb1NMgtHl+t7Z2H5bJmd p9Sgmq3XjUnvevf1U1ovMTiP2SO1hExrnoD7vaY81/Q1ge9cJxiOYFfOITSsgPTE6iFQ wqotK0TXdxzph0NilF4k4zU2sAwVkWb8GUcNWfJ5/9aehZ5FA+NoWc9l+Ubs+qsQXgOY wwqg== X-Received: by 10.180.21.169 with SMTP id w9mr34482799wie.73.1441628650193; Mon, 07 Sep 2015 05:24:10 -0700 (PDT) Received: from cizrna.lan ([109.72.12.78]) by smtp.gmail.com with ESMTPSA id cm6sm15438wib.22.2015.09.07.05.24.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Sep 2015 05:24:09 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v4 02/22] ARM: amba: Move reading of periphid to pre_probe() Date: Mon, 7 Sep 2015 14:23:27 +0200 Message-Id: <1441628627-5143-3-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1441628627-5143-1-git-send-email-tomeu.vizoso@collabora.com> References: <1441628627-5143-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150907_052429_776204_D8838C5A X-CRM114-Status: GOOD ( 23.85 ) X-Spam-Score: -2.3 (--) 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, Russell King , linux-acpi@vger.kernel.org, Arnd Bergmann , Stephen Warren , Linus Walleij , Dmitry Torokhov , "Rafael J. Wysocki" , Rob Herring , Javier Martinez Canillas , Mark Brown , Thierry Reding , 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 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);