From patchwork Thu Dec 14 15:33:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 121973 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6960010qgn; Thu, 14 Dec 2017 07:34:04 -0800 (PST) X-Google-Smtp-Source: ACJfBotJ3hFxRZhzEJk+qeeig4ZvnfArhaaRIIXNIIg+FYpxt396eCCPiCESuySdKNVsb4BZ/86+ X-Received: by 10.98.163.73 with SMTP id s70mr9875391pfe.64.1513265644740; Thu, 14 Dec 2017 07:34:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513265644; cv=none; d=google.com; s=arc-20160816; b=w813ZhDXdfc373h+CFCqFQSDe6+rv7sLmX+5AC360Ce3aQTKwKCPffHeBvWRzgimp/ H7YzwTebxsRcMGhsodAJDljeWsLO9czBqj1j6/AMk4ZRw3F4fcxc1YmTT+xomXAqVJsX 5zqYqghsNwb9IDI18XN0Ep6TtqVnM03uOAzp4jrNHRwsKWQq4ipKUkFvwI6u38DcfFwO 5PZeDIQlhHG16x29/ooZnqqp4zPX/xa7xQR/FwrEaPfEogF3NVTo6wFdk1dXWcqflL96 dKUxh9cNVByqvUgZkvCs+LpWweDHlWx9M/KiZ2KcSztGBk/WFhSWgluhA007DO5Z6mgi j3mg== 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=L2jvAGAsv9XxhKmrq+BC5liNBLzdIHYfWNO3NCY5kpzgjhU9Vr5v2nxuG9G7j2SAAU ePoZRo9qhVXHxuEqZYAjmudGaekRQCINifnjIZCY4bCxTtUQc7f3e2ua3qCHkhJRSA0h ZbThydonzI3wKCJtKOat/9KzC46Fqd2zIw66ygWz6Od5w8aU5o/ANjMS8hjN0MZmKAFt k+OPuv1SL0/9YyzTQPQrauG0OQoN9gRL7BQNeGom1rNVxY0ZPtvPdo5bvq7RAaYVWt/o 7X2bQ8RFZvGoHvTPpjAf8elslzK/3+lX6Sqo5s644TZqk25LUtzNSrq76lLANH/jb2+B BWkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cYdJ9iaR; 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 q12si3358439pls.475.2017.12.14.07.34.04; Thu, 14 Dec 2017 07:34:04 -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=cYdJ9iaR; 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 S1753325AbdLNPd6 (ORCPT + 19 others); Thu, 14 Dec 2017 10:33:58 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:45069 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753264AbdLNPdy (ORCPT ); Thu, 14 Dec 2017 10:33:54 -0500 Received: by mail-pg0-f66.google.com with SMTP id m25so3615147pgv.12 for ; Thu, 14 Dec 2017 07:33:53 -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=cYdJ9iaR7RB/2eh2ysuLTqt6mI8pRef5ilpcS+/OGV7qaWUZIw/NSF4z3dxvnp7prh vFEVJHAApLYR20XT886s98bX+wjgNTnvlVakyfhkSqVsCWvg9VMDVxVa09N59A+YxPIS D0jbvh+SZsa6NKLPA4uJ0Al/mbZwaJuBdkh3Q= 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=DIbcMXSjLgnOcpwZM1JLAQyBhOnHFpvCudZg6kqWKr/jxjoGykiiq6RwOrmDoA+vUd SGevh0V1DgtvbkqSPS+XPCNZ9fTcREiE5UVtlQ37hVV5mYNOiUzvueo4P02rbfMVK3SG 6OeBP2duv2PsDCeMmVqxGYcatCQWlh8Ulql6D5FazGlE56EgqmSFMBPZDUThb/HPoe6B KomSvbOO0t8LZ7XCOVLprN/qHufHYj7+lBc0TKeX71J1VTgDFoyVblxTabZEOjwgw6Yd Jdh8ZLTH/R0Jd3wTidsluscGnvDFu5mCxHeAEAoyMHB4u0emkLz0RE179PPv3Qb+Z4ab C8aQ== X-Gm-Message-State: AKGB3mLGTdxErtZuqcVW/rI0hCptQBn/eE/6z/MIMw7LfqEK0sJmXl/s RG8mITkC6fQD8exAg17ICA2kfg== X-Received: by 10.99.109.5 with SMTP id i5mr8631028pgc.359.1513265633370; Thu, 14 Dec 2017 07:33:53 -0800 (PST) Received: from localhost ([122.172.99.7]) by smtp.gmail.com with ESMTPSA id r90sm8676848pfj.148.2017.12.14.07.33.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Dec 2017 07:33:52 -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 V5 01/13] of: platform: Add of_find_any_device_by_node() Date: Thu, 14 Dec 2017 21:03:08 +0530 Message-Id: <6dbdbc0e5fa8ca4722e9d3b1a92a6f9e008066e2.1513264961.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 */