Received: by 10.223.185.116 with SMTP id b49csp519333wrg; Fri, 23 Feb 2018 02:29:14 -0800 (PST) X-Google-Smtp-Source: AH8x2260T6VtCoHNKUNs78GelhybgBVxHUd6K1o7a/WSE83vSNOPdHrmeJaVD+SoLhA+zO/RtFOW X-Received: by 2002:a17:902:5682:: with SMTP id j2-v6mr1247438pli.441.1519381754649; Fri, 23 Feb 2018 02:29:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519381754; cv=none; d=google.com; s=arc-20160816; b=lYqhbUPPY68BK/9gxm8/Qi1MABWXXmA2zI1aYyjH1ghTf3s+NJQtC9Ngy8eToiJsYV nF4I6x3vPgreqfPPw8tBRwsO4Yc9Q24YWnYwNELj1h1RkKIlYKt2z7BB98qK4gPvdMwD RKUYZQjrvEYdrIcvk77eerjYnlJyxDw1kbt0g7U7kWav3i0OupBf6y1LXXLKaD5B4+wf HS8Jpwig0A9CmwqpJM8Mslorx4fNOLqV9Rb/G/hzHMrgptRE2Bx1z4C66tiaaP5VF1QI M+qhEq5jCdNt/2NV2QTAzuvL8bq1t1j0XhGt0ywjelCB035TDRtM+tox1C+EC3YYTSGp gsnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=hKE+dtbHYf0RuN0sOC8TzmR2sRg9XSryiPC5z8/Fkcs=; b=ADi5VNzFkGcqlEr3C+NE4YlT6qktZHwJoy3WqGLGV6IxcnnpDe/3MdANjuJwhhHOBY pGLHQG6MXv4zpQAJ8j99Ihegs8IRuiIz8TkWVQpOIjxmnkxHPROKtwYXKsCAOFl6z9GB JEUnWimluFMTfPKK2KQNpkTZzjTKnu3x4vbxnZVpcJ9GS1QcVhkaHTni+QwCC1rqxtc7 ftQl3BBAcr/KgvdQHN+7pFevSnDTnip8trVoIvwaTkpGhPDFR4p59x5F3FhLD4tXWGq1 bUFtYYEfQR4y4ZjESP7+eODIcgH+scO1KgRcGXgL6VncacpDQVCdKsoMic7FcJzMVsbO CCnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mgg8E91s; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 15-v6si1590585pla.23.2018.02.23.02.29.00; Fri, 23 Feb 2018 02:29:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mgg8E91s; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751454AbeBWKYL (ORCPT + 99 others); Fri, 23 Feb 2018 05:24:11 -0500 Received: from mail-pl0-f66.google.com ([209.85.160.66]:39195 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750903AbeBWKYI (ORCPT ); Fri, 23 Feb 2018 05:24:08 -0500 Received: by mail-pl0-f66.google.com with SMTP id s13so4660830plq.6 for ; Fri, 23 Feb 2018 02:24:08 -0800 (PST) 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 :in-reply-to:references; bh=hKE+dtbHYf0RuN0sOC8TzmR2sRg9XSryiPC5z8/Fkcs=; b=Mgg8E91skrRWsa2B2JvNIkC6Ea3SOi685GMwsEzBqmJ4Jo3hscWGj4dVSC749q1ll+ 1P6cq1mTvcjxlD/jf52SKzz1tyvVNq+YVeF3ucZjC9tNfrDkORarukHDLglmsX1h3tIT V1WBoFLReBrwXUjigbfjjGWzC07BbHyuv2TSg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=hKE+dtbHYf0RuN0sOC8TzmR2sRg9XSryiPC5z8/Fkcs=; b=k4WA+cOprvUTTrSptt32sPKT6+gqA/+40n6kuFTflJp2FGeuBTrudS60trTj2rzmQ+ MZk5GO4T/95GxzjZzf25+cLhnc6co1J+Ch0l2PESTIXpn3DqFZ2P7cbzXzZ7eU4GvCSE 4/fpZyLiyquzNLR3H3fmnByDlfmNlZYsBseThLRmzNwRyGg6X1McjRh7DqmvVKCO/6Hw jthbkgBVDQEVFKYPv+p99bVUGXB7gTvJgudQARKe7CSNK7BEQEQHQYOuG0MdfOH3/yCL 1mGG7bUGziXCGWm8gbZPDkaMXKxL3LYnyGD4JVUcEYgJ4Qc760aXs2k0UlrLOc/BgibI FCkg== X-Gm-Message-State: APf1xPDwttSJZ8zRb0IYpS/sGbnfeKqWfC0th9BTmWcWuYcvfstbacW/ oY/tuRSrvqf8nZR/ex2Vy7LFVg== X-Received: by 2002:a17:902:14cb:: with SMTP id y11-v6mr1279789plg.294.1519381447793; Fri, 23 Feb 2018 02:24:07 -0800 (PST) Received: from localhost ([122.167.232.138]) by smtp.gmail.com with ESMTPSA id a3sm4356866pfh.120.2018.02.23.02.24.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 02:24:07 -0800 (PST) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org, olof@lixom.net Subject: [PATCH V7 01/13] of: platform: Add of_find_any_device_by_node() Date: Fri, 23 Feb 2018 15:53:40 +0530 Message-Id: <483bc64db23821497d0634a86e801510e439fe3d.1519380923.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This creates a new helper that returns the struct device corresponding to a struct device_node. This currently works only for amba and platform devices, but can be easily extended to include other bus types. This also creates an internal of_find_amba_device_by_node() helper, which isn't exported as of now. Signed-off-by: Viresh Kumar --- drivers/of/platform.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 5 +++++ 2 files changed, 60 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index c00d81dfac0b..72853f9043e6 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -55,6 +55,61 @@ struct platform_device *of_find_device_by_node(struct device_node *np) } EXPORT_SYMBOL(of_find_device_by_node); +#ifdef CONFIG_ARM_AMBA +/** + * of_find_amba_device_by_node - Find the amba_device associated with a node + * @np: Pointer to device tree node + * + * Takes a reference to the embedded struct device which needs to be dropped + * after use. + * + * Returns amba_device pointer, or NULL if not found + */ +static struct amba_device *of_find_amba_device_by_node(struct device_node *np) +{ + struct device *dev; + + dev = bus_find_device(&amba_bustype, NULL, np, of_dev_node_match); + return dev ? to_amba_device(dev) : NULL; +} +#else +static inline struct amba_device *of_find_amba_device_by_node(struct device_node *np) +{ + return NULL; +} +#endif + +/** + * of_find_any_device_by_node - Find the struct device associated with a node + * @np: Pointer to device tree node + * + * Takes a reference to the embedded struct device which needs to be dropped + * after use. + * + * This currently supports only AMBA and platform devices. + * + * Returns struct device pointer, or NULL if not found + */ +struct device *of_find_any_device_by_node(struct device_node *np) +{ + struct device *dev = NULL; + + if (of_device_is_compatible(np, "arm,primecell")) { + struct amba_device *adev = of_find_amba_device_by_node(np); + + if (adev) + dev = &adev->dev; + } else { + struct platform_device *pdev = of_find_device_by_node(np); + + if (pdev) + dev = &pdev->dev; + } + + return dev; +} +EXPORT_SYMBOL(of_find_any_device_by_node); + #ifdef CONFIG_OF_ADDRESS /* * The following routines scan a subtree and registers a device for diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 84a966623e78..5fb20afaf895 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -54,11 +54,16 @@ extern struct platform_device *of_device_alloc(struct device_node *np, struct device *parent); #ifdef CONFIG_OF extern struct platform_device *of_find_device_by_node(struct device_node *np); +extern struct device *of_find_any_device_by_node(struct device_node *np); #else static inline struct platform_device *of_find_device_by_node(struct device_node *np) { return NULL; } +static inline struct device *of_find_any_device_by_node(struct device_node *np) +{ + return NULL; +} #endif /* Platform devices and busses creation */ -- 2.15.0.194.g9af6a3dea062