From patchwork Mon Apr 21 19:01:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 4026031 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C9B539F391 for ; Mon, 21 Apr 2014 19:04:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C357C202B8 for ; Mon, 21 Apr 2014 19:04:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BED31202A7 for ; Mon, 21 Apr 2014 19:04:40 +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 1WcJT9-0007Rj-W1; Mon, 21 Apr 2014 19:01:31 +0000 Received: from mail-ob0-x22d.google.com ([2607:f8b0:4003:c01::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WcJT6-00079m-W0 for linux-arm-kernel@lists.infradead.org; Mon, 21 Apr 2014 19:01:29 +0000 Received: by mail-ob0-f173.google.com with SMTP id wn1so4696762obc.32 for ; Mon, 21 Apr 2014 12:01:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=H/zCAKE/qFYYECqMVRnJZrodb9w72jAEVkINdSHQXrE=; b=04rTGlERZnS8y1vRMX9Hq2u5a9eVLxYGHztBH8OP56wnnP+//HcYJ/lykLM5h9YGnB lK8OqE6lRyU7NtRBmi5dLEuHbTUOWpfudDBT83nsXM0zgXuLq+1VS3w9dckfrXUCZdF+ BsbVM/RsFL0BwGmOswNtJHSYa4O4JjY/SsSnI27gXyTeLfVbLaWfuGrPeS/xQPXvWMoA +p4bQCsjORR8FIiCAQZ1m4CqGQVjPhpdMUC5EHstmw6rW3qZ8MZutptU2xi/k/1ZT7gV FItAnh6orZxwyVIrGqdsLV0xfTVLXRhPbrIQZ6BRXaC49uUdW0WvGdw1Jr8h18ZDcDp+ LdGQ== X-Received: by 10.60.141.9 with SMTP id rk9mr33562192oeb.12.1398106867599; Mon, 21 Apr 2014 12:01:07 -0700 (PDT) Received: from [192.168.1.136] (72-48-77-163.dyn.grandenetworks.net. [72.48.77.163]) by mx.google.com with ESMTPSA id rt4sm13428968obb.12.2014.04.21.12.01.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Apr 2014 12:01:06 -0700 (PDT) Message-ID: <53556AF1.2030608@gmail.com> Date: Mon, 21 Apr 2014 14:01:05 -0500 From: Rob Herring User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Tony Lindgren , Russell King - ARM Linux Subject: Re: [PATCH v3 2/2] dt: platform driver: Fill the resources before probe and defer if needed References: <20140320161118.B7075C4067A@trevor.secretlab.ca> <1395413185-29763-1-git-send-email-jjhiblot@traphandler.com> <1395413185-29763-3-git-send-email-jjhiblot@traphandler.com> <20140418205213.GA21823@atomide.com> <20140418215848.GD21823@atomide.com> <20140418230335.GI24070@n2100.arm.linux.org.uk> <20140418232407.GQ21823@atomide.com> <20140421155424.GD23945@atomide.com> In-Reply-To: <20140421155424.GD23945@atomide.com> X-Enigmail-Version: 1.6 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140421_120129_146830_A74EE64B X-CRM114-Status: GOOD ( 37.25 ) X-Spam-Score: 0.1 (/) Cc: "devicetree@vger.kernel.org" , Jean-Jacques Hiblot , Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" , Grant Likely , Rob Herring , Gregory Clement , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 On Mon, Apr 21, 2014 at 10:54 AM, Tony Lindgren wrote: > * Rob Herring [140421 06:47]: >> On Fri, Apr 18, 2014 at 6:24 PM, Tony Lindgren wrote: >> > * Russell King - ARM Linux [140418 16:04]: >> >> On Fri, Apr 18, 2014 at 02:58:48PM -0700, Tony Lindgren wrote: >> >> > Oh come on, let's stop pretending it's not broken. And it's way worse with >> >> > device tree as there's nothing making sure the resources for a driver >> >> > are set up before the driver probes. And we've been unable to fix just >> >> > this issue alone for about six months now. It's also broken beyond that. >> >> > It's called of_platform_bus yet it won't even pass the platform_data >> >> > as auxdata to the devices on a sub-bus instantatiated like I2C. >> >> >> >> Isn't there a much simpler solution to the platform device IRQ problem? >> >> >> >> Rather than trying to fix it at the point where the resources are >> >> created, why not just *not* have DT create the IRQ resources in the >> >> first place, and instead have platform_get_irq() (which is the function >> >> which should be used to get an IRQ) be the actor to do whatever is >> >> necessary to return the IRQ(s) ? >> > >> > Yeah why not. I don't see why we would need to do all this of_* special >> > trickery for much anything beyond parsing the binding. >> >> That can work, but it will still need something like >> of_find_irq_domain() to determine whether to return -EPROBE_DEFER or >> not. > > Right. Naturally let's do whatever it takes to first fix this issue > in a minimal way first for the -rc cycle so we can do the longer term > changes needed. I'm not really convinced there is a simple and safe enough solution for 3.15. We should also be willing to tag a solution for stable if we take it for -rc (although that decision could be deferred). >> You could also go in the other direction and don't create the device >> until the resources can be resolved. Unlike any of the other >> solutions, that would work for amba bus as well although we may never >> have a case where we need this with the amba bus. This would require >> making of_platform_populate be callable multiple times, but there are >> already some other reasons for wanting to do that. Specifically, I >> would like the core code to call of_platform_populate with default >> options and then only platforms with non-default options need a call >> to of_platform_populate. > > I like this idea as this would also probably remove the the numerous > dmesg errors we are currently getting for drivers reprobing with > -EPROBE_DEFER. One issue with my proposal is with supporting modules. IIUC, deferred probe will continue trying forever and loading modules can cause probe to succeed. If devices are not created and on the deferred probe list, then they will not get probed when a module load fixes the dependency. > In the long term we should have platform bus just call a set of > standardized functions implemented by whatever the data source might > be. That way we can limit the use of of_* functions in device drivers > to just parsing of custom bindings in the drivers and use bus specific > functions for everything else. > >> >> Yes, I know we have some drivers which use platform_get_resources() with >> >> IORESOURCE_IRQ, but they should really use the right accessor. And those >> >> who just dereference the resource array directly... get what's coming >> >> (though of course they have to be fixed.) >> > >> > $ git grep IORESOURCE_IRQ drivers/ | grep platform_get_resource | wc -l >> > 179 >> >> Certainly, this is worthwhile clean-up no matter what the solution. > > Yeah agreed. But let's also consider the IORESOURCE_IRQ as just another > source for for the bus or driver data in addition to the DT parsed data. > Both sources of data should work just fine with platform_bus even > without cleaning up the drivers Ah, right. Except for those drivers you need to work with deferred probe would have to use platform_get_irq. That fact makes this solution quite a bit easier. Something like this is what you had in mind? */ diff --git a/drivers/base/platform.c b/drivers/base/platform.c index e714709..5b47210 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -87,7 +88,11 @@ int platform_get_irq(struct platform_device *dev, unsigned int num) return -ENXIO; return dev->archdata.irqs[num]; #else - struct resource *r = platform_get_resource(dev, IORESOURCE_IRQ, num); + struct resource *r; + if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node) + return of_irq_get(dev->dev.of_node, num); + + r = platform_get_resource(dev, IORESOURCE_IRQ, num); return r ? r->start : -ENXIO; #endif diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 7d3184f..30449ad 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -400,6 +400,26 @@ int of_irq_to_resource(struct device_node *dev, int index, struct resource *r) EXPORT_SYMBOL_GPL(of_irq_to_resource); /** + * of_irq_get - Decode a node's IRQ and return it as a Linux irq number + * @dev: pointer to device tree node + * @index: zero-based index of the irq + * + * Returns Linux irq number on success, or -EPROBE_DEFER if the irq domain + * is not yet created. + * + */ +int of_irq_get(struct device_node *dev, int index) +{ + int irq = irq_of_parse_and_map(dev, index); + + if (!irq && of_find_irq_domain(dev, index) == NULL) + return -EPROBE_DEFER; + + return irq; +} +EXPORT_SYMBOL_GPL(of_irq_get); + +/** * of_irq_count - Count the number of IRQs a node uses * @dev: pointer to device tree node