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: 70872 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp555611qgy; Sun, 26 Jun 2016 00:32:38 -0700 (PDT) X-Received: by 10.66.26.36 with SMTP id i4mr22634976pag.3.1466926358176; Sun, 26 Jun 2016 00:32:38 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id b21si18126211pfk.45.2016.06.26.00.32.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jun 2016 00:32:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org 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-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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+patch=linaro.org@lists.infradead.org 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(+) -- 2.9.0.rc2.8.ga28705d _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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) {