From patchwork Fri Feb 23 10:23:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 129340 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp435179lja; Fri, 23 Feb 2018 02:24:16 -0800 (PST) X-Google-Smtp-Source: AH8x224xAx0Dg2KaaM3hUAO12us2b0+MePPLOWSNBrijlXrvmT4zyaimbubnuI2O1m/U5Xm5QRud X-Received: by 10.101.93.82 with SMTP id e18mr1033969pgt.371.1519381456556; Fri, 23 Feb 2018 02:24:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519381456; cv=none; d=google.com; s=arc-20160816; b=gXbUuQyctoLDGS1Q907aYCdO03kW84R3AGL+8fbqc5BH0XWN1rfx/9xshZaGJD2VYr p+dV4QWP5Xc3VePkEF16+RhUX0MZcBz1LzHGFxUgTXUZKhFD6Xm1sW2dmaBTxU3uB+H7 SBLrupKHku4fycMDqYboWgSZR0mdk9OpHvNHPvIYwAld53OhUQNTL9UKPi0/fCtdwi4g IlHtpQonKEHKub0mowFx7dmx3Fbl9FcSmbi0POyZaVnGKD3hK+rOlQVt81gxltoVkUYB 8X3AtAFjPFG+GQQPQXY4N7VZK2+hOKQ0cIzF2iWqYYRxwPp3AuDtloV6J/NkjKmcVwg3 3wCg== 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 y184si1350278pgd.291.2018.02.23.02.24.16; Fri, 23 Feb 2018 02:24:16 -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 S1751469AbeBWKYL (ORCPT + 28 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(+) -- 2.15.0.194.g9af6a3dea062 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 */