From patchwork Sun Jun 26 07:28:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9199183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 81D7260754 for ; Sun, 26 Jun 2016 07:33:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75E6D2853F for ; Sun, 26 Jun 2016 07:33:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68C2428546; Sun, 26 Jun 2016 07:33:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id BD6012853F for ; Sun, 26 Jun 2016 07:33:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bH4V8-0001GG-Id; Sun, 26 Jun 2016 07:29:06 +0000 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bH4V5-0000rn-Pl for linux-arm-kernel@lists.infradead.org; Sun, 26 Jun 2016 07:29:04 +0000 Received: by mail-pf0-x229.google.com with SMTP id c2so51925771pfa.2 for ; Sun, 26 Jun 2016 00:28:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cqXF0P67GKX003uhusBagbnwp7IULvJRNt1LvXkgE+U=; b=hv2NRjQFBIIMDgQ6WmjJOqy3to1jsDu0aRh/2TJ+V19j6/6so/NT58UI538byRarAq B/B1cBnHVyskjf6+iNMPkm/i42YYD3lJEJxrOoEmpOa2b5aol3RAyCGKrYFbGXcRnk5e SwkPkfPexmHqQOStlrfHlsF85fNqm05iYRK0A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cqXF0P67GKX003uhusBagbnwp7IULvJRNt1LvXkgE+U=; b=a+MCJiPgR1YoYwe1e8L9GdTltQ4pjgvUUnHbMSrNPYthIakqCbbD4ARy4LqLTsQ4PV GVmR4YmHKQCYIk0RbbFWrCqeOdp0EIwy7aAjykysWIDzqcFwo2zDtEhlks44hKixFErj s7f5wQOE0R0pQ5Gm5wXPGuSPCK5hlGnZD2qXBOsL+ErIkU9tg53Yx8v83o6yNSZ7dT8+ B4ZSX1qipbeYa8OCRi11oj31xS40HCLxNwUsBmOntGRJmEftmTGJ1wJAVvCC5aeUWCVa w0/6/1AuKglbFuRDqtUWkal06+YUtnvDVCQ/DN+Lrtmj7x9CfLKLiRn1b4PygLbApYCG pSMg== X-Gm-Message-State: ALyK8tI4A2x8ZHKKD5NscKyXOt5HeVA56zta1EkigvfZp3vr8pbYWsOLomhjKXXv+av52tmt X-Received: by 10.98.35.133 with SMTP id q5mr22050989pfj.7.1466926122915; Sun, 26 Jun 2016 00:28:42 -0700 (PDT) Received: from localhost.localdomain (ip68-101-172-78.sd.sd.cox.net. [68.101.172.78]) by smtp.gmail.com with ESMTPSA id f138sm3790495pfa.17.2016.06.26.00.28.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Jun 2016 00:28:42 -0700 (PDT) From: Stephen Boyd To: linux-usb@vger.kernel.org Subject: [PATCH 01/21] of: device: Support loading a module with OF based modalias Date: Sun, 26 Jun 2016 00:28:18 -0700 Message-Id: <20160626072838.28082-2-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.9.0.rc2.8.ga28705d In-Reply-To: <20160626072838.28082-1-stephen.boyd@linaro.org> References: <20160626072838.28082-1-stephen.boyd@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160626_002903_862800_DCC711FB X-CRM114-Status: GOOD ( 14.44 ) 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: Felipe Balbi , Arnd Bergmann , Neil Armstrong , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson , devicetree@vger.kernel.org, Rob Herring , Andy Gross , 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-Virus-Scanned: ClamAV using ClamSMTP In the case of ULPI devices, we want to be able to load the driver before registering the device so that we don't get stuck in a loop waiting for the phy module to appear and failing usb controller probe. Currently we request the ulpi module via the ulpi ids, but in the DT case we might need to request it with the OF based modalias instead. Add a common function that allows anyone to request a module with the OF based modalias. Cc: Rob Herring Cc: Signed-off-by: Stephen Boyd --- drivers/of/device.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_device.h | 6 ++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/of/device.c b/drivers/of/device.c index fd5cfad7c403..f275e5beb736 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -226,6 +226,56 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) return tsize; } +static ssize_t of_device_modalias_size(struct device *dev) +{ + const char *compat; + int cplen, i; + ssize_t csize; + + if ((!dev) || (!dev->of_node)) + return -ENODEV; + + /* Name & Type */ + csize = 5 + strlen(dev->of_node->name) + strlen(dev->of_node->type); + + /* Get compatible property if any */ + compat = of_get_property(dev->of_node, "compatible", &cplen); + if (!compat) + return csize; + + /* Find true end (we tolerate multiple \0 at the end */ + for (i = (cplen - 1); i >= 0 && !compat[i]; i--) + cplen--; + if (!cplen) + return csize; + cplen++; + + /* Check space (need cplen+1 chars including final \0) */ + return csize + cplen; +} + +int of_device_request_module(struct device *dev) +{ + char *str; + ssize_t size; + int ret; + + size = of_device_modalias_size(dev); + if (size < 0) + return size; + + str = kmalloc(size + 1, GFP_KERNEL); + if (!str) + return -ENOMEM; + + of_device_get_modalias(dev, str, size); + str[size] = '\0'; + ret = request_module(str); + kfree(str); + + return ret; +} + /** * of_device_uevent - Display OF related uevent information */ diff --git a/include/linux/of_device.h b/include/linux/of_device.h index cc7dd687a89d..e9afbcc8de12 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -37,6 +37,7 @@ extern const void *of_device_get_match_data(const struct device *dev); extern ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len); +extern int of_device_request_module(struct device *dev); extern void of_device_uevent(struct device *dev, struct kobj_uevent_env *env); extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env); @@ -78,6 +79,11 @@ static inline int of_device_get_modalias(struct device *dev, return -ENODEV; } +static inline int of_device_request_module(struct device *dev) +{ + return -ENODEV; +} + static inline int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) {