From patchwork Wed Jan 10 03:47:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 124010 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4791345qgn; Tue, 9 Jan 2018 19:52:39 -0800 (PST) X-Google-Smtp-Source: ACJfBotiprzfbfEdWZl45IK3Ovf9mhzTXknTQWOp3iWuBlCeaf/XLXvakAB4Rb6C9MCpPCJ/1M7J X-Received: by 10.98.211.204 with SMTP id z73mr6118241pfk.198.1515556359430; Tue, 09 Jan 2018 19:52:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515556359; cv=none; d=google.com; s=arc-20160816; b=QSEtLPQOsG9cH7QbCa4J356yVFks2SpFKt/n7hpj0ECQYXRl0158rAXBrWYFa46vZU 9olqH0sDUD2MyW8PPQlBdp5zmwkex7m0hX9Ln16TKw9RDs0OMKRa12uUg5z8CfSFwDMq vwZwCp2r0Ldx8UdjJB6iMrSERdV7PVOeguAAEGh0P8DGNu8cYAGftQpfy2bdXfqNIxt7 VXKGxmD7FCvX2tR65w8iCICv8WCOoK3/Gc6ELQVgh45NU+ZTww9qJqeBa33fF2GfWa80 9X9HvC6WmO0nq6MEOGL+3U0jHsN9ACtztPOYDBxvHkz9XQ9Swywv000aIl+rsG8Gq1Lo ikQQ== 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=JvF1dk+O7f0i+Fy6jVvZS+EaoWZtI51KnXjLkfkaMqQ=; b=0Hi/6jmIscw+Y/ZbGCT6uAUPlYIoEGvVE0uqDKE4o2kd1gVT362Ab3LlgY5nW9eu5/ G+HQkaGA1Kl2aqHgsZ1H6y5jg8p7mnN3mH5duInVWJfXYwb3ZReK7VRmh/FkVCbTYpYr OkTrWxPjA4qbvSD/EJSS2BsA0eagSyLcVZcAysDWYz3ryWzuSd473SB7DS4LMuKRPDf2 4ierokahCXzyCG6t17IMJ4Iz60BJdL9Zv7OyebFIOywCwqIxY3wLHxwCkMGJa3h3+8Iw vTOz0MbKhsWPALQZKNbBKY+FkVdcQYfkg3YeNSNdyAcDAK3TsrNBIFDMXw9hD7ZNEsK5 wO/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ce6DzfwY; 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 k4si11246672pls.297.2018.01.09.19.52.39; Tue, 09 Jan 2018 19:52:39 -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=Ce6DzfwY; 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 S1756867AbeAJDwh (ORCPT + 28 others); Tue, 9 Jan 2018 22:52:37 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:42256 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965146AbeAJDr4 (ORCPT ); Tue, 9 Jan 2018 22:47:56 -0500 Received: by mail-pg0-f68.google.com with SMTP id q67so9808629pga.9 for ; Tue, 09 Jan 2018 19:47:55 -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=JvF1dk+O7f0i+Fy6jVvZS+EaoWZtI51KnXjLkfkaMqQ=; b=Ce6DzfwYVXN+KftvKMbWxtfcaTa1QZCA3Xl0+JEjS8s50iVeSmmSeBRCFOyx9zexcV tK3C5ehEOI1PiythfXoT4IIgelUT4lhW20il+QkuQj8Jqb7jPmLEj7AFjz2Ywagd5tAo 4pLc+EMrw2KFTxS6aRyyAudfk2JO+76X6Y1b0= 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=JvF1dk+O7f0i+Fy6jVvZS+EaoWZtI51KnXjLkfkaMqQ=; b=eyT67yKKorb1H9+QUc4zysX6+fIZy4ozMRDYbV3bBCF9/9LFmmsxg8PcmsbIofKk/D oYhQEJdlKirjc2Sl84VgkZRv650+4NB0V7YWQ5QYLwsPnY33vMs8BkSZ/e3IXXLaBQ4U NXsX7/xX/ZA940b49C24Z12HD8l7XEh51myb1J1TnZtCPoqGUuKgmuitdPo3EbDvyzZ+ 8N8pghzTZaYAn6bNLvqccj+7f+EYJe9HmPqRibqurn75A2hNW95oZcr2otRHIjAIbgC/ NR/zGUSPl8+nU6jHIgLjh4pSyChHsMkzUEpycRym1eg1h2BWHCEQzc4pkh9hgD/6aZaS qTcA== X-Gm-Message-State: AKwxytcuI+rQT7Av006htSm5nq5BynSWn12/LBgQ2IRKe1EIpWG858qR FCaKdNWNS/YaJJaCYp927KWTjw== X-Received: by 10.99.2.136 with SMTP id 130mr2613478pgc.268.1515556075532; Tue, 09 Jan 2018 19:47:55 -0800 (PST) Received: from localhost ([122.172.19.39]) by smtp.gmail.com with ESMTPSA id i186sm30474804pfg.178.2018.01.09.19.47.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 19:47:55 -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 Subject: [PATCH V6 01/13] of: platform: Add of_find_any_device_by_node() Date: Wed, 10 Jan 2018 09:17:30 +0530 Message-Id: <744c2ed81cfe95768369b061c422eec3708447a0.1515554879.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 b7cf84b29737..61a4a81bea9f 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -60,6 +60,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 fb908e598348..4909d1aa47ec 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -59,11 +59,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 */