From patchwork Wed Apr 13 09:36:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 8820221 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A2577C0553 for ; Wed, 13 Apr 2016 09:38:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AC9AB2026C for ; Wed, 13 Apr 2016 09:38:27 +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 B9DED2013D for ; Wed, 13 Apr 2016 09:38:26 +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 1aqHEQ-0008ME-Vg; Wed, 13 Apr 2016 09:37:06 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aqHDt-00083h-0M for linux-arm-kernel@lists.infradead.org; Wed, 13 Apr 2016 09:36:37 +0000 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O5K00KQGG09IS10@mailout1.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 13 Apr 2016 10:36:10 +0100 (BST) X-AuditID: cbfec7f5-f792a6d000001302-33-570e1309c150 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id AE.95.04866.9031E075; Wed, 13 Apr 2016 10:36:09 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O5K005BCG05JE40@eusync1.samsung.com>; Wed, 13 Apr 2016 10:36:09 +0100 (BST) From: Marek Szyprowski To: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 2/2] drivers: amba: properly handle devices with power domains Date: Wed, 13 Apr 2016 11:36:00 +0200 Message-id: <1460540160-18762-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1460540160-18762-1-git-send-email-m.szyprowski@samsung.com> References: <1460540160-18762-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrALMWRmVeSWpSXmKPExsVy+t/xy7qcwnzhBs1bzS02zljPatG8eD2b xesXhhabHl9jtbi8aw6bxYzz+5gsbl/mtVh75C67xfG14Q6cHi3NPWwed67tYfPYP3cNu8fm JfUefVtWMXp83iQXwBbFZZOSmpNZllqkb5fAldGz+wJbwVy1irs975gbGCfIdzFyckgImEgs ur6UFcIWk7hwbz1bFyMXh5DAUkaJo3u2QzlNTBL33jcwglSxCRhKdL3tYgOxRQSyJebv7WYH KWIWWMEk0f/wAVhCWCBY4sD+G8wgNouAqsTM9//BVvAKeEhcvbuSBWKdnMT/lyuYQGxOAU+J o3e2gcWFgGpe7drBPoGRdwEjwypG0dTS5ILipPRcI73ixNzi0rx0veT83E2MkHD7uoNx6TGr Q4wCHIxKPLwa63nDhVgTy4orcw8xSnAwK4nwfuHjCxfiTUmsrEotyo8vKs1JLT7EKM3BoiTO O3PX+xAhgfTEktTs1NSC1CKYLBMHp1QDI6vajK9+HFMYp5/OXcZctLTvU1idtP2MCWzPVabl f33J1jZNarP27ptTd56bGnFm1dbp2nOZzaIOVZ/blpN0yNty8tNHRioztr46+WzWraSYKXFi IvvWN0r/ff6b/1SX697110+oMNVvmtPQ15ybKa/Q+23rjgtF8+5Zcp3l0rIPv5rzOYtj4Uwl luKMREMt5qLiRAAnzXBdMwIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160413_023633_348261_7F109FEA X-CRM114-Status: GOOD ( 24.51 ) X-Spam-Score: -7.9 (-------) 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: Ulf Hansson , Russell King - ARM Linux , Bartlomiej Zolnierkiewicz , Greg Kroah-Hartman , Krzysztof Kozlowski , Marek Szyprowski 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=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 To read pid/cid registers, the probed device need to be properly turned on. When it is inside a power domain, the bus code should ensure that the given power domain is enabled before trying to access device's registers. However in some cases power domain (or clocks) might not be yet available. Returning EPROBE_DEFER is not a solution in such case, because callers don't handle this special error code. Instead such devices are added to the special list and their registration is retried in late_initcall, when hopefully all resources are available. Signed-off-by: Marek Szyprowski --- drivers/amba/bus.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 10 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index f0099360039e..3329262007f9 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -336,16 +336,7 @@ 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_device_try_add(struct amba_device *dev, struct resource *parent) { u32 size; void __iomem *tmp; @@ -373,6 +364,12 @@ int amba_device_add(struct amba_device *dev, struct resource *parent) goto err_release; } + ret = dev_pm_domain_attach(&dev->dev, true); + if (ret == -EPROBE_DEFER) { + iounmap(tmp); + goto err_release; + } + ret = amba_get_enable_pclk(dev); if (ret == 0) { u32 pid, cid; @@ -398,6 +395,7 @@ int amba_device_add(struct amba_device *dev, struct resource *parent) } iounmap(tmp); + dev_pm_domain_detach(&dev->dev, true); if (ret) goto err_release; @@ -421,6 +419,94 @@ int amba_device_add(struct amba_device *dev, struct resource *parent) err_out: return ret; } + +/* + * Registration of AMBA device require reading its pid and cid registers. + * To do this, the device must be turned on (if it is a part of power domain) + * and have clocks enabled. However in some cases those resources might not be + * yet available. Returning EPROBE_DEFER is not a solution in such case, + * because callers don't handle this special error code. Instead such devices + * are added to the special list and their registration is retried from + * deferred probe notifier, when hopefully all resources are available. + */ +struct deferred_device { + struct amba_device *dev; + struct resource *parent; + struct list_head node; +}; + +static LIST_HEAD(deferred_devices); +static DEFINE_MUTEX(deferred_devices_lock); + +static int amba_deferred_probe_notifier(struct notifier_block *nb, + unsigned long action, void *data); +static struct notifier_block amba_deferred_probe_nb = { + .notifier_call = amba_deferred_probe_notifier, +}; + +static int amba_deferred_probe_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct deferred_device *ddev, *tmp; + + mutex_lock(&deferred_devices_lock); + + list_for_each_entry_safe(ddev, tmp, &deferred_devices, node) { + int ret = amba_device_try_add(ddev->dev, ddev->parent); + + if (ret == -EPROBE_DEFER) + continue; + + list_del_init(&ddev->node); + kfree(ddev); + } + + if (list_empty(&deferred_devices)) + deferred_probe_unregister_notifier(&amba_deferred_probe_nb); + + mutex_unlock(&deferred_devices_lock); + + return NOTIFY_DONE; +} + +/** + * 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) +{ + int ret = amba_device_try_add(dev, parent); + + if (ret == -EPROBE_DEFER) { + struct deferred_device *ddev; + + ddev = kmalloc(sizeof(*ddev), GFP_KERNEL); + if (!ddev) + return -ENOMEM; + + ddev->dev = dev; + ddev->parent = parent; + ret = 0; + + mutex_lock(&deferred_devices_lock); + + if (list_empty(&deferred_devices)) + ret = deferred_probe_register_notifier( + &amba_deferred_probe_nb); + if (ret == 0) + list_add_tail(&ddev->node, &deferred_devices); + else + kfree(ddev); + + mutex_unlock(&deferred_devices_lock); + } + return ret; +} EXPORT_SYMBOL_GPL(amba_device_add); static struct amba_device *